53bool contains(
const std::string& s,
const std::string& regex ) {
54 return s.find( regex )!=std::string::npos;
60 TList* list = tnd->GetListOfKeys();
63 for (
int i=0 ; i<list->GetSize() ; i++ ) {
65 std::string name( list->At(i)->GetName() );
67 TKey* tobj = (TKey*)list->At(i);
71 if (
contains( tobj->GetClassName(),
"TH1" ) ) {
76 eff = (TH1F*)tobj->ReadObj();
78 std::string dname = name+
"_d";
79 std::string nname = name+
"_n";
84 for (
int j=0 ; j<list->GetSize() ; j++ ) {
86 const std::string name( list->At(j)->GetName() );
88 if ( name==dname ) den = (TH1F*)((TKey*)list->At(j))->ReadObj();
89 if ( name==nname ) num = (TH1F*)((TKey*)list->At(j))->ReadObj();
93 std::cout <<
"Efficiency " << eff->GetName() << std::endl;
95 std::string title = eff->GetTitle();
101 eff->SetName( name.c_str() );
102 eff->SetTitle( title.c_str() );
104 eff->Write(
"",TObject::kOverwrite);
124 if ( tnd==0 )
return false;
126 static const std::string token[6] = {
"1d",
"2d",
"mean",
"sigma",
"chi2",
"fractional uncertainty" };
127 bool found[6] = {
false,
false,
false,
false,
false,
false };
133 TList* list = tnd->GetListOfKeys();
136 for (
int i=0 ; i<list->GetSize() ; i++ ) {
138 std::string name( list->At( i )->GetName() );
142 for (
int j=0 ; j<6 ; j++ ) {
144 if ( name == token[j] ) {
154 std::cout <<
"Resplot count " <<
count <<
" " << tnd->GetName() << std::endl;
156 if (
count == 6 )
return true;
166void search(TDirectory* td=0,
const std::string& s=
"") {
172 if (
ir>10 ) exit(0);
176 TDirectory* here = gDirectory;
182 if ( ns!=
"" ) ns +=
"/";
185 gDirectory->cd(td->GetName());
189 std::cout <<
"\n" <<
depth <<
"Directory " << ns;
192 std::string savedepth =
depth;
197 TList* tl = gDirectory->GetListOfKeys();
205 for (
int i=tl->GetSize() ; i-- ; ) {
207 TKey* tobj = (TKey*)tl->At(i);
209 if ( tobj==0 )
continue;
215 if ( std::string(tobj->GetClassName()).find(
"TDirectory")!=std::string::npos ) {
218 TDirectory* tnd = (TDirectory*)tobj->ReadObj();
228 std::cout <<
"Resplot refitting " << tnd->GetName() << std::endl;
231 std::cout <<
"deleting ..." << std::endl;
232 gDirectory->Delete( (std::string(tnd->GetName())+
";1").c_str() );
234 std::cout <<
"refitting ..." << std::endl;
238 std::cout <<
"writing ..." << std::endl;
264 std::cout <<
"\tprocessed directory in " << t*0.001 <<
" s from " << global_time*0.001 <<
" s";
267 depth = std::move(savedepth);
283 if ( FILE* testfile=fopen(s.c_str(),
"r") ) {
298 std::cout <<
"processing" << std::endl;
302 std::cerr <<
"output file " <<
outputfile <<
" already exists" << std::endl;
306 std::cout <<
"copying file to " <<
outputfile << std::endl;
309 system( (
"cp "+inputfile+
" "+
outputfile).c_str() );
315 std::cout <<
"opening root files" << std::endl;
318 std::cout <<
"opening " << inputfile << std::endl;
326 std::cerr <<
"cannot open " <<
outputfile.c_str() << std::endl;
332 TDirectory* here = gDirectory;
342 std::cout <<
"closing the files" << std::endl;
353int usage(std::ostream& s,
int argc,
char** argv) {
355 s <<
"Usage: " << argv[0] <<
" [OPTIONS] -o output.root input.root \n\n";
356 s <<
" -o filename \toutput filename (required)\n";
357 s <<
" -h, --help \tdisplay this help\n";
360 s <<
"refit:usage() no arguments!\n";
368int main(
int argc,
char** argv) {
371 if ( argc<3 )
return usage( std::cerr, argc, argv );
374 for (
int i=1 ; i<argc ; i++ ) {
375 if ( std::string(argv[i])==
"-h" || std::string(argv[i])==
"--help" )
return usage( std::cout, argc, argv );
380 std::string output_file =
"";
381 std::string input_file =
"";
383 for (
int i=1 ; i<argc ; i++ ) {
384 if ( std::string(argv[i])==
"--verbose" )
verbose =
true;
385 else if ( std::string(argv[i])==
"-o" ) {
387 if ( i<argc ) output_file = argv[i];
388 else return usage( std::cerr, argc, argv );
391 if ( input_file==
"" ) input_file = argv[i];
392 else return usage( std::cerr, argc, argv );
398 if ( output_file ==
"" )
return usage( std::cerr, argc, argv );
399 if ( input_file ==
"" )
return usage( std::cerr, argc, argv );
409 if (
verbose ) std::cout <<
"timing" << std::endl;
413 cost( input_file, output_file );
417 std::cout <<
"\ntotal time " << t*0.001 <<
" s (" << (t*0.001/60) <<
" min)" << std::endl;
struct timeval simpletimer_start(void)
double simpletimer_stop(const struct timeval &start_time)
std::pair< std::vector< unsigned int >, bool > res
these functions have a precision of about 0.001 ms
static TF1 * FitNull95(TH1D *s, double a=0, double b=0)
struct timeval global_timer
glabal timer - how long have I taken so far?
int ir
counter of the current depth
std::string depth
tag string for intendation
std::vector< TFile * > fptr
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
void search(TDirectory *td=0, const std::string &s="")
recursive directory search for TH1 and TH2
bool isResplot(TDirectory *tnd)
bool handleEfficiency(TDirectory *tnd)
bool contains(const std::string &s, const std::string ®ex)
does a string contain the substring
bool file_exists(const std::string &s)
void cost(const std::string &inputfile, const std::string &outputfile)