#!/usr/bin/python
from ROOT import *
import os, sys
gROOT.SetBatch(True)
gROOT.ProcessLine("gErrorIgnoreLevel = kFatal;")

test = os.listdir("./doNoReco")
dupl = False
for item in test:
  if item.endswith(".root"):
    dupl = True
if dupl == True: print 'Previous verion of histogram root file exists!! Please remove them first.'

def runAna(file_path, name):
  print 'processing ' + file_path
  chain = TChain("fcncLepJets/tree","events")
  chain.Add(file_path)
  chain.SetProof();
  chain.Process("MyAnalysis.C+", name)
  #print chain.GetCurrentFile().GetName()

  f = TFile.Open(file_path, "READ")

  ## save Event Summary histogram ##
  out = TFile("doNoReco/hist_" + name + ".root", "update")
  hevt = f.Get("fcncLepJets/EventInfo")
  hscale = f.Get("fcncLepJets/ScaleWeights")
  hscale.Write()
  hps = f.Get("fcncLepJets/PSWeights")
  hps.Write()
  hevt.Write()
  out.Write()
  out.Close()

p = TProof.Open("", "workers=8")

if not dupl:
