31#include "TDirectory.h"
48int colours[6] = { 1, 2, kBlue-4, 6, kCyan-2, kMagenta+2 };
49int markers[6] = { 20, 24, 25, 26, 25, 22 };
50double msizes[6] = { 0.85, 1, 1, 1, 1, 1 };
53void band_intersect(
double& x0,
double& x1,
double& y0,
double& y1,
double ylo,
double yhi ) {
62 if ( y0>ylo && y1<ylo) {
64 double x = (ylo-y0)*(x1-x0)/(y1-y0)+x0;
69 if ( y0<ylo && y1>ylo) {
71 double x = x1-(y1-ylo)*(x1-x0)/(y1-y0);
76 if ( y0<ylo && y1<ylo) {
90 if ( y0<yhi && y1>yhi) {
92 double x = (yhi-y0)*(x1-x0)/(y1-y0)+x0;
97 if ( y0>yhi && y1<yhi) {
99 double x = x1-(y1-yhi)*(x1-x0)/(y1-y0);
115void band_plot( TH1*
h,
double xlo,
double xhi,
double ylo,
double yhi ) {
123 for (
int i=
h->GetNbinsX()+1 ; i-- ; ) {
124 double yt =
h->GetBinContent(i);
125 if ( last && (
yt<ylo || (
yt==0 && ylo==0 ) ) )
continue;
133 if (
contains( std::string(
h->GetName()),
"vs_mu") )
h->GetXaxis()->SetRangeUser( 18, 58 );
134 if (
contains( std::string(
h->GetName()),
"a0_eff") )
h->GetXaxis()->SetRangeUser( -190, 200 );
138 for (
int i=1 ; i<=
h->GetNbinsX()+1 ; i++ ) {
140 double x0 =
h->GetBinCenter(i);
141 double x1 =
h->GetBinCenter(i+1);
144 if (
contains( std::string(
h->GetName()),
"vs_mu") && x0<18 )
continue;
145 if (
contains( std::string(
h->GetName()),
"vs_mu") && x1>58 )
continue;
147 if (
contains( std::string(
h->GetName()),
"a0_eff") && x0<-200 )
continue;
148 if (
contains( std::string(
h->GetName()),
"a0_eff") && x1> 200 )
continue;
153 if ( ifirst<0 ) ifirst = i;
162 if ( xlo!=-999 && x0<xlo )
continue;
163 if ( xhi!=-999 && x1>xhi )
continue;
165 double y0_up =
h->GetBinContent(i) +
h->GetBinError(i);
166 double y1_up =
h->GetBinContent(i+1) +
h->GetBinError(i+1);
167 double y0_lo =
h->GetBinContent(i) -
h->GetBinError(i);
168 double y1_lo =
h->GetBinContent(i+1) -
h->GetBinError(i+1);
173 TLine*
t0 =
new TLine( x0, y0_up, x1, y1_up );
174 TLine* t1 =
new TLine( x0_1, y0_lo, x1_1, y1_lo );
176 t0->SetLineColor(
h->GetLineColor() );
179 t1->SetLineColor(
h->GetLineColor() );
190 if (
h->GetLineColor()>10 )
h->SetFillStyle(3395);
191 else h->SetFillStyle(3354);
193 h->SetFillColor(
h->GetLineColor());
204 for (
int i=
h->GetNbinsX()+1 ; --i ; ) n +=
h->GetBinContent(i);
211 for (
int i=
h->GetNbinsX() ; i>0 ; i-- ) n +=
h->GetBinContent(i);
221 for (
int i=
h->GetNbinsX()+2 ; --i ; ) n +=
h->GetBinContent(i);
224 for (
int i=
h->GetNbinsX()+2 ; --i ; ) {
225 double x =
h->GetBinCenter(i);
232 for (
int i=
h->GetNbinsX()+2 ; --i ; ) {
233 h->SetBinContent(i,
h->GetBinContent(i)*in );
234 h->SetBinError(i,
h->GetBinError(i)*in );
249 for (
int i=0 ; i<
h->GetNbinsX() ; i++ ) {
250 double w =
h->GetBinLowEdge(i+2)-
h->GetBinLowEdge(i+1);
251 f +=
h->GetBinContent(i+1)*w;
252 fx +=
h->GetBinContent(i+1)*w*
h->GetBinCenter(i+1);
253 fx2 +=
h->GetBinContent(i+1)*w*
h->GetBinCenter(i+1)*
h->GetBinCenter(i+1);
289 if (
a.f == b.f )
return true;
292 if (
a.negative() != b.negative() )
return false;
295 int ulps_diff = std::abs(
a.i - b.i );
296 if (ulps_diff <= max_diff)
return true;
315 double ylo =
h->GetMinimum();
319 for (
int i=0 ; i<t->GetN() && ih<=h->GetNbinsX() ; i++, ih++ ) {
325 t->GetPoint( i,
xt,
yt );
326 ye = t->GetErrorYlow( i );
328 double yh =
h->GetBinContent(ih);
329 double xh =
h->GetBinCenter(ih);
333 yh =
h->GetBinContent(ih);
334 xh =
h->GetBinCenter(ih);
339 if ( (
yt-ye) < ylo ) {
340 h->SetBinContent(ih, ylo-100 );
341 t->SetPoint( i,
xt, ylo-10000 );
350 TLatex* lat =
new TLatex();
352 lat->SetTextFont(72);
353 lat->SetTextColor(
color);
354 lat->SetTextSize(
size);
355 lat->DrawLatex(
x,
y,
"ATLAS");
357 TLatex* lat2 =
new TLatex();
359 lat2->SetTextFont(52);
360 lat2->SetTextColor(
color);
361 lat2->SetTextSize(
size);
362 lat2->DrawLatex(
x+0.13,
y,
"For Approval");
365void myText( Double_t
x, Double_t
y, Color_t
color,
const std::string& text, Double_t tsize) {
367 TLatex lat; lat.SetTextAlign(12); lat.SetTextSize(tsize);
369 lat.SetTextColor(
color);
370 lat.DrawLatex(
x,
y,text.c_str());
377 return label(
"%s", ctime(&t) );
382bool contains(
const std::string& s,
const std::string& p) {
383 return (s.find(p)!=std::string::npos);
387bool contains(
const std::string& s,
char p)
noexcept {
388 return (s.find(p)!=std::string::npos);
393bool fcontains(
const std::string& s,
const std::string& p) {
394 return (s.find(p)==0);
401 double xlo =
h->GetBinLowEdge(1);
402 double xhi =
h->GetBinLowEdge(
h->GetNbinsX()+1);
407 for (
int i=
h->GetNbinsX()+1 ; --i ; ) {
408 if (
h->GetBinCenter(i)>xlo &&
h->GetBinCenter(i)<xhi ) n +=
h->GetBinContent(i);
415bool exists(
const std::string& filename ) {
417 if ( stat( filename.c_str(), &sb)==0 )
return true;
428 glob( s.c_str(), GLOB_TILDE, 0, &glob_result );
430 std::vector<std::string> ret;
431 for(
unsigned i=0 ; i<glob_result.gl_pathc ; i++ ){
432 ret.push_back( std::string(glob_result.gl_pathv[i]) );
434 globfree(&glob_result);
438 std::cerr <<
"no matching file: " << s << std::endl;
442 if ( ret.size()>1 ) {
443 for (
unsigned i=0 ; i<ret.size() ; i++ ) {
444 std::cout <<
"matched " << ret[i] << std::endl;
456 for (
int i=
h->GetNbinsX() ; i>0 ; i-- )
if (
h->GetBinContent(i)!=0 )
return false;
461std::string
tail( std::string s,
const std::string& pattern ) {
462 size_t pos = s.find(pattern);
463 while ( pos != std::string::npos ) {
465 pos = s.find(pattern);
471std::string
head( std::string s,
const std::string& pattern ) {
472 size_t pos = s.find_last_of(pattern);
473 if ( pos != std::string::npos ) {
474 s.erase( pos, s.size() );
480void contents( std::vector<std::string>& keys, TDirectory* td,
481 const std::string& directory,
const std::string& pattern,
const std::string& path ) {
490void contents( std::vector<std::string>& keys, TDirectory* td,
491 const std::string& directory,
const std::vector<std::string>&
patterns,
const std::string& path ) {
495 TList* tl = td->GetListOfKeys();
497 for (
int i=tl->GetSize() ; i-- ; ) {
499 TKey* tobj = (TKey*)tl->At(i);
501 if ( tobj==0 )
continue;
503 if ( std::string(tobj->GetClassName()).find(
"TDirectory")!=std::string::npos ) {
505 TDirectory* tnd = (TDirectory*)tobj->ReadObj();
508 std::string dname = tnd->GetName();
510 std::string newpath = path+dname+
"/";
517 if ( directory ==
"" ||
contains( path, directory ) ) {
521 for (
size_t i=
patterns.size() ; i-- ; ) {
523 if (
contains(std::string(tobj->GetName()), pattern ) ) matched &=
true;
524 else matched =
false;
527 if (
print ) std::cout <<
"will process " << td->GetName() <<
" \t:: " << tobj->GetName() <<
"\tpatterns: " <<
patterns.size() << std::endl;
529 keys.push_back( path+tobj->GetName() );
540double realmax( TH1*
h,
bool include_error,
double lo,
double hi ) {
543 if (
h->GetNbinsX()==0 )
return 0;
546 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
549 double c =
h->GetBinCenter(i);
550 if ( lo>c || hi<c )
continue;
553 double re =
h->GetBinContent(i);
554 if ( include_error )
re +=
h->GetBinError(i);
556 if ( first || rm<
re ) {
568double realmin( TH1*
h,
bool ,
double lo,
double hi ) {
570 if (
h->GetNbinsX()==0 )
return 0;
575 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
578 double c =
h->GetBinCenter(i);
579 if ( lo>c || hi<c )
continue;
582 double re =
h->GetBinContent(i);
586 if ( first || rm>
re ) rm =
re;
598 for (
int i=
h->GetNbinsX() ; i>0 ; i-- ) {
599 n +=
h->GetBinContent(i);
600 if ( 2*n>N )
return h->GetBinCenter(i);
611 int ihi =
h->GetNbinsX();
613 h->GetXaxis()->SetRange( ilo, ihi );
615 std::vector<int> limits(2,0);
619 if (
empty(
h) )
return limits;
624 for ( ; ilo<=ihi ; ilo++ )
if (
h->GetBinContent(ilo)!=0 )
break;
625 for ( ; ihi>=ilo ; ihi-- )
if (
h->GetBinContent(ihi)!=0 )
break;
633 double icont = 1/content;
637 for ( ; ilo<=ihi ; ilo++ ) {
638 flo +=
h->GetBinContent(ilo);
639 if ( (flo*icont)>0.0005 )
break;
642 for ( ; ihi>=ilo ; ihi-- ) {
643 fhi +=
h->GetBinContent(ihi);
644 if ( (fhi*icont)>0.0005 )
break;
649 int delta_lo = ilo-1;
650 int delta_hi =
h->GetNbinsX()-ihi;
653 if ( delta_hi<delta_lo ) {
654 limits[0] = 1+delta_hi;
658 limits[0] = 1+delta_lo;
659 limits[1] =
h->GetNbinsX()-delta_lo;
665 if ( ihi<h->GetNbinsX() ) ihi++;
678 std::vector<int> limits =
findxrange(
h, symmetric );
679 h->GetXaxis()->SetRange( limits[0], limits[1] );
687 std::vector<int> limits =
findxrange(
h, symmetric );
689 std::vector<double> dlimits(2,0);
691 double dx =
h->GetBinLowEdge(limits[1]+1)-
h->GetBinLowEdge(limits[1]);
693 dlimits[0] =
h->GetBinLowEdge(limits[0]);
694 dlimits[1] =
h->GetBinLowEdge(limits[1]+1)-dx*1e-11;
702 h->GetXaxis()->SetRangeUser( limits[0], limits[1] );
707std::string
findcell( std::string name,
const std::string& regex,
const std::string& splitex ) {
709 size_t posex = name.find( regex );
711 if ( posex==std::string::npos )
return "";
713 size_t pos = name.find_last_of( splitex );
715 std::string duff = name;
717 while ( pos!=std::string::npos && pos>posex+regex.size() ) {
719 pos = name.find_last_of( splitex );
722 pos = name.find( regex );
724 name = name.substr( pos, name.size() );
726 pos = name.find( splitex );
728 if ( pos!=std::string::npos )
return name.substr( 0, pos );
737 TDirectory* here = gDirectory;
741 std::cout <<
"gDirectory::GetName() " << gDirectory->GetName() << std::endl;
747 TList* tl = gDirectory->GetListOfKeys();
751 for (
int i=0 ; i<tl->GetSize() ; i++ ) {
753 TKey* tobj = (TKey*)tl->At(i);
755 if ( tobj==0 )
continue;
757 if ( std::string(tobj->GetClassName()).find(
"TDirectory")!=std::string::npos ) {
759 TDirectory* tnd = (TDirectory*)tobj->ReadObj();
761 std::string name = tnd->GetName();
763 if ( name.find(
"run_" )==0 ) {
782 std::vector<std::string> release_data;
784 if ( finput && foutdir ) {
786 TTree*
tree = (TTree*)finput->Get(
"dataTree");
787 TTree* clone =
tree->CloneTree();
790 clone->Write(
"", TObject::kOverwrite);
size_t size() const
Number of registered mappings.
void print(char *figname, TCanvas *c1)
static const Attributes_t empty
Header file for AthHistogramAlgorithm.
std::string findcell(std::string name, const std::string ®ex, const std::string &splitex)
bool contains(const std::string &s, const std::string &p)
contains a string
void band_intersect(double &x0, double &x1, double &y0, double &y1, double ylo, double yhi)
void copyReleaseInfo(TFile *finput, TFile *foutdir)
copy the release info TTree
std::vector< double > findxrangeuser(TH1 *h, bool symmetric)
void xrange(TH1 *h, bool symmetric)
std::string stime()
return the current data and time
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
void xrangeuser(TH1 *h, bool symmetric)
bool operator==(floaty_t a, floaty_t b)
std::string globbed(const std::string &s)
match a file name
double realmax(TH1 *h, bool include_error, double lo, double hi)
void Norm(TH1 *h, double scale, double xmin, double xmax)
std::string findrun(TFile *f)
bool exists(const std::string &filename)
does a file exist
std::string tail(std::string s, const std::string &pattern)
tail of a string
std::vector< int > findxrange(TH1 *h, bool symmetric)
automatically set the xrange on a histogram
double realmin(TH1 *h, bool, double lo, double hi)
void band_plot(TH1 *h, double xlo, double xhi, double ylo, double yhi)
void ATLASFORAPP_LABEL(double x, double y, int color, double size)
void trim_tgraph(TH1 *h, TGraphAsymmErrors *t)
void myText(Double_t x, Double_t y, Color_t color, const std::string &text, Double_t tsize)
std::string head(std::string s, const std::string &pattern)
head of a string
bool almost_equal(floaty_t a, floaty_t b, int max_diff)
bool fcontains(const std::string &s, const std::string &p)
contains a string at the beginning of the string
std::string label(const std::string &format, int i)
std::vector< std::string > patterns
int32_t raw_mantissa() const
float has 23 bit mentissa
bool negative() const
portable extraction of components sign
int32_t raw_exponent() const
and an 8 bit exponent