Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 30 additions & 32 deletions Histos.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,42 @@
# Draw Histograms
# """
#
# def __init__(self):
class Histos(object):

def __init__(self):

file=ROOT.TFile("histos.root","read")
Gfile=ROOT.TFile("histos_good.root", "read")

histo=file.Get('h_pt')
file=ROOT.TFile("histos.root","read")
Gfile=ROOT.TFile("histos_good.root", "read")

ROOT.TCanvas.__init__._creates = False
canvas = ROOT.TCanvas()
#### bins and bounds?????
#def drawHisto(self, variable, bins, x_min, x_max):
def drawHisto(self, *variable)

ROOT.SetOwnership(canvas, False)
for i in variable:

if variable="pt":
histo=file.Get('h_pt')
createCanvas(histo)
if variable="eta":
histo=file.Get('h_eta')

def createCanvas(self, histo):

ROOT.TCanvas.__init__._creates = False
canvas = ROOT.TCanvas()

ROOT.SetOwnership(canvas, False)

canvas.cd()
canvas.Range(-68.75, -7.5, 856.25, 42.5)
canvas.SetFillColor(0)
canvas.SetBorderMode(0)
canvas.SetBorderSize(2)
canvas.SetTickx(1)
canvas.SetTicky(1)
canvas.SetLeftMargin(0.15)
canvas.SetRightMargin(0.05)
canvas.SetTopMargin(0.05)
canvas.SetBottomMargin(0.15)
canvas.SetFrameFillStyle(0)
canvas.SetFrameBorderMode(0)
canvas.SetFrameFillStyle(0)
canvas.SetFrameBorderMode(0)
canvas._showGuideLines = False


histo.Draw()
plot = {'canvas': canvas}

canvas.Update()
canvas.Draw()

canvas.SaveAs("h_pt.png")
canvas.cd()

histo.Draw()
plot = {'canvas': canvas}

canvas.Update()
canvas.Draw()

canvas.SaveAs(histo.name()+".png")


ROOT.gApplication.Run()
Expand Down
67 changes: 61 additions & 6 deletions Muon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@

class Muon(object):

def __init__(self, event, position, pt, eta, energy, vertex):
def __init__(self, event, position, pt,px,py,pz, eta, energy,vertex_z,dB,edB,isolation_sumPt,isolation_emEt,isolation_hadEt,isGlobalMuon,isTrackerMuon,numberOfValidHits,normChi2,charge,Vertex_Z):

self.event = event
self.position = position
self.pt = pt
self.px=px
self.py=py
self.pz=pz
self.eta = eta
self.energy = energy
self.vertex = vertex


def setPt(pt):
self.pt=pt
self.vertex_z = vertex_z
self.dB=dB
self.edB=edB
self.isolation_sumPt=isolation_sumPt
self.isolation_emEt=isolation_emEt
self.isolation_hadEt=isolation_hadEt
self.isGlobalMuon=isGlobalMuon
self.isTrackerMuon=isTrackerMuon
self.numberOfValidHits=numberOfValidHits
self.normChi2=normChi2
self.charge=charge
self.Vertex_Z=Vertex_Z

def setMuon(pt, eta, energy):
self.pt=pt
Expand All @@ -34,12 +44,57 @@ def getPosition (self):
def getPt(self):
return self.pt

def getPx(self):
return self.px

def getPy(self):
return self.py

def getPz(self):
return self.pz

def getEta(self):
return self.eta

def getEnergy(self):
return self.energy

def getvertex_z(self):
return self.vertex_z

def getdB(self):
return self.dB

def getedB(self):
return self.edB

def getIsolation_sumPt(self):
return self.isolation_sumPt

def getIsolation_emEt(self):
return self.isolation_emEt

def getIsolation_hadEt(self):
return self.isolation_hadEt

def getIsGlobalMuon(self):
return self.isGlobalMuon

def getIsTrackerMuon(self):
return self.isTrackerMuon

def getNumberOfValidHits(self):
return self.numberOfValidHits

def getNormChi2(self):
return self.normChi2

def getCharge(self):
return self.charge

def getVertex_Z(self):
return self.Vertex_Z

def printMuon(self):
print " Muon del evento: "+ repr(self.getEvent()) + " con posicion: " + repr(self.getPosition()) + " tiene como variables: \n "+ "pt: "+ repr(self.getPt())+ ", eta: "+ repr(self.getEta())

165 changes: 126 additions & 39 deletions Selector.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,154 @@
import ROOT as ROOT
from ROOT import *
import sys
import getopt
from DataFormats.FWLite import Events, Handle
from Muon import Muon
from readTTree import readTTree


def main ():
class Selection(object):

# Max and min variables
def __init__(self,pt_min,eta_max,distance,dB_max,isolation,mass_min,normChi2_max,numValidHits ):
#Otros posibles constructores eleigiendo el numero de cortes y en cuales variables."Seian Muchos"
self.pt_min = pt_min
self.eta_max = eta_max
self.distance = distance
self.dB_max = dB_max
self.normChi2_max = normChi2_max
self.isolation = isolation
#dimensionless. (sumPt+emEnergy+hadEnergy)/muon.pt = maxima energia antes de considerarlo como un jet de particulas.
self.mass_min = mass_min
self.numValidHits = numValidHits

