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 236 of file generateEDF.py.

References mps_setup.append, createfilelist.int, and edm.print().

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

Definition at line 286 of file generateEDF.py.

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

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