_doc_ = " Testing TPROOF analysis in pyroot"

import ROOT
import sys
import os
import time

from ROOT import TPySelector

from Muon import Muon

##############################################
###### Selector 
##############################################

class Selec_good(TPySelector):


	DEBUG = True



	def Begin(self):


		self.Info('Begin', '-'*30)
		self.outList=self.GetOutputList()

		self.h_pt=ROOT.TH1F("h_Muon_pt","h_Muon_pt",50,0,50)
                self.outList.Add(self.h_pt)

	def Init(self, tree):

		self.Muon_pt = ROOT.std.vector('float')()
		self.Muont_pt = 0
		self.Info('Init', '-'*30)
		self.fChain.SetBranchAddress("Muon_pt", self.Muon_pt);


	def SlaveBegin(self, tree):
    		self.Info('SlaveBegin',self.__class__.__name__ )
		self.eventsProcessed = 0

#		self.h_pt=ROOT.TH1F("h_Muon_pt","h_Muon_pt",50,0,50)
#		self.outList.Add(self.h_pt)

	def Notify( self ):
		    self.Info('Notify', 'tree %s, file %s' % (self.fChain.GetName(), self.fChain.GetDirectory().GetName()))


	def Process(self, entry):
		print "Process"
		# Address the data of each physical variable registed in this event or entry number to its branch associated listed above.  
		self.fChain.GetEntry(entry)
				
		for position in range(0, self.Muon_pt.size()):
			# Fill the histograms by calling fillHisto function(the variable for filling the histo, Muon_pt, for example; the value of that variable in the position within the event) .
			self.h_pt.Fill(self.Muon_pt[position], 1)

		return True	

	def SlaveTerminate(self):
		print "Slave Terminate"

	
	def Terminate(self):
		print " Terminate "	
		self.file = ROOT.TFile("histos.root","RECREATE");

#		for var in range(0, len(self.variable)):
		self.outList.FindObject("h_Muon_pt").Write()
		
		self.file.Close()

