ATLAS Offline Software
Loading...
Searching...
No Matches
listroot.cxx File Reference
#include "simpletimer.h"
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include "TH1F.h"
#include "TFile.h"
#include "TList.h"
#include "TKey.h"
#include "TPad.h"
#include "TStyle.h"
#include "TDirectory.h"
#include "TrigInDetAnalysis/TIDDirectory.h"
#include "utils.h"
#include "DrawLabel.h"
#include "label.h"

Go to the source code of this file.

Classes

class  inode
class  TCck

Functions

bool contains (const std::string &s, const std::string &regex)
 does a string contain the substring
template<typename T>
std::ostream & operator<< (std::ostream &s, const std::vector< T * > &t)
void binWidth (TH1 *h)
template<typename T>
std::ostream & operator<< (std::ostream &s, const std::vector< T > &t)
void minlog (TH1 *h)
double hmax (TH1 *&h)
std::ostream & operator<< (std::ostream &s, const inode &t)
bool isvetoed (const std::string &s)
std::vector< std::string > split (std::string s, const std::string &regex)
void scan (TDirectory *td=0, int depth=0)
int main (int argc, char **argv)

Variables

int ir = 0
bool dirflag = true
bool dbg = true
std::string cwd
bool overlay = false
bool plot = false
bool logy = false
bool drawmean = true
double entries = 0
int colours [4] = { kBlack, kRed, kBlue, kMagenta }
int styles [4] = { 1, 2, 3, 4 }
int istyle = 0
bool drawn = false
bool binwidth = false
double xmin = 0
double xmax = 0
double ymin = 0
double ymax = 0
std::vector< std::string > directories
std::vector< std::string > patterns
std::vector< std::string > Patterns
 these patterns are ored
std::vector< std::string > veto
 these patterns are anded
double minmean = 0
 these patterns are vetoed
double maxmean = 1e10
int maxdepth = 3

Detailed Description

Author
mark sutton
Date
Fri 11 Jan 2019 07:41:26 CET

Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration

Definition in file listroot.cxx.

Function Documentation

◆ binWidth()

void binWidth ( TH1 * h)

Definition at line 80 of file listroot.cxx.

80 {
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 );
85 }
86}
Header file for AthHistogramAlgorithm.

◆ contains()

bool contains ( const std::string & s,
const std::string & regex )

does a string contain the substring

does a string contain the substring

Definition at line 67 of file listroot.cxx.

67{ return s.find(regex)!=std::string::npos; }

◆ hmax()

double hmax ( TH1 *& h)

Definition at line 115 of file listroot.cxx.

115 {
116
117 if ( h && h->GetEntries()>0 && h->GetNbinsX()>0 ) {
118
119 h->SetDirectory(0);
120
121#if 0
122 TH1D* nh = new TH1D( h->GetName(), h->GetTitle(),
123 h->GetNbinsX(), h->GetBinLowEdge(1), h->GetBinLowEdge( h->GetNbinsX()+1 ) );
124#endif
125
126 TH1D* nh = (TH1D*)h->Clone();
127
128 double n = 0;
129
130 for ( int i=1 ; i<h->GetNbinsX()+1 ; i++ ) {
131 n += h->GetBinContent(i);
132 nh->SetBinContent( i, h->GetBinContent(i) );
133 }
134
135 nh->SetEntries( n );
136
137 // nh->GetXAxis()->SetTitle( h->GetXaxis()->GetTitle() );
138 // nh->GetYAxis()->SetTitle( h->GetYaxis()->GetTitle() );
139
140 h = nh;
141
142
143
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;
148 }
149 return vhmax;
150 }
151 return 0;
152}

◆ isvetoed()

bool isvetoed ( const std::string & s)

Definition at line 196 of file listroot.cxx.

196 {
197 for ( size_t i=0 ; i<veto.size() ; i++ ) if ( contains(s,veto[i]) ) return true;
198 return false;
199}
std::vector< std::string > veto
these patterns are anded
Definition listroot.cxx:191
bool contains(const std::string &s, const std::string &regex)
does a string contain the substring
Definition listroot.cxx:67

◆ main()

int main ( int argc,
char ** argv )

handle arguments

navigate files

Definition at line 456 of file listroot.cxx.

