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

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

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

Definition at line 287 of file generateEDF.py.

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

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