 |
ATLAS Offline Software
|
Go to the documentation of this file.
33 #include "TGraphAsymmErrors.h"
59 bool contains(
const std::string&
s,
const std::string&
p);
60 bool contains(
const std::string&
s,
char p) noexcept;
63 bool fcontains(
const std::string&
s,
const std::string&
p);
69 std::string
tail( std::string
s,
const std::string&
pattern );
72 std::string
head( std::string
s,
const std::string&
pattern );
75 std::string
globbed(
const std::string&
s );
81 const std::string&
path=
"" );
86 const std::vector<std::string>&
patterns=std::vector<std::string>(),
87 const std::string&
path=
"" );
90 double realmax( TH1*
h,
bool include_error=
true,
double lo=0,
double hi=0 );
91 double realmin( TH1*
h,
bool include_error=
true,
double lo=0,
double hi=0 );
93 std::string
findcell( std::string
name,
const std::string&
regex,
const std::string& splitex=
"/" );
103 virtual const char*
what()
const throw() {
return "data don't match"; }
110 for (
unsigned i=0 ;
i<
v.size() ;
i++ )
s <<
"\t" <<
v[
i];
116 std::vector<int>
findxrange(TH1*
h,
bool symmetric=
false );
124 void xrange(TH1*
h,
bool symmetric=
true );
170 std::vector<std::string>
keys =
split(
s,
":" );
179 for (
size_t i=1 ;
i<
keys.size() ;
i++ ) {
192 std::cout <<
"offset:" << std::endl;
193 std::cout <<
"\tkey: " <<
keys[
i] << std::endl;
194 std::cout <<
"\tpos: " <<
keys[
i].find(
"offset") << std::endl;
199 std::cout <<
"m_offset: " <<
m_offset << std::endl;
201 else if (
keys[
i]==
"auton" ) {
205 else if (
keys[
i]==
"autow" ) {
209 else if (
keys[
i]==
"autown" ||
keys[
i]==
"autonw" ) {
214 else if (
keys[
i]==
"autosym" ) {
218 else if (
keys[
i]==
"normw" ||
keys[
i]==
"widthn" ) {
222 else if ( !minset ) {
227 std::cerr <<
"not enough values for the axis range: " <<
s << std::endl;
237 std::cout <<
"AxisInfo::info" <<
m_info <<
"\n";
238 std::cout <<
"\tlog " <<
m_log <<
"\n";
239 std::cout <<
"\tauto " <<
m_autoset <<
"\n";
278 static std::vector<std::string>
split(
const std::string&
s,
const std::string&
t=
":" ) {
283 std::vector<std::string>
tags;
285 while (
pos!=std::string::npos ) {
323 s <<
"[ " <<
a.tag() << (
a.log() ?
" : log" :
"" ) <<
" ";
324 if (
a.autoset() )
s <<
" : auto";
325 else if (
a.rangeset() )
s <<
" : range " <<
a.lo() <<
" - " <<
a.hi();
378 void AddEntry( TObject* tobj,
const std::string&
s,
const std::string&
type=
"p" ) {
379 m_obj.push_back( tobj );
401 m_leg->SetBorderSize(0);
402 m_leg->SetTextFont(42);
403 m_leg->SetTextSize(0.04);
404 m_leg->SetFillStyle(3000);
405 m_leg->SetFillColor(0);
406 m_leg->SetLineColor(0);
437 tg->SetLineColor(
h->GetLineColor() );
438 tg->SetMarkerColor(
h->GetMarkerColor() );
439 tg->SetMarkerStyle(
h->GetMarkerStyle() );
440 tg->SetMarkerSize(
h->GetMarkerSize() );
441 tg->SetLineWidth(
h->GetLineWidth() );
442 tg->SetLineStyle(
h->GetLineStyle() );
448 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ )
h->SetBinError(
i, 1
e-100 );
500 gStyle->SetOptStat(0);
503 href()->SetLineStyle(2);
504 href()->SetMarkerStyle(0);
509 htest()->SetLineStyle(1);
520 std::cout << std::endl;
526 htest()->GetXaxis()->SetMoreLogLabels(
true);
536 htest()->GetXaxis()->SetMoreLogLabels(
true);
550 else href()->Draw(
"hist same");
564 if (
htest()->GetMarkerStyle()>23 ) {
566 TH1D* hnull = (TH1D*)
htest()->Clone(
"duff"); hnull->SetDirectory(0);
568 hnull->SetLineColor(kWhite);
569 hnull->SetMarkerStyle(
htest()->GetMarkerStyle()-4 );
571 hnull->SetMarkerColor(kWhite);
572 hnull->SetMarkerSize(
htest()->GetMarkerSize()*0.75 );
574 hnull->DrawCopy(
"l same");
579 htest()->Draw(
"ep same");
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);
603 bool displayref =
false;
607 std::sprintf( meanrefc,
" <t> = %3.2f #pm %3.2f ms (ref)", muref.
mean(), muref.
error() );
610 std::sprintf( meanrefc,
"%s",
"" );
615 std::sprintf( meanc,
" <t> = %3.2f #pm %3.2f ms", mutest.
mean(), mutest.
error() );
617 std::string dkey =
key;
619 std::string
remove[7] = {
"TIME_",
"Time_",
"All_",
"Algorithm_",
"Class_",
"HLT_",
"Chain_HLT_" };
621 if ( dkey.find(
"Chain")!=std::string::npos ) {
622 if ( dkey.find(
"__")!=std::string::npos ) dkey.erase( 0, dkey.find(
"__")+2 );
626 for (
int ir=0 ;
ir<7 ;
ir++ ) {
630 std::string rkey = dkey;
634 dkey += std::string(
" : ");
636 if ( (dkey+meanc).
size()>58 ) {
638 leg.AddEntry( hnull, meanc,
"p" );
641 leg.AddEntry(
htest(), (dkey+meanc).c_str(),
"p" );
645 rkey += std::string(
" : ");
649 if ( (rkey+meanrefc).
size()>58 ) {
650 leg.AddEntry(
href(), rkey,
"l" );
651 leg.AddEntry( hnull, meanrefc,
"l" );
654 leg.AddEntry(
href(), (rkey+meanrefc).c_str(),
"l" );
666 if ( drawlegend )
leg.Draw();
677 gStyle->SetOptStat(0);
680 href()->SetLineStyle(2);
681 href()->SetMarkerStyle(0);
685 htest()->SetLineStyle(1);
690 std::cout << std::endl;
696 htest()->GetXaxis()->SetMoreLogLabels(
true);
706 htest()->GetXaxis()->SetMoreLogLabels(
true);
722 else href()->Draw(
"hist same");
738 if (
htest()->GetMarkerStyle()>23 ) {
740 TH1D* hnull = (TH1D*)
htest()->Clone(
"duff"); hnull->SetDirectory(0);
742 hnull->SetLineColor(kWhite);
743 hnull->SetMarkerStyle(
htest()->GetMarkerStyle()-4 );
745 hnull->SetMarkerColor(kWhite);
746 hnull->SetMarkerSize(
htest()->GetMarkerSize()*0.75 );
748 hnull->DrawCopy(
"l same");
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);
773 bool displayref =
false;
777 std::sprintf( meanrefc,
" <t> = %3.2f #pm %3.2f ms (ref)", muref.
mean(), muref.
error() );
780 std::sprintf( meanrefc,
"%s",
"" );
786 std::sprintf( meanc,
" <t> = %3.2f #pm %3.2f ms", mutest.
mean(), mutest.
error() );
788 std::string dkey =
key;
790 std::string
remove[7] = {
"TIME_",
"Time_",
"All_",
"Algorithm_",
"Class_",
"HLT_",
"Chain_HLT_" };
792 if ( dkey.find(
"Chain")!=std::string::npos ) {
793 if ( dkey.find(
"__")!=std::string::npos ) dkey.erase( 0, dkey.find(
"__")+2 );
797 for (
int ir=0 ;
ir<7 ;
ir++ ) {
801 std::string rkey = dkey;
805 dkey += std::string(
" : ");
807 if ( (dkey+meanc).
size()>58 ) {
809 leg.AddEntry( hnull, meanc,
"p" );
812 leg.AddEntry(
htest(), (dkey+meanc).c_str(),
"p" );
816 rkey += std::string(
" : ");
819 if ( (rkey+meanrefc).
size()>58 ) {
820 leg.AddEntry(
href(), rkey,
"l" );
821 leg.AddEntry( hnull, meanrefc,
"l" );
824 leg.AddEntry(
href(), (rkey+meanrefc).c_str(),
"l" );
836 if ( drawlegend )
leg.Draw();
845 if (
s!=
"" ) gPad->Print(
s.c_str());
904 std::cout << __FUNCTION__ << std::endl;
905 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
906 double duff =
h->GetBinContent(
i);
908 std::cout<<
"\t\t" << __FUNCTION__ <<
" " <<
h->GetName() <<
" " <<
i <<
" " <<
h->GetBinContent(
i) <<
" " << (duff*1e6) << std::endl;
912 gPad->Print( (std::string(
"duff-")+
h->GetName()+
".pdf").c_str() );
917 class Plots :
public std::vector<Plotter> {
934 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
936 if ( rmtest!=0 && (
first ||
min>rmtest ) )
min = rmtest;
937 if ( rmtest!=0 )
first =
false;
945 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
948 if ( rmtest!=0 && (
first ||
max<rmtest ) )
max = rmtest;
949 if ( rmtest!=0 )
first =
false;
958 if (
size()<1 )
return;
967 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
968 if ( at(
i).href() ) at(
i).href()->SetMaximum(
scale*tmax);
969 at(
i).htest()->SetMaximum(
scale*tmax);
977 if (
size()<1 )
return;
980 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
981 if ( at(
i).href() ) at(
i).href()->SetMinimum(0);
982 at(
i).htest()->SetMinimum(0);
995 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
996 if ( at(
i).href() ) at(
i).href()->SetMinimum(
scale*tmin);
997 at(
i).htest()->SetMinimum(
scale*tmin);
1004 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1005 if ( at(
i).href() ) at(
i).href()->SetMinimum(
scale);
1006 at(
i).htest()->SetMinimum(
scale);
1008 if ( at(
i).
href() )
if ( at(
i).
href()->GetMinimum()<=0 ) at(
i).href()->GetMinimum(1
e-4);
1009 if ( at(
i).
htest()->GetMinimum()<=0 ) at(
i).htest()->GetMinimum(1
e-4);
1017 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1018 if ( at(
i).href() ) at(
i).href()->SetMaximum(
scale);
1019 at(
i).htest()->SetMaximum(
scale);
1028 std::vector<double>
v(2,0);
1030 TH1F* hf = at(0).htest();
1035 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1036 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1042 for (
unsigned i=1 ;
i<
size() ;
i++ ) {
1046 if ( ::
empty( hf ) )
continue;
1048 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1049 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1061 if (
v[0]>
lo )
v[0] =
lo;
1062 if (
v[1]<
hi )
v[1] =
hi;
1068 double upper = (
v[1]-
v[0] )*1.1 +
v[0];
1069 double lower =
v[0] - (
v[1]-
v[0] )*0.1;
1072 double dx = std::log10(
v[1])-std::log10(
v[0]);
1077 if ( lower<vlo ) lower = vlo;
1106 else if (
size() == 0)
1108 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;
1128 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1129 if ( at(
i).href() ) ::
xrange( at(
i).href(), symmetric );
1138 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1139 if ( at(
i).href() ) at(
i).href()->GetXaxis()->SetRangeUser(
m_lo,
m_hi );
1140 at(
i).htest()->GetXaxis()->SetRangeUser(
m_lo,
m_hi );
1149 std::cout <<
"\tlimits \t" <<
m_name <<
"\tmin " << rmin <<
"\tmax " << rmax << std::endl;
1170 double ymax = at(
i).htest()->GetMaximum();
1171 double ymin = at(
i).htest()->GetMinimum();
1172 at(
i).htest()->GetYaxis()->SetMoreLogLabels(
true);
1173 if (
ymax/
ymin>1e6 ) at(
i).htest()->GetYaxis()->SetMoreLogLabels(
false);
1197 if (
size()>0 )
return at(0).htest()->GetXaxis()->GetTitle();
1202 if (
size()>0 )
return at(0).htest()->GetYaxis()->GetTitle();
1207 if (
size()>0 ) at(0).htest()->GetXaxis()->SetTitle(
s.c_str());
1211 if (
size()>0 ) at(0).htest()->GetYaxis()->SetTitle(
s.c_str());
1218 std::vector<Plotter>::push_back(
val );
1314 return s <<
"[ " <<
h.name() <<
" \tx: \"" <<
h.xtitle() <<
"\" " <<
h.xaxis() <<
"\t\ty: \"" <<
h.ytitle() <<
"\" " <<
h.yaxis() <<
" ]";
1373 s <<
"Panel: " <<
p.name();
1374 if (
p.size() == 1 )
s <<
"\t" <<
p[0];
1375 else for (
size_t i=0 ;
i<
p.size() ;
i++ )
s <<
"\n\t" <<
p[
i];
1383 #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)
tPlotter(T *htest=0, T *href=0, const std::string &s="", TGraphAsymmErrors *tgtest=0, TGraphAsymmErrors *tgref=0)
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)
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