//----------------------------------------------------------------------------- // Dec 15 1999 P.Murat: // -------------------- // an example showing how to copy a subset of events from the input ntuple // (UC STNTUPLE 5.x converted to ROOT) to output TStntuple (C++ equivalent of // US STNTUPLE) // // the user is supposed to supply a function event_is_ok(THBookStnEvent*) // returning 1 if the input event has to be copied into output ntuple and // 0 otherwise //----------------------------------------------------------------------------- #ifndef __CINT__ #include "TROOT.h" #include "TSystem.h" #include "TRegexp.h" #include "TFile.h" #include "TTree.h" #include "TInterpreter.h" #include #include #include #include #endif THBookStnEvent* input_event; TStntupleEvent* output_event; int book_histograms(); int process_event(TStntupleEvent* event); int end_job(); double const kDegree = TMath::Pi()/180.; //----------------------------------------------------------------------------- // `dir' - name of the directory with root files, I'm assuming that all the // *.root files in `dir' produce one chain //----------------------------------------------------------------------------- int hbook_loop(const char* dir_name, int first_event=0, int last_event=-1) { // define input chain input_event = new THBookStnEvent(); output_event = new TStntupleEvent(); book_histograms(); THBookStntuple* input = new THBookStntuple("/STNTUPLE/h1",input_event); void* dir; char filename[200]; Ssiz_t len; if (dir = gSystem->OpenDirectory(dir_name)) { char* fname; while (fname = (char*) gSystem->GetDirEntry(dir)) { sprintf(filename,"%s/%s",dir_name,fname); TRegexp regexp(".root"); if (regexp.Index(filename,&len,0) > 0) { input->Add(filename); } } } else { // this could be a single file TFile f(dir_name); if (f.IsOpen()) { input->Add(dir_name); } else { printf(" ------------ cant open input file \n"); return -2; } } input->Print(); input->LoadTree(0); input->SetBranches(); int ngood = 0; int nbytes; double nentries = input->GetEntries(); printf("nentries = %5d\n",nentries); int ifirst = 0; if (first_event > 0) ifirst = first_event; int ilast = (int) nentries; if (last_event >= 0) ilast = last_event; for (Int_t ievent=ifirst; ieventLoadTree(ievent) < 0) break; // read the event in nbytes = input->GetEntry(ievent); output_event->InitFromHBook(input_event); process_event(output_event); } end_job(); delete input; delete input_event; delete output_event; }