pt_min = 12
eta_max = 2.4
distance = 0.2
dB_max = 0.02 # cm. dB=impact parameter
#normChi2_max = 10
isolation = 0.15
#dimensionless. (sumPt+emEnergy+hadEnergy)/muon.pt = maxima energia antes de considerarlo como un jet de particulas.
mass_min = 60
chi2 = 10
numValidHits = 10
self.good_muons = []
self.mass=[]
self.pt_1=[]
self.pt_2=[]

# Good muons list
good_muons = []

#####self read y self muons???????########Tambien puedo llamar a esta clase y su metodo desde el script principal(donde este el main, no???
read=readTTree()
muons=read.process()

bin=[]

self.bin=[0]*10
self.bin[0]=len(muons)

# Histograms for good muons variables
h_pt = ROOT.TH1F('g_pt', 'good_pt', 50, -2, 300)

self.G_pt = ROOT.TH1F('g_pt', 'Transverse Momentum good Muons', 50, -2, 300)
self.G_eta=ROOT.TH1F( 'g_eta', 'Angle Transverse good Muons', 50, -50 , 50 )


for iMuon in range(0, len(muons)):
#muons[iMuon].printMuon()
# Good muons list
if selector(muons[iMuon], pt_min):
#muons[iMuon].printMuon()
good_muons.append(muons[iMuon])
h_pt.Fill(muons[iMuon].getPt())
# Print elements of good_muons
# The selector function evaluates if the inner muon is GlobalMuon and TrackerMuon returning a boolean type before starting the selection for the different variables cuts.
if selector(muons[iMuon],self.pt_min,self.eta_max,self.distance,self.dB_max,self.isolation,self.normChi2_max,self.numValidHits ):
#append this muon to the good muons list.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chorrada: Pero es good poner aquí un printMuon() para el debug que en mi codigo lo dejo y no lo quito :P

self.good_muons.append(muons[iMuon])

self.G_pt.Fill(muons[iMuon].getPt())
self.G_eta.Fill(muons[iMuon].getEta())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo raro es que no te de un error de indexación en esta y la siguiente línea


self.Ghistos = ROOT.TFile("Ghistos.root", "RECREATE")
self.G_pt.Write()
self.G_eta.Write()
self.Ghistos.Close()

######??????????meter los histogramas en el bucle de good muos y comentar.

for i in range (0,len(self.good_muons)):
j=i
self.good_muons[i].getEvent()
while self.good_muons[j+1].getEvent()== self.good_muons[j].getEvent():
if (self.good_muons[j].getCharge()*self.good_muons[j+1].getCharge())<0:
#get its Lorentz vector through a ROOT function

tlv1=ROOT.TLorentzVector()
tlv1.SetPxPyPzE(self.good_muons[j].getPx(), self.good_muons[j].getPy(), self.good_muons[j].getPz(), self.good_muons[j].getEnergy())
tlv2=ROOT.TLorentzVector()
tlv2.SetPxPyPzE(self.good_muons[j+1].getPx(), self.good_muons[j+1].getPy(), self.good_muons[j+1].getPz(), self.good_muons[j+1].getEnergy())

#self.pt_1.append(self.good_muons[i].getPt())
#self.pt_2.append(self.good_muons[i+1].getPt())
mass=(tlv1+tlv2).M()
if self.mass_min<mass<120:
self.mass.append(mass)
j=j+1


# Print elements of good_muons
#for jMuon in range (0, len(good_muons)):
# good_muons[jMuon].printMuon()

fhistosGood= ROOT.TFile("histos_good.root", "RECREATE")
def addBin(i):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

te falta pasarle self como argumento

bin[i]=+1
return bin[i]


h_pt.Write()

fhistosGood.Close()

def selector(muon,pt_min):

def selector(muon,pt_min,eta_max,distance,dB_max,isolation,normChi2_max,numValidHits):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lo mismo que el anterior: self como argumento


i=0
# Minimum transverse momentum (pt) and maximum eta angle
if muon.getPt() > pt_min :

if muon.getIsGlobalMuon():

i=+1
self.bin.addBin(i)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no está bien, bin es una lista y no puede llamar al método addBin de la clase. bin pasado como parámetro a la función selector y addbin (o directamente quitar esta últimafunción) lo veo mejor ;)

return True

if muon.getIsTrackerMuon():

i=+1
self.bin.addBin(i)
return True


if muon.getPt() >self.pt_min:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No hace falta poner self.pt_min ya que es la variable que le pasas como parámetro


i=+1
self.bin.addBin(i)
return True

if muon.getEta()< self.eta_max:
i=+1
self.bin.addBin(i)
return True

return False
if muon.getdB()< self.dB_max:

i=+1
self.bin.addBin(i)
return True


if ((muon.getIsolation_sumPt+getIsolation_emEt()+getIsolation_hadEt)/muon.getPt())<self.isolation:
i=+1
self.bin.addBin(i)
return True


if abs(muon.getvertex_z()-muon.getVertex_Z())< self.distance:

i=+1
self.bin.addBin(i)
return True

if muon.getNormChi2()<self.normChi2_max:

i=+1
self.bin.addBin(i)
return True

if muon.getNumberOfValidHits()>self.numValidHits:

i=+1
self.bin.addBin(i)
return True

#Last bin for the efficiency.Just the number of good muons.
i=+1
self.bin.addBin(i)

return True
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si los cortes no los pasa retornará false no? Porque sino siempre te diría que el Muon es selected!


def addBin(i):
bin[i]=0



if __name__ == "__main__":
main()
Loading