456 {
457
458 gStyle->SetPadLeftMargin(0.15);
459 gStyle->SetPadBottomMargin(0.15);
460
461 std::vector<std::string> files;
462
463 std::string dir = "";
464
466
467 std::string outfile = "";
468
469
470 for ( int i=1 ; i<argc ; i++ ) {
471
472 std::string arg = argv[i];
473
474 if ( arg=="-o" ) {
475 if (++i < argc) outfile = argv[i];
476 else return -1;
477 }
478 else if ( arg=="--depth" ) {
479 if (++i < argc) maxdepth = std::atoi(argv[i]);
480 else return -1;
481 }
482 else if ( arg=="-d" ) {
483 if (++i < argc) dir = argv[i];
484 else return -1;
485 }
486 else if ( arg=="-p" ) {
487 if (++i < argc) patterns.push_back( argv[i] );
488 else return -1;
489 }
490 else if ( arg=="-v" ) {
491 if (++i < argc) veto.push_back( argv[i] );
492 else return -1;
493 }
494 else if ( arg=="--min" ) {
495 if (++i < argc) minmean = std::atof( argv[i] );
496 else return -1;
497 }
498 else if ( arg=="--max" ) {
499 if (++i < argc) maxmean = std::atof( argv[i] );
500 else return -1;
501 }
502 else if ( arg=="--entries" ) {
503 if (++i < argc) entries = std::atof( argv[i] );
504 else return -1;
505 }
506 else if ( arg=="-P" ) {
507 if (++i < argc) Patterns.push_back( argv[i] );
508 else return -1;
509 }
510 else if ( arg=="--xmax" ) {
511 if (++i < argc) xmax = std::atof( argv[i] );
512 else return -1;
513 }
514 else if ( arg=="--xmax" ) {
515 if (++i < argc) xmax = std::atof( argv[i] );
516 else return -1;
517 }
518 else if ( arg=="--xmin" ) {
519 if (++i < argc) xmin = std::atof( argv[i] );
520 else return -1;
521 }
522 else if ( arg=="--ymin" ) {
523 if (++i < argc) ymin = std::atof( argv[i] );
524 else return -1;
525 }
526 else if ( arg=="--ymax" ) {
527 if (++i < argc) ymax = std::atof( argv[i] );
528 else return -1;
529 }
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) );
535
536 }
537
538
539 if ( dir!="" ) directories = split( std::move(dir), "/" );
540
542
543 if ( outfile!="" ) {
544 fout = new TFile( outfile.c_str(), "recreate" );
545 std::cout << "saving to file: " << outfile << std::endl;
546 }
547
548
549 for ( size_t i=0 ; i<files.size() ; i++ ) {
550
551 TFile* f = new TFile( files[i].c_str() );
552 f->cd();
553
554 scan( gDirectory, 0 ); //, dir );
555
556 std::cout << "closing" << std::endl;
557
558 // std::cout << "root is extremely annoying, why is it taking so long to close this file?" << std::endl;
559
560 // f->Close();
561
562 std::cout << "done" << std::endl;
563
564 }
565
566 if ( fout ) {
567 fout->Write();
568 fout->Close();
569 }
570
571 return 0;
572}
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:50
double minmean
these patterns are vetoed
Definition listroot.cxx:193
double xmax
Definition listroot.cxx:61
std::vector< std::string > directories
Definition listroot.cxx:185
std::vector< std::string > Patterns
these patterns are ored
Definition listroot.cxx:189
bool logy
Definition listroot.cxx:45
double maxmean
Definition listroot.cxx:194
void scan(TDirectory *td=0, int depth=0)
Definition listroot.cxx:440
bool overlay
Definition listroot.cxx:42
double ymin
Definition listroot.cxx:63
double entries
Definition listroot.cxx:49
int maxdepth
Definition listroot.cxx:202
double xmin
Definition listroot.cxx:60
std::vector< std::string > split(std::string s, const std::string &regex)
Definition listroot.cxx:416
bool binwidth
Definition listroot.cxx:58
std::vector< std::string > patterns
Definition listroot.cxx:187
double ymax
Definition listroot.cxx:64

◆ minlog()

void minlog ( TH1 * h)

Definition at line 94 of file listroot.cxx.

94 {
95 double mn = 1;
96 double mx = 1;
97 bool unset = true;
98 for ( int i=h->GetNbinsX()+1 ; i-- ; ) {
99 double d = h->GetBinContent(i);
100 if ( d!=0 && unset ) {
101 unset = false;
102 mn = d;
103 mx = d;
104 }
105 if ( d!=0 ) {
106 if ( d<mn ) mn = d;
107 if ( d>mx ) mx = d;
108 }
109 }
110 h->SetMinimum(mn*0.1);
111 h->SetMaximum(mx*10);
112}
const bool mn

◆ operator<<() [1/3]

std::ostream & operator<< ( std::ostream & s,
const inode & t )

Definition at line 177 of file listroot.cxx.

