Fork me on GitHub

Changeset 154d5da in git


Ignore:
Timestamp:
Aug 14, 2013, 11:07:05 PM (11 years ago)
Author:
pavel <pavel@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
9394cbd
Parents:
298a8fb
Message:

first working version of DelphesProMC.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • readers/DelphesProMC.py

    r298a8fb r154d5da  
    33import urllib2
    44import cStringIO
    5 import zipfile 
     5import zipfile
    66
    77import ROOT
     
    1111
    1212################################################################################
     13# HttpFile class is written by Eli Carter (retracile)
     14# http://stackoverflow.com/a/7852229
    1315
    1416class HttpFile(object):
     
    6264  data = ProMC_pb2.ProMCEvent()
    6365  data.ParseFromString(zip.read(name))
    64  
     66
    6567  event = data.event
    6668  particles = data.particles
     
    6870  element = branch.NewEntry()
    6971
    70 
    71 # element.Number = event.Number
    72 # element.ProcessID = event.Process_ID
    73 # element.MPI = event.MPI
    74 # element.Weight = event.Weight
    75 # element.Scale = event.Scale
    76 # element.AlphaQED = event.Alpha_QED
    77 # element.AlphaQCD = event.Alpha_QCD
    78 # element.ID1 = event.ID1
    79 # element.ID2 = event.ID2
    80 # element.X1 = event.X1
    81 # element.X2 = event.X2
    82 # element.ScalePDF = event.Scale_PDF
    83 # element.PDF1 = event.PDF1
    84 # element.PDF2 = event.PDF2
     72  element.Number = event.Number[0] if event.Number else 0
     73  element.ProcessID = event.Process_ID[0] if event.Process_ID else 0
     74  element.MPI = event.MPI[0] if event.MPI else 0
     75#  element.Weight = event.Weight[0] if event.Weight else 0
     76  element.Scale = event.Scale[0] if event.Scale else 0
     77  element.AlphaQED = event.Alpha_QED[0] if event.Alpha_QED else 0
     78  element.AlphaQCD = event.Alpha_QCD[0] if event.Alpha_QCD else 0
     79  element.ID1 = event.ID1[0] if event.ID1 else 0
     80  element.ID2 = event.ID2[0] if event.ID2 else 0
     81  element.X1 = event.X1[0] if event.X1 else 0
     82  element.X2 = event.X2[0] if event.X2 else 0
     83  element.ScalePDF = event.Scale_PDF[0] if event.Scale_PDF else 0
     84  element.PDF1 = event.PDF1[0] if event.PDF1 else 0
     85  element.PDF2 = event.PDF2[0] if event.PDF2 else 0
    8586
    8687  for i in range(len(particles.pdg_id)):
     
    104105    candidate.Status = status
    105106
    106 #    candidate.M1 = particles.mother1[i]
    107 #    candidate.M2 = particles.mother2[i]
    108 
    109 #    candidate.D1 = particles.daughter1[i]
    110 #    candidate.D2 = particles.daughter2[i]
     107    candidate.M1 = particles.mother1[i]
     108    candidate.M2 = particles.mother2[i]
     109
     110    candidate.D1 = particles.daughter1[i]
     111    candidate.D2 = particles.daughter2[i]
    111112
    112113    candidate.Mass = mass
     
    141142
    142143if not outputFile.IsOpen():
    143   print "** ERROR: can't open ", sys.argv[2]
     144  print "** ERROR: can't open", sys.argv[2]
    144145  sys.exit(1)
    145146
     
    163164
    164165for fileName in sys.argv[3:]:
    165   print "** Reading " + fileName
    166 
    167   file = HttpFile(fileName)
     166  print "** Reading", fileName
     167
     168  if fileName.startswith("http://"):
     169    file = HttpFile(fileName)
     170  else:
     171    file = open(fileName)
     172
    168173  zip = zipfile.ZipFile(file)
     174
     175  numberOfEvents = len(zip.namelist())
     176  if numberOfEvents <= 0: continue
     177
     178  progressBar = ROOT.ExRootProgressBar(numberOfEvents - 1)
    169179
    170180  # retrive information from the header file
     
    176186  modularDelphes.Clear()
    177187  treeWriter.Clear()
     188  eventCounter = 0
    178189  for name in zip.namelist():
    179     if name.isdigit():
    180       ConvertInput(name, momentumUnit, lengthUnit, branchEvent, factory,
    181         allParticleOutputArray, stableParticleOutputArray, partonOutputArray)
    182 
    183       modularDelphes.ProcessTask()
    184 
    185       treeWriter.Fill()
    186 
    187       modularDelphes.Clear()
    188       treeWriter.Clear()
    189 
     190    eventCounter += 1
     191    if not name.isdigit(): continue
     192
     193    ConvertInput(name, momentumUnit, lengthUnit, branchEvent, factory,
     194      allParticleOutputArray, stableParticleOutputArray, partonOutputArray)
     195
     196    modularDelphes.ProcessTask()
     197
     198    treeWriter.Fill()
     199
     200    modularDelphes.Clear()
     201    treeWriter.Clear()
     202    progressBar.Update(eventCounter)
     203
     204  progressBar.Update(eventCounter, eventCounter, ROOT.kTRUE)
     205  progressBar.Finish()
    190206  zip.close()
    191207
Note: See TracChangeset for help on using the changeset viewer.