31#include "TDirectory.h"
46int colours[6] = { 1, 2, kBlue-4, 6, kCyan-2, kMagenta+2 };
47int markers[6] = { 20, 24, 25, 26, 25, 22 };
48double msizes[6] = { 0.85, 1, 1, 1, 1, 1 };
54 for (
int i=
h->GetNbinsX()+1 ; --i ; ) n +=
h->GetBinContent(i);
61 for (
int i=
h->GetNbinsX() ; i>0 ; i-- ) n +=
h->GetBinContent(i);
67void Norm( TH1*
h,
double scale ) {
69 for (
int i=
h->GetNbinsX()+2 ; --i ; ) n +=
h->GetBinContent(i);
72 for (
int i=
h->GetNbinsX()+2 ; --i ; ) {
73 h->SetBinContent(i,
h->GetBinContent(i)*in );
74 h->SetBinError(i,
h->GetBinError(i)*in );
89 for (
int i=0 ; i<
h->GetNbinsX() ; i++ ) {
90 double w =
h->GetBinLowEdge(i+2)-
h->GetBinLowEdge(i+1);
91 f +=
h->GetBinContent(i+1)*w;
92 fx +=
h->GetBinContent(i+1)*w*
h->GetBinCenter(i+1);
93 fx2 +=
h->GetBinContent(i+1)*w*
h->GetBinCenter(i+1)*
h->GetBinCenter(i+1);
129 if (
a.f == b.f )
return true;
132 if (
a.negative() != b.negative() )
return false;
135 int ulps_diff = std::abs(
a.i - b.i );
136 if (ulps_diff <= max_diff)
return true;
155 double ylo =
h->GetMinimum();
159 for (
int i=0 ; i<t->GetN() && ih<=h->GetNbinsX() ; i++, ih++ ) {
165 t->GetPoint( i,
xt,
yt );
166 ye = t->GetErrorYlow( i );
168 double yh =
h->GetBinContent(ih);
169 double xh =
h->GetBinCenter(ih);
173 yh =
h->GetBinContent(ih);
174 xh =
h->GetBinCenter(ih);
179 if ( (
yt-ye) < ylo ) {
180 h->SetBinContent(ih, ylo-100 );
181 t->SetPoint( i,
xt, ylo-100 );
190 TLatex* lat =
new TLatex();
192 lat->SetTextFont(72);
193 lat->SetTextColor(
color);
194 lat->SetTextSize(size);
195 lat->DrawLatex(
x,
y,
"ATLAS");
197 TLatex* lat2 =
new TLatex();
199 lat2->SetTextFont(52);
200 lat2->SetTextColor(
color);
201 lat2->SetTextSize(size);
202 lat2->DrawLatex(
x+0.13,
y,
"For Approval");
205void myText( Double_t
x, Double_t
y, Color_t
color,
const std::string& text, Double_t tsize) {
208 TLatex lat; lat.SetTextAlign(12); lat.SetTextSize(tsize);
210 lat.SetTextColor(
color);
211 lat.DrawLatex(
x,
y,text.c_str());
218 return label(
"%s", ctime(&t) );
223bool contains(
const std::string& s,
const std::string& p) {
224 return (s.find(p)!=std::string::npos);
228bool contains(
const std::string& s,
char p)
noexcept {
229 return (s.find(p)!=std::string::npos);
234bool fcontains(
const std::string& s,
const std::string& p) {
235 return (s.find(p)==0);
242 double xlo =
h->GetBinLowEdge(1);
243 double xhi =
h->GetBinLowEdge(
h->GetNbinsX()+1);
248 for (
int i=
h->GetNbinsX()+1 ; --i ; ) {
249 if (
h->GetBinCenter(i)>xlo &&
h->GetBinCenter(i)<xhi ) n +=
h->GetBinContent(i);
256bool exists(
const std::string& filename ) {
258 if ( stat( filename.c_str(), &sb)==0 )
return true;
269 glob( s.c_str(), GLOB_TILDE, 0, &glob_result );
271 std::vector<std::string> ret;
272 for(
unsigned i=0 ; i<glob_result.gl_pathc ; i++ ){
273 ret.push_back( std::string(glob_result.gl_pathv[i]) );
275 globfree(&glob_result);
279 std::cerr <<
"no matching file: " << s << std::endl;
283 if ( ret.size()>1 ) {
284 for (
unsigned i=0 ; i<ret.size() ; i++ ) {
285 std::cout <<
"matched " << ret[i] << std::endl;
297 for (
int i=
h->GetNbinsX() ; i>0 ; i-- )
if (
h->GetBinContent(i)!=0 )
return false;
302std::string
tail( std::string s,
const std::string& pattern ) {
303 size_t pos = s.find(pattern);
304 while ( pos != std::string::npos ) {
306 pos = s.find(pattern);
312std::string
head( std::string s,
const std::string& pattern ) {
313 size_t pos = s.find_last_of(pattern);
314 if ( pos != std::string::npos ) {
315 s.erase( pos, s.size() );
321void contents( std::vector<std::string>& keys, TDirectory* td,
322 const std::string& directory,
const std::string& pattern,
const std::string& path ) {
331void contents( std::vector<std::string>& keys, TDirectory* td,
332 const std::string& directory,
const std::vector<std::string>&
patterns,
const std::string& path ) {
336 TList* tl = td->GetListOfKeys();
338 for (
int i=tl->GetSize() ; i-- ; ) {
340 TKey* tobj = (TKey*)tl->At(i);
342 if ( tobj==0 )
continue;
344 if ( std::string(tobj->GetClassName()).find(
"TDirectory")!=std::string::npos ) {
346 TDirectory* tnd = (TDirectory*)tobj->ReadObj();
349 std::string dname = tnd->GetName();
351 std::string newpath = path+dname+
"/";
358 if ( directory ==
"" ||
contains( path, directory ) ) {
362 for (
size_t i=
patterns.size() ; i-- ; ) {
363 const std::string& pattern =
patterns[i];
364 if (
contains(std::string(tobj->GetName()), pattern ) ) matched &=
true;
365 else matched =
false;
368 if (
print ) std::cout <<
"will process " << td->GetName() <<
" \t:: " << tobj->GetName() <<
"\tpatterns: " <<
patterns.size() << std::endl;
370 keys.push_back( path+tobj->GetName() );
381double realmax( TH1*
h,
bool include_error,
double lo,
double hi ) {
383 if (
h->GetNbinsX()==0 )
return 0;
386 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
389 double c =
h->GetBinCenter(i);
390 if ( lo>c || hi<c )
continue;
393 double re =
h->GetBinContent(i);
394 if ( include_error )
re +=
h->GetBinError(i);
396 if ( first || rm<
re ) {
408double realmin( TH1*
h,
bool ,
double lo,
double hi ) {
410 if (
h->GetNbinsX()==0 )
return 0;
415 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
418 double c =
h->GetBinCenter(i);
419 if ( lo>c || hi<c )
continue;
422 double re =
h->GetBinContent(i);
426 if ( first || rm>
re ) rm =
re;
438 for (
int i=
h->GetNbinsX() ; i>0 ; i-- ) {
439 n +=
h->GetBinContent(i);
440 if ( 2*n>N )
return h->GetBinCenter(i);
451 int ihi =
h->GetNbinsX();
453 h->GetXaxis()->SetRange( ilo, ihi );
455 std::vector<int> limits(2,0);
459 if (
empty(
h) )
return limits;
464 for ( ; ilo<=ihi ; ilo++ )
if (
h->GetBinContent(ilo)!=0 )
break;
465 for ( ; ihi>=ilo ; ihi-- )
if (
h->GetBinContent(ihi)!=0 )
break;
473 double icont = 1/content;
477 for ( ; ilo<=ihi ; ilo++ ) {
478 flo +=
h->GetBinContent(ilo);
479 if ( (flo*icont)>0.0005 )
break;
482 for ( ; ihi>=ilo ; ihi-- ) {
483 fhi +=
h->GetBinContent(ihi);
484 if ( (fhi*icont)>0.0005 )
break;
489 int delta_lo = ilo-1;
490 int delta_hi =
h->GetNbinsX()-ihi;
493 if ( delta_hi<delta_lo ) {
494 limits[0] = 1+delta_hi;
498 limits[0] = 1+delta_lo;
499 limits[1] =
h->GetNbinsX()-delta_lo;
505 if ( ihi<h->GetNbinsX() ) ihi++;
518 std::vector<int> limits =
findxrange(
h, symmetric );
519 h->GetXaxis()->SetRange( limits[0], limits[1] );
527 std::vector<int> limits =
findxrange(
h, symmetric );
529 std::vector<double> dlimits(2,0);
531 double dx =
h->GetBinLowEdge(limits[1]+1)-
h->GetBinLowEdge(limits[1]);
533 dlimits[0] =
h->GetBinLowEdge(limits[0]);
534 dlimits[1] =
h->GetBinLowEdge(limits[1]+1)-dx*1e-11;
542 h->GetXaxis()->SetRangeUser( limits[0], limits[1] );
547std::string
findcell( std::string name,
const std::string& regex,
const std::string& splitex ) {
549 size_t posex = name.find( regex );
551 if ( posex==std::string::npos )
return "";
553 size_t pos = name.find_last_of( splitex );
555 std::string duff = name;
557 while ( pos!=std::string::npos && pos>posex+regex.size() ) {
559 pos = name.find_last_of( splitex );
562 pos = name.find( regex );
564 name = name.substr( pos, name.size() );
566 pos = name.find( splitex );
568 if ( pos!=std::string::npos )
return name.substr( 0, pos );
577 TDirectory* here = gDirectory;
581 std::cout <<
"gDirectory::GetName() " << gDirectory->GetName() << std::endl;
587 TList* tl = gDirectory->GetListOfKeys();
591 for (
int i=0 ; i<tl->GetSize() ; i++ ) {
593 TKey* tobj = (TKey*)tl->At(i);
595 if ( tobj==0 )
continue;
597 if ( std::string(tobj->GetClassName()).find(
"TDirectory")!=std::string::npos ) {
599 TDirectory* tnd = (TDirectory*)tobj->ReadObj();
601 std::string name = tnd->GetName();
603 if ( name.find(
"run_" )==0 ) {
622 std::vector<std::string> release_data;
624 if ( finput && foutdir ) {
626 TTree*
tree = (TTree*)finput->Get(
"dataTree");
627 TTree* clone =
tree->CloneTree();
630 clone->Write(
"", TObject::kOverwrite);
const boost::regex re(r_e)
void print(char *figname, TCanvas *c1)
static const Attributes_t empty
Header file for AthHistogramAlgorithm.
void Norm(TH1 *h, double scale)
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 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)
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 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