177 {
178 s << t.m_name << " " << t.m_type;
179 // if ( t.m_dir ) s << "\n" << t.m_nodes;
180 return s;
181}

◆ operator<<() [2/3]

template<typename T>
std::ostream & operator<< ( std::ostream & s,
const std::vector< T * > & t )

Definition at line 74 of file listroot.cxx.

74 {
75 for ( size_t i=0 ; i<t.size() ; i++ ) s << *t[i] << "\n";
76 return s;
77}

◆ operator<<() [3/3]

template<typename T>
std::ostream & operator<< ( std::ostream & s,
const std::vector< T > & t )

Definition at line 89 of file listroot.cxx.

89 {
90 for ( size_t i=0 ; i<t.size() ; i++ ) s << t[i] << "\n";
91 return s;
92}

◆ scan()

void scan ( TDirectory * td = 0,
int depth = 0 )

Definition at line 440 of file listroot.cxx.

440 {
441
442 if ( td ) {
443 TCck t( td, depth );
444 std::cout << t.scan( depth ) << std::endl;
445 }
446
447 // if ( std::string(tobj->GetClassName()).find("TH1")!=std::string::npos ) add<TH1>( objname.c_str(), tobj, depth+"\t" );
448 // if ( std::string(tobj->GetClassName()).find("TH2")!=std::string::npos ) add<TH2>( objname.c_str(), tobj, depth+"\t" );
449 // if ( std::string(tobj->GetClassName()).find("TProfile")!=std::string::npos ) add<TProfile>( objname.c_str(), tobj, depth+"\t" );
450
451}
std::string depth
tag string for intendation
Definition fastadd.cxx:46

◆ split()

std::vector< std::string > split ( std::string s,
const std::string & regex )

Definition at line 416 of file listroot.cxx.

416 {
417
418 std::vector<std::string> out;
419
420 size_t pos = s.find(regex);
421
422 while ( pos!=std::string::npos ) {
423 out.push_back( s.substr( 0, pos ) );
424 s.erase( 0, pos+1 );
425 pos = s.find(regex);
426 }
427
428 out.push_back( std::move(s) );
429
430 return out;
431
432}

Variable Documentation

◆ binwidth

bool binwidth = false

Definition at line 58 of file listroot.cxx.

◆ colours

int colours[4] = { kBlack, kRed, kBlue, kMagenta }

Definition at line 51 of file listroot.cxx.

51{ kBlack, kRed, kBlue, kMagenta };

◆ cwd

std::string cwd

Definition at line 38 of file listroot.cxx.

◆ dbg

bool dbg = true

Definition at line 36 of file listroot.cxx.

◆ directories

std::vector<std::string> directories

Definition at line 185 of file listroot.cxx.

◆ dirflag

bool dirflag = true

Definition at line 35 of file listroot.cxx.

◆ drawmean

bool drawmean = true

Definition at line 47 of file listroot.cxx.

◆ drawn

bool drawn = false

Definition at line 56 of file listroot.cxx.

◆ entries

double entries = 0

Definition at line 49 of file listroot.cxx.

◆ ir

int ir = 0

Definition at line 33 of file listroot.cxx.

◆ istyle

int istyle = 0

Definition at line 54 of file listroot.cxx.

◆ logy

bool logy = false

Definition at line 45 of file listroot.cxx.

◆ maxdepth

int maxdepth = 3

Definition at line 202 of file listroot.cxx.

◆ maxmean

double maxmean = 1e10

Definition at line 194 of file listroot.cxx.

◆ minmean

double minmean = 0

these patterns are vetoed

Definition at line 193 of file listroot.cxx.

◆ overlay

bool overlay = false

Definition at line 42 of file listroot.cxx.

◆ Patterns

std::vector<std::string> Patterns

these patterns are ored

Definition at line 189 of file listroot.cxx.

◆ patterns

std::vector<std::string> patterns

Definition at line 187 of file listroot.cxx.

◆ plot

bool plot = false

Definition at line 44 of file listroot.cxx.

◆ styles

int styles[4] = { 1, 2, 3, 4 }

Definition at line 52 of file listroot.cxx.

52{ 1, 2, 3, 4 };

◆ veto

std::vector<std::string> veto

these patterns are anded

Definition at line 191 of file listroot.cxx.

◆ xmax

double xmax = 0

Definition at line 61 of file listroot.cxx.

◆ xmin

double xmin = 0

Definition at line 60 of file listroot.cxx.

◆ ymax

double ymax = 0

Definition at line 64 of file listroot.cxx.

◆ ymin

double ymin = 0

Definition at line 63 of file listroot.cxx.