Skip to content

Instantly share code, notes, and snippets.

@jdbrice
Created August 1, 2016 21:11
Show Gist options
  • Select an option

  • Save jdbrice/e39ec14801d5374e75dfb7c73391c417 to your computer and use it in GitHub Desktop.

Select an option

Save jdbrice/e39ec14801d5374e75dfb7c73391c417 to your computer and use it in GitHub Desktop.
#include "TFile.h"
#include "TH1F.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"
#include <unordered_map>
#include <fstream>
ofstream lfirst( "list_first.list" );
ofstream lsecond( "list_second.list" );
ofstream lboth( "list_both.list" );
Int_t day( Int_t _run ) {
return (_run - 17000000) / 1000;
}
void readFile( string fn ){
cout << ".";
TFile * f = new TFile( fn.c_str(), "READ" );
TTreeReader reader( "tof", f );
TTreeReaderValue<Int_t> runId( reader, "run" );
unordered_map< Int_t, bool > unqRuns;
while( reader.Next() ) {
unqRuns[ *runId ] = true;
}
bool first = false;
bool second = false;
for ( auto kv : unqRuns ){
// cout << "Run# = " << kv.first << endl;
if ( day(kv.first) < 80 ) {
first = true;
}
if ( day(kv.first) > 80 ) {
second = true;
}
}
if ( first )
lfirst << fn << endl;
if ( second )
lsecond << fn << endl;
if ( first && second )
lboth << fn << endl;
f->Close();
}
void fileListMaker( ){
ifstream inf("list.lis" );
std::string line ="";
while( getline( inf, line ) ){
// cout << "filename : " << line << endl;
readFile( line );
}
lfirst.close();
lsecond.close();
lboth.close();
cout << endl << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment