CMS 3D CMS Logo

Classes | Functions
generateEDF Namespace Reference

Classes

class  LumiInfo
 

LumiInfo Class

More...
 
class  LumiInfoCont
 

LumiInfoCont Class

More...
 

Functions

def loadEvents (filename, cont, options)
 

General Functions

More...
 
def makeEDFplot (lumiCont, eventsDict, totalWeight, outputFile, options)
 

Function Documentation

def generateEDF.loadEvents (   filename,
  cont,
  options 
)

General Functions

Definition at line 234 of file generateEDF.py.

References mps_setup.append, and createfilelist.int.

234 def loadEvents (filename, cont, options):
235  eventsDict = {}
236  print "loading events from '%s'" % filename
237  events = open (filename, 'r')
238  runIndex, lumiIndex, eventIndex, weightIndex = 0, 1, 2, 3
239  if options.relOrder:
240  lumiIndex, eventIndex = 2,1
241  minPieces = 3
242  totalWeight = 0.
243  if options.weights:
244  minPieces = 4
245  for line in events:
246  pieces = sepRE.split (line.strip())
247  if len (pieces) < minPieces:
248  if nonSpaceRE.search (line):
249  print "skipping", line
250  continue
251  try:
252  run, lumi, event = int( pieces[runIndex] ), \
253  int( pieces[lumiIndex] ), \
254  int( pieces[eventIndex] )
255  except:
256  continue
257  key = (run, lumi)
258  if key not in cont:
259  if options.ignore:
260  print "Warning, %s is not found in the lumi information" \
261  % key.__str__()
262  continue
263  else:
264  raise RuntimeError("%s is not found in lumi information. Use '--ignoreNoLumiEvents' option to ignore these events and continue." \
265  % key.__str__())
266  if options.edfMode != 'time' and not cont[key].xingInfo:
267  if options.ignore:
268  print "Warning, %s does not have Xing information" \
269  % key.__str__()
270  continue
271  else:
272  raise RuntimeError("%s does not have Xing information. Use '--ignoreNoLumiEvents' option to ignore these events and continue." \
273  % key.__str__())
274  if options.weights:
275  weight = float (pieces[weightIndex])
276  else:
277  weight = 1
278  eventsDict.setdefault( key, []).append( (event, weight) )
279  totalWeight += weight
280  events.close()
281  return eventsDict, totalWeight
282 
283 
def loadEvents(filename, cont, options)
General Functions
Definition: generateEDF.py:234
def generateEDF.makeEDFplot (   lumiCont,
  eventsDict,
  totalWeight,
  outputFile,
  options 
)

Definition at line 284 of file generateEDF.py.

References objects.autophobj.float, list(), SiStripPI.max, and min().

284 def makeEDFplot (lumiCont, eventsDict, totalWeight, outputFile, options):
285  # make TGraph
286  xVals = [0]
287  yVals = [0]
288  expectedVals = [0]
289  predVals = [0]
290  weight = 0
291  expectedChunks = []
292  ########################
293  ## Time Ordering Mode ##
294  ########################
295  if 'time' == options.edfMode:
296  # if we have a minimum run number, clear the lists
297  if lumiCont.minRun or lumiCont.minIntLum:
298  xVals = []
299  yVals = []
300  expectedVals = []
301  predVals = []
302  # loop over events
303  for key, eventList in sorted( eventsDict.iteritems() ):
304  usePoints = True
305  # should we add this point?
306  if lumiCont.minRun and lumiCont.minRun > key[0] or \
307  lumiCont.maxRun and lumiCont.maxRun < key[0]:
308  usePoints = False
309  for event in eventList:
310  weight += event[1]
311  if not usePoints:
312  continue
313  factor = weight / totalWeight
314  try:
315  intLum = lumiCont[key].totalRecorded
316  except:
317  raise RuntimeError("key %s not found in lumi information" \
318  % key.__str__())
319  if lumiCont.minIntLum and lumiCont.minIntLum > intLum or \
320  lumiCont.maxIntLum and lumiCont.maxIntLum < intLum:
321  continue
322  lumFrac = intLum / lumiCont.totalRecLum
323  xVals.append( lumiCont[key].totalRecorded)
324  yVals.append (factor)
325  expectedVals.append (lumFrac)
326  predVals.append (lumFrac * options.pred)
327  # put on the last point if we aren't giving a maximum run
328  if not lumiCont.maxRun and not lumiCont.maxIntLum:
329  xVals.append (lumiCont.totalRecLum)
330  yVals.append (1)
331  expectedVals.append (1)
332  predVals.append (options.pred)
333  ####################
334  ## Reset Expected ##
335  ####################
336  if options.resetExpected:
337  slope = (yVals[-1] - yVals[0]) / (xVals[-1] - xVals[0])
338  print "slope", slope
339  for index, old in enumerate (expectedVals):
340  expectedVals[index] = yVals[0] + \
341  slope * (xVals[index] - xVals[0])
342  #############################################
343  ## Break Expected by Integrated Luminosity ##
344  #############################################
345  if options.breakExpectedIntLum:
346  breakExpectedIntLum = []
347  for chunk in options.breakExpectedIntLum:
348  pieces = sepRE.split (chunk)
349  try:
350  for piece in pieces:
351  breakExpectedIntLum.append( float(piece) )
352  except:
353  raise RuntimeError("'%s' from '%s' is not a valid float" \
354  % (piece, chunk))
355  breakExpectedIntLum.sort()
356  boundaries = []
357  breakIndex = 0
358  done = False
359  for index, xPos in enumerate (xVals):
360  if xPos > breakExpectedIntLum[breakIndex]:
361  boundaries.append (index)
362  while breakIndex < len (breakExpectedIntLum):
363  breakIndex += 1
364  if breakIndex >= len (breakExpectedIntLum):
365  done = True
366  break
367  # If this next position is different, than
368  # we're golden. Otherwise, let it go through
369  # the loop again.
370  if xPos <= breakExpectedIntLum[breakIndex]:
371  break
372  if done:
373  break
374  # do we have any boundaries?
375  if not boundaries:
376  raise RuntimeError("No values of 'breakExpectedIntLum' are in current range.")
377  # is the first boundary at 0? If not, add 0
378  if boundaries[0]:
379  boundaries.insert (0, 0)
380  # is the last boundary at the end? If not, make the end a
381  # boundary
382  if boundaries[-1] != len (xVals) - 1:
383  boundaries.append( len (xVals) - 1 )
384  rangeList = list(zip (boundaries, boundaries[1:]))
385  for thisRange in rangeList:
386  upper = thisRange[1]
387  lower = thisRange[0]
388  slope = (yVals[upper] - yVals[lower]) / \
389  (xVals[upper] - xVals[lower])
390  print "slope", slope
391  # now go over the range inclusively
392  pairList = []
393  for index in range (lower, upper + 1):
394  newExpected = yVals[lower] + \
395  slope * (xVals[index] - xVals[lower])
396  pairList.append( (xVals[index], newExpected) )
397  expectedVals[index] = newExpected
398  expectedChunks.append (pairList)
399  ###########################################
400  ## Instantanous Luminosity Ordering Mode ##
401  ###########################################
402  elif 'instLum' == options.edfMode or 'instIntLum' == options.edfMode:
403  eventTupList = []
404  if not lumiCont.xingInfo:
405  raise RuntimeError("Luminosity Xing information missing.")
406  for key, eventList in sorted( eventsDict.iteritems() ):
407  try:
408  lumi = lumiCont[key]
409  instLum = lumi.aveInstLum
410  fracAXIL = lumi.fracAXILrecorded
411  totalAXIL = lumi.totalAXILrecorded
412  except:
413  raise RuntimeError("key %s not found in lumi information" \
414  % key.__str__())
415  for event in eventList:
416  eventTupList.append( (instLum, fracAXIL, totalAXIL, key,
417  event[0], event[1], ) )
418  eventTupList.sort()
419  for eventTup in eventTupList:
420  weight += eventTup[5]
421  factor = weight / totalWeight
422  if 'instLum' == options.edfMode:
423  xVals.append (eventTup[0])
424  else:
425  xVals.append (eventTup[2])
426  yVals.append (factor)
427  expectedVals.append (eventTup[1])
428  predVals.append (eventTup[1] * options.pred)
429  else:
430  raise RuntimeError("It looks like Charles screwed up if you are seeing this.")
431 
432  size = len (xVals)
433  step = int (math.sqrt(size) / 2 + 1)
434  if options.printValues:
435  for index in range (size):
436  print "%8f %8f %8f" % (xVals[index], yVals[index], expectedVals[index]),
437  if index > step:
438  denom = xVals[index] - xVals[index - step]
439  numer = yVals[index] - yVals[index - step]
440  if denom:
441  print " %8f" % (numer / denom),
442  if 0 == index % step:
443  print " **", ## indicates statistically independent
444  ## slope measurement
445  print
446  print
447 
448  xArray = array.array ('d', xVals)
449  yArray = array.array ('d', yVals)
450  expected = array.array ('d', expectedVals)
451  graph = ROOT.TGraph( size, xArray, yArray)
452  graph.SetTitle (options.title)
453  graph.SetMarkerStyle (20)
454  expectedGraph = ROOT.TGraph( size, xArray, expected)
455  expectedGraph.SetLineColor (ROOT.kRed)
456  expectedGraph.SetLineWidth (3)
457  if options.noDataPoints:
458  expectedGraph.SetLineStyle (2)
459 
460  # run statistical tests
461  if options.weights:
462  print "average weight per event:", weight / ( size - 1)
463  maxDistance = ROOT.TMath.KolmogorovTest (size, yArray,
464  size, expected,
465  "M")
466  prob = ROOT.TMath.KolmogorovProb( maxDistance * math.sqrt( size ) )
467 
468  # display everything
469  ROOT.gROOT.SetStyle('Plain')
470  ROOT.gROOT.SetBatch()
471  c1 = ROOT.TCanvas()
472  graph.GetXaxis().SetRangeUser (min (xVals), max (xVals))
473  minValue = min (min(yVals), min(expected))
474  if options.pred:
475  minValue = min (minValue, min (predVals))
476  graph.GetYaxis().SetRangeUser (minValue,
477  max (max(yVals), max(expected), max(predVals)))
478  graph.SetLineWidth (3)
479  if options.noDataPoints:
480  graph.Draw ("AL")
481  else:
482  graph.Draw ("ALP")
483  if 'instLum' == options.edfMode:
484  graph.GetXaxis().SetTitle ("Average Xing Inst. Luminosity (1/ub/s)")
485  graph.GetXaxis().SetRangeUser (0., lumiCont.max('aveInstLum'))
486  else:
487  if 'instIntLum' == options.edfMode:
488  graph.GetXaxis().SetTitle ("Integrated Luminosity - Inst. Lum. Ordered (1/%s)" \
489  % lumiCont.invunits)
490  else:
491  graph.GetXaxis().SetTitle ("Integrated Luminosity (1/%s)" \
492  % lumiCont.invunits)
493  graph.GetYaxis().SetTitle ("Fraction of Events Seen")
494  expectedGraphs = []
495  if expectedChunks:
496  for index, chunk in enumerate (expectedChunks):
497  expectedXarray = array.array ('d', [item[0] for item in chunk])
498  expectedYarray = array.array ('d', [item[1] for item in chunk])
499  expectedGraph = ROOT.TGraph( len(chunk),
500  expectedXarray,
501  expectedYarray )
502  expectedGraph.SetLineWidth (3)
503  if options.noDataPoints:
504  expectedGraph.SetLineStyle (2)
505  if index % 2:
506  expectedGraph.SetLineColor (ROOT.kBlue)
507  else:
508  expectedGraph.SetLineColor (ROOT.kRed)
509  expectedGraph.Draw("L")
510  expectedGraphs.append (expectedGraph)
511  exptectedGraph = expectedGraphs[0]
512  else:
513  expectedGraph.Draw ("L")
514  green = 0
515  if options.pred:
516  predArray = array.array ('d', predVals)
517  green = ROOT.TGraph (size, xArray, predArray)
518  green.SetLineWidth (3)
519  green.SetLineColor (8)
520  green.Draw ('l')
521  legend = ROOT.TLegend(0.15, 0.65, 0.50, 0.85)
522  legend.SetFillStyle (0)
523  legend.SetLineColor(ROOT.kWhite)
524  observed = 'Observed'
525  if options.weights:
526  observed += ' (weighted)'
527  legend.AddEntry(graph, observed,"PL")
528  if options.resetExpected:
529  legend.AddEntry(expectedGraph, "Expected from partial yield","L")
530  else:
531  legend.AddEntry(expectedGraph, "Expected from total yield","L")
532  if options.pred:
533  legend.AddEntry(green, options.predLabel,"L")
534  legend.AddEntry("","D_{stat}=%.3f, N=%d" % (maxDistance, size),"")
535  legend.AddEntry("","P_{KS}=%.3f" % prob,"")
536  legend.Draw()
537 
538  # save file
539  c1.Print (outputFile)
540 
541 
def makeEDFplot(lumiCont, eventsDict, totalWeight, outputFile, options)
Definition: generateEDF.py:284
T min(T a, T b)
Definition: MathUtil.h:58
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run