|
ATLAS Offline Software
|
Go to the documentation of this file.
31 #include "TGraphAsymmErrors.h"
56 bool contains(
const std::string&
s,
const std::string&
p);
57 bool contains(
const std::string&
s,
char p) noexcept;
60 bool fcontains(
const std::string&
s,
const std::string&
p);
66 std::string
tail( std::string
s,
const std::string&
pattern );
69 std::string
head( std::string
s,
const std::string&
pattern );
72 std::string
globbed(
const std::string&
s );
78 const std::string&
path=
"" );
83 const std::vector<std::string>&
patterns=std::vector<std::string>(),
84 const std::string&
path=
"" );
87 double realmax( TH1*
h,
bool include_error=
true,
double lo=0,
double hi=0 );
88 double realmin( TH1*
h,
bool include_error=
true,
double lo=0,
double hi=0 );
90 std::string
findcell( std::string
name,
const std::string&
regex,
const std::string& splitex=
"/" );
100 virtual const char*
what()
const throw() {
return "data don't match"; }
107 for (
unsigned i=0 ;
i<
v.size() ;
i++ )
s <<
"\t" <<
v[
i];
113 std::vector<int>
findxrange(TH1*
h,
bool symmetric=
false );
121 void xrange(TH1*
h,
bool symmetric=
true );
167 std::vector<std::string>
keys =
split(
s,
":" );
176 for (
size_t i=1 ;
i<
keys.size() ;
i++ ) {
188 std::cout <<
"offset:" << std::endl;
189 std::cout <<
"\tkey: " <<
keys[
i] << std::endl;
190 std::cout <<
"\tpos: " <<
keys[
i].find(
"offset") << std::endl;
195 std::cout <<
"m_offset: " <<
m_offset << std::endl;
197 else if (
keys[
i]==
"auton" ) {
201 else if (
keys[
i]==
"autow" ) {
205 else if (
keys[
i]==
"autown" ||
keys[
i]==
"autonw" ) {
210 else if (
keys[
i]==
"autosym" ) {
214 else if (
keys[
i]==
"normw" ||
keys[
i]==
"widthn" ) {
218 else if ( !minset ) {
223 std::cerr <<
"not enough values for the axis range: " <<
s << std::endl;
233 std::cout <<
"AxisInfo::info" <<
m_info <<
"\n";
234 std::cout <<
"\tlog " <<
m_log <<
"\n";
235 std::cout <<
"\tauto " <<
m_autoset <<
"\n";
274 static std::vector<std::string>
split(
const std::string&
s,
const std::string&
t=
":" ) {
279 std::vector<std::string>
tags;
281 while (
pos!=std::string::npos ) {
319 s <<
"[ " <<
a.tag() << (
a.log() ?
" : log" :
"" ) <<
" ";
320 if (
a.autoset() )
s <<
" : auto";
321 else if (
a.rangeset() )
s <<
" : range " <<
a.lo() <<
" - " <<
a.hi();
374 void AddEntry( TObject* tobj,
const std::string&
s,
const std::string&
type=
"p" ) {
375 m_obj.push_back( tobj );
397 m_leg->SetBorderSize(0);
398 m_leg->SetTextFont(42);
399 m_leg->SetTextSize(0.04);
400 m_leg->SetFillStyle(3000);
401 m_leg->SetFillColor(0);
402 m_leg->SetLineColor(0);
433 tg->SetLineColor(
h->GetLineColor() );
434 tg->SetMarkerColor(
h->GetMarkerColor() );
435 tg->SetMarkerStyle(
h->GetMarkerStyle() );
436 tg->SetMarkerSize(
h->GetMarkerSize() );
437 tg->SetLineWidth(
h->GetLineWidth() );
438 tg->SetLineStyle(
h->GetLineStyle() );
444 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ )
h->SetBinError(
i, 1
e-100 );
458 tPlotter(
T* _htest=0,
T* _href=0,
const std::string&
s=
"", TGraphAsymmErrors* _tgtest=0, TGraphAsymmErrors* _tgref=0 ) :
496 gStyle->SetOptStat(0);
499 href()->SetLineStyle(2);
500 href()->SetMarkerStyle(0);
505 htest()->SetLineStyle(1);
516 std::cout << std::endl;
522 htest()->GetXaxis()->SetMoreLogLabels(
true);
532 htest()->GetXaxis()->SetMoreLogLabels(
true);
546 else href()->Draw(
"hist same");
560 if (
htest()->GetMarkerStyle()>23 ) {
562 TH1D* hnull = (TH1D*)
htest()->Clone(
"duff"); hnull->SetDirectory(0);
564 hnull->SetLineColor(kWhite);
565 hnull->SetMarkerStyle(
htest()->GetMarkerStyle()-4 );
567 hnull->SetMarkerColor(kWhite);
568 hnull->SetMarkerSize(
htest()->GetMarkerSize()*0.75 );
570 hnull->DrawCopy(
"l same");
575 htest()->Draw(
"ep same");
583 static TH1D* hnull =
new TH1D(
"hnull",
"", 1, 0, 1);
584 hnull->SetMarkerColor(kWhite);
585 hnull->SetLineColor(kWhite);
586 hnull->SetMarkerStyle(0);
587 hnull->SetLineStyle(0);
588 hnull->SetLineWidth(0);
589 hnull->SetMarkerSize(0);
599 bool displayref =
false;
603 std::sprintf( meanrefc,
" <t> = %3.2f #pm %3.2f ms (ref)", muref.
mean(), muref.
error() );
606 std::sprintf( meanrefc,
"%s",
"" );
611 std::sprintf( meanc,
" <t> = %3.2f #pm %3.2f ms", mutest.
mean(), mutest.
error() );
613 std::string dkey =
key;
615 std::string
remove[7] = {
"TIME_",
"Time_",
"All_",
"Algorithm_",
"Class_",
"HLT_",
"Chain_HLT_" };
617 if ( dkey.find(
"Chain")!=std::string::npos ) {
618 if ( dkey.find(
"__")!=std::string::npos ) dkey.erase( 0, dkey.find(
"__")+2 );
622 for (
int ir=0 ;
ir<7 ;
ir++ ) {
626 std::string rkey = dkey;
630 dkey += std::string(
" : ");
632 if ( (dkey+meanc).
size()>58 ) {
634 leg.AddEntry( hnull, meanc,
"p" );
637 leg.AddEntry(
htest(), (dkey+meanc).c_str(),
"p" );
641 rkey += std::string(
" : ");
645 if ( (rkey+meanrefc).
size()>58 ) {
646 leg.AddEntry(
href(), rkey,
"l" );
647 leg.AddEntry( hnull, meanrefc,
"l" );
650 leg.AddEntry(
href(), (rkey+meanrefc).c_str(),
"l" );
662 if ( drawlegend )
leg.Draw();
673 gStyle->SetOptStat(0);
676 href()->SetLineStyle(2);
677 href()->SetMarkerStyle(0);
681 htest()->SetLineStyle(1);
686 std::cout << std::endl;
692 htest()->GetXaxis()->SetMoreLogLabels(
true);
702 htest()->GetXaxis()->SetMoreLogLabels(
true);
718 else href()->Draw(
"hist same");
734 if (
htest()->GetMarkerStyle()>23 ) {
736 TH1D* hnull = (TH1D*)
htest()->Clone(
"duff"); hnull->SetDirectory(0);
738 hnull->SetLineColor(kWhite);
739 hnull->SetMarkerStyle(
htest()->GetMarkerStyle()-4 );
741 hnull->SetMarkerColor(kWhite);
742 hnull->SetMarkerSize(
htest()->GetMarkerSize()*0.75 );
744 hnull->DrawCopy(
"l same");
757 static TH1D* hnull =
new TH1D(
"hnull",
"", 1, 0, 1);
758 hnull->SetMarkerColor(kWhite);
759 hnull->SetLineColor(kWhite);
760 hnull->SetMarkerStyle(0);
761 hnull->SetLineStyle(0);
762 hnull->SetLineWidth(0);
763 hnull->SetMarkerSize(0);
769 bool displayref =
false;
773 std::sprintf( meanrefc,
" <t> = %3.2f #pm %3.2f ms (ref)", muref.
mean(), muref.
error() );
776 std::sprintf( meanrefc,
"%s",
"" );
782 std::sprintf( meanc,
" <t> = %3.2f #pm %3.2f ms", mutest.
mean(), mutest.
error() );
784 std::string dkey =
key;
786 std::string
remove[7] = {
"TIME_",
"Time_",
"All_",
"Algorithm_",
"Class_",
"HLT_",
"Chain_HLT_" };
788 if ( dkey.find(
"Chain")!=std::string::npos ) {
789 if ( dkey.find(
"__")!=std::string::npos ) dkey.erase( 0, dkey.find(
"__")+2 );
793 for (
int ir=0 ;
ir<7 ;
ir++ ) {
797 std::string rkey = dkey;
801 dkey += std::string(
" : ");
803 if ( (dkey+meanc).
size()>58 ) {
805 leg.AddEntry( hnull, meanc,
"p" );
808 leg.AddEntry(
htest(), (dkey+meanc).c_str(),
"p" );
812 rkey += std::string(
" : ");
815 if ( (rkey+meanrefc).
size()>58 ) {
816 leg.AddEntry(
href(), rkey,
"l" );
817 leg.AddEntry( hnull, meanrefc,
"l" );
820 leg.AddEntry(
href(), (rkey+meanrefc).c_str(),
"l" );
832 if ( drawlegend )
leg.Draw();
841 if (
s!=
"" ) gPad->Print(
s.c_str());
900 std::cout << __FUNCTION__ << std::endl;
901 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
902 double duff =
h->GetBinContent(
i);
904 std::cout<<
"\t\t" << __FUNCTION__ <<
" " <<
h->GetName() <<
" " <<
i <<
" " <<
h->GetBinContent(
i) <<
" " << (duff*1e6) << std::endl;
908 gPad->Print( (std::string(
"duff-")+
h->GetName()+
".pdf").c_str() );
913 class Plots :
public std::vector<Plotter> {
930 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
932 if ( rmtest!=0 && (
first ||
min>rmtest ) )
min = rmtest;
933 if ( rmtest!=0 )
first =
false;
941 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
944 if ( rmtest!=0 && (
first ||
max<rmtest ) )
max = rmtest;
945 if ( rmtest!=0 )
first =
false;
954 if (
size()<1 )
return;
963 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
964 if ( at(
i).href() ) at(
i).href()->SetMaximum(
scale*tmax);
965 at(
i).htest()->SetMaximum(
scale*tmax);
973 if (
size()<1 )
return;
976 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
977 if ( at(
i).href() ) at(
i).href()->SetMinimum(0);
978 at(
i).htest()->SetMinimum(0);
991 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
992 if ( at(
i).href() ) at(
i).href()->SetMinimum(
scale*tmin);
993 at(
i).htest()->SetMinimum(
scale*tmin);
1000 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1001 if ( at(
i).href() ) at(
i).href()->SetMinimum(
scale);
1002 at(
i).htest()->SetMinimum(
scale);
1004 if ( at(
i).href() )
if ( at(
i).href()->GetMinimum()<=0 ) at(
i).href()->GetMinimum(1
e-4);
1005 if ( at(
i).htest()->GetMinimum()<=0 ) at(
i).htest()->GetMinimum(1
e-4);
1013 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1014 if ( at(
i).href() ) at(
i).href()->SetMaximum(
scale);
1015 at(
i).htest()->SetMaximum(
scale);
1024 std::vector<double>
v(2,0);
1026 TH1F* hf = at(0).htest();
1031 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1032 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1038 for (
unsigned i=1 ;
i<
size() ;
i++ ) {
1042 if ( ::
empty( hf ) )
continue;
1044 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1045 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1057 if (
v[0]>
lo )
v[0] =
lo;
1058 if (
v[1]<
hi )
v[1] =
hi;
1064 double upper = (
v[1]-
v[0] )*1.1 +
v[0];
1065 double lower =
v[0] - (
v[1]-
v[0] )*0.1;
1068 double dx = std::log10(
v[1])-std::log10(
v[0]);
1073 if ( lower<vlo ) lower = vlo;
1102 else if (
size() == 0)
1104 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;
1124 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1125 if ( at(
i).href() ) ::
xrange( at(
i).href(), symmetric );
1134 for (
unsigned i=0 ;
i<
size() ;
i++ ) {
1135 if ( at(
i).href() ) at(
i).href()->GetXaxis()->SetRangeUser(
m_lo,
m_hi );
1136 at(
i).htest()->GetXaxis()->SetRangeUser(
m_lo,
m_hi );
1145 std::cout <<
"\tlimits \t" <<
m_name <<
"\tmin " << rmin <<
"\tmax " << rmax << std::endl;
1166 double ymax = at(
i).htest()->GetMaximum();
1167 double ymin = at(
i).htest()->GetMinimum();
1168 at(
i).htest()->GetYaxis()->SetMoreLogLabels(
true);
1169 if (
ymax/
ymin>1e6 ) at(
i).htest()->GetYaxis()->SetMoreLogLabels(
false);
1193 if (
size()>0 )
return at(0).htest()->GetXaxis()->GetTitle();
1198 if (
size()>0 )
return at(0).htest()->GetYaxis()->GetTitle();
1203 if (
size()>0 ) at(0).htest()->GetXaxis()->SetTitle(
s.c_str());
1207 if (
size()>0 ) at(0).htest()->GetYaxis()->SetTitle(
s.c_str());
1214 std::vector<Plotter>::push_back(
val );
1310 return s <<
"[ " <<
h.name() <<
" \tx: \"" <<
h.xtitle() <<
"\" " <<
h.xaxis() <<
"\t\ty: \"" <<
h.ytitle() <<
"\" " <<
h.yaxis() <<
" ]";
1369 s <<
"Panel: " <<
p.name();
1370 if (
p.size() == 1 )
s <<
"\t" <<
p[0];
1371 else for (
size_t i=0 ;
i<
p.size() ;
i++ )
s <<
"\n\t" <<
p[
i];
1379 #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)
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
std::string c_str() const
AxisInfo(const std::string &s)
Legend(const Legend &legend)
void push_back(const HistDetails &h)
std::vector< TObject * > m_obj
TGraphAsymmErrors * tgref()
std::string detail() const
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 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
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
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
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
static bool s_plotref
use non c++17 format for improved external compatability
void MinScale(double scale, double lo=0, double hi=0)
std::string plotfilename() const
class to store information about axes, limits, whether it is log or linear scale etc
std::string stime()
return the current data and time
std::string tag() const
accessors
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