25#include "TDirectory.h"
51int colours[4] = { kBlack, kRed, kBlue, kMagenta };
67bool contains(
const std::string& s,
const std::string& regex ) {
return s.find(regex)!=std::string::npos; }
74std::ostream&
operator<<( std::ostream& s,
const std::vector<T*>& t ) {
75 for (
size_t i=0 ; i<t.size() ; i++ ) s << *t[i] <<
"\n";
81 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
82 double d =
h->GetBinLowEdge(i+1)-
h->GetBinLowEdge(i);
83 h->SetBinContent( i,
h->GetBinContent(i)/d );
84 h->SetBinError( i,
h->GetBinError(i)/d );
89std::ostream&
operator<<( std::ostream& s,
const std::vector<T>& t ) {
90 for (
size_t i=0 ; i<t.size() ; i++ ) s << t[i] <<
"\n";
98 for (
int i=
h->GetNbinsX()+1 ; i-- ; ) {
99 double d =
h->GetBinContent(i);
100 if ( d!=0 && unset ) {
110 h->SetMinimum(
mn*0.1);
111 h->SetMaximum(mx*10);
117 if (
h &&
h->GetEntries()>0 &&
h->GetNbinsX()>0 ) {
122 TH1D* nh =
new TH1D(
h->GetName(),
h->GetTitle(),
123 h->GetNbinsX(),
h->GetBinLowEdge(1),
h->GetBinLowEdge(
h->GetNbinsX()+1 ) );
126 TH1D* nh = (TH1D*)
h->Clone();
130 for (
int i=1 ; i<
h->GetNbinsX()+1 ; i++ ) {
131 n +=
h->GetBinContent(i);
132 nh->SetBinContent( i,
h->GetBinContent(i) );
144 double vhmax =
h->GetBinContent(1);
145 for (
int i=2 ; i<
h->GetNbinsX() ; i++ ) {
146 double vm =
h->GetBinContent(i);
147 if ( vm>vhmax ) vhmax = vm;
158 const std::string& t,
159 TKey* k, TDirectory* d=0,
160 const std::vector<inode>& in=std::vector<inode>() )
178 s << t.m_name <<
" " << t.m_type;
197 for (
size_t i=0 ; i<
veto.size() ; i++ )
if (
contains(s,
veto[i]) )
return true;
225 std::string inspace =
spacer;
227 TDirectory* cck = gDirectory;
229 int deptht =
depth-1;
238 if ( deptht>=0 &&
size_t(deptht)<
directories.size() ) {
249 if ( !accept )
return;
259 TList* tl =
m_dir->GetListOfKeys();
262 for (
int i=tl->GetSize() ; i-- ; ) {
264 TKey* tobj = (TKey*)tl->At(i);
267 std::vector<inode> nodes;
273 if ( std::string(tobj->GetClassName()).find(
"TDirectory")!=std::string::npos ) {
274 tnd = (TDirectory*)tobj->ReadObj();
276 m_nodes.push_back(
inode( tobj->GetName(), tobj->GetClassName(), tobj, tnd, nodes ) );
282 if (
patterns.empty() ) accept =
true;
284 for (
unsigned ip=
patterns.size() ; ip-- ; ) {
285 if ( std::string( tobj->GetName()).find(
patterns[ip] )!=std::string::npos ) accept =
true;
290 for (
unsigned ip=
Patterns.size() ; ip-- ; ) {
291 if ( std::string( tobj->GetName()).find(
Patterns[ip] )==std::string::npos ) accept =
false;
295 if ( accept &&
isvetoed(tobj->GetName()) ) accept =
false;
298 m_nodes.push_back(
inode( tobj->GetName(), tobj->GetClassName(), tobj ) );
305 if ( std::string( tobj->GetClassName()).find(
"TH1")!=std::string::npos ) {
306 TH1*
h = (TH1*)tobj->ReadObj();
310 std::cout <<
"\tentries " <<
h->GetEntries() <<
" \tmean " <<
h->GetMean() <<
"\tplot " <<
plot <<
"\t";
319 h->SetMaximum(
hmax(
h)*1.2 );
321 std::string t = tobj->GetName();
323 if ( t.find(
"____")!=std::string::npos ) t.erase( 0, t.find(
"___")+4);
324 if ( t.find(
"_FirstTime")!=std::string::npos ) t.erase( t.find(
"_FirstTime"), t.size());
326 h->SetTitle(t.c_str());
338 h->SetMaximum(
ymax );
344 h->DrawCopy(
"samehist");
349 if (
logy ) gPad->SetLogy(
true);
350 gPad->Print( (std::string(tobj->GetName())+
".pdf").c_str() );
359 std::cout << std::endl;
364 std::string cckname = tobj->GetName();
365 TDirectory* cck = gDirectory;
368 std::string tdir =
chop( cckname,
"____" );
370 if ( cckname.size()==0 ) {
371 h->SetName( tdir.c_str() );
378 h->SetName( cckname.c_str() );
386 std::cout << std::endl;
393 if ( cck ) cck->cd();
395 spacer = std::move(inspace);
416std::vector<std::string>
split( std::string s,
const std::string& regex ) {
418 std::vector<std::string> out;
420 size_t pos = s.find(regex);
422 while ( pos!=std::string::npos ) {
423 out.push_back( s.substr( 0, pos ) );
428 out.push_back( std::move(s) );
444 std::cout << t.scan(
depth ) << std::endl;
456int main(
int argc,
char** argv) {
458 gStyle->SetPadLeftMargin(0.15);
459 gStyle->SetPadBottomMargin(0.15);
461 std::vector<std::string>
files;
463 std::string dir =
"";
467 std::string outfile =
"";
470 for (
int i=1 ; i<argc ; i++ ) {
472 std::string arg = argv[i];
475 if (++i < argc) outfile = argv[i];
478 else if ( arg==
"--depth" ) {
479 if (++i < argc)
maxdepth = std::atoi(argv[i]);
482 else if ( arg==
"-d" ) {
483 if (++i < argc) dir = argv[i];
486 else if ( arg==
"-p" ) {
487 if (++i < argc)
patterns.push_back( argv[i] );
490 else if ( arg==
"-v" ) {
491 if (++i < argc)
veto.push_back( argv[i] );
494 else if ( arg==
"--min" ) {
495 if (++i < argc)
minmean = std::atof( argv[i] );
498 else if ( arg==
"--max" ) {
499 if (++i < argc)
maxmean = std::atof( argv[i] );
502 else if ( arg==
"--entries" ) {
503 if (++i < argc)
entries = std::atof( argv[i] );
506 else if ( arg==
"-P" ) {
507 if (++i < argc)
Patterns.push_back( argv[i] );
510 else if ( arg==
"--xmax" ) {
511 if (++i < argc)
xmax = std::atof( argv[i] );
514 else if ( arg==
"--xmax" ) {
515 if (++i < argc)
xmax = std::atof( argv[i] );
518 else if ( arg==
"--xmin" ) {
519 if (++i < argc)
xmin = std::atof( argv[i] );
522 else if ( arg==
"--ymin" ) {
523 if (++i < argc)
ymin = std::atof( argv[i] );
526 else if ( arg==
"--ymax" ) {
527 if (++i < argc)
ymax = std::atof( argv[i] );
530 else if ( arg==
"--plot" )
plot =
true;
531 else if ( arg==
"--logy" )
logy =
true;
532 else if ( arg==
"--overlay" )
overlay =
true;
533 else if ( arg==
"--binwidth" )
binwidth =
true;
534 else files.push_back( std::move(arg) );
544 fout =
new TFile( outfile.c_str(),
"recreate" );
545 std::cout <<
"saving to file: " << outfile << std::endl;
549 for (
size_t i=0 ; i<
files.size() ; i++ ) {
551 TFile* f =
new TFile(
files[i].c_str() );
554 scan( gDirectory, 0 );
556 std::cout <<
"closing" << std::endl;
562 std::cout <<
"done" << std::endl;
these functions have a precision of about 0.001 ms
Header file for AthHistogramAlgorithm.
std::vector< inode > scan(int depth=0)
static std::string spacer
std::vector< inode > m_nodes
TCck(TDirectory *d, int depth=0)
TDirectory * m_dir
if this node is, itself a directory
std::vector< inode > m_nodes
inode(const std::string &n, const std::string &t, TKey *k, TDirectory *d=0, const std::vector< inode > &in=std::vector< inode >())
int ir
counter of the current depth
std::string depth
tag string for intendation
std::vector< std::string > files
file names and file pointers
std::string chop(std::string &s1, const std::string &s2)
std::string label(const std::string &format, int i)
std::vector< std::string > veto
these patterns are anded
double minmean
these patterns are vetoed
std::vector< std::string > directories
std::vector< std::string > Patterns
these patterns are ored
std::ostream & operator<<(std::ostream &s, const std::vector< T * > &t)
void scan(TDirectory *td=0, int depth=0)
bool contains(const std::string &s, const std::string ®ex)
does a string contain the substring
bool isvetoed(const std::string &s)
std::vector< std::string > split(std::string s, const std::string ®ex)
std::vector< std::string > patterns