CMS 3D CMS Logo

Classes | Functions | Variables
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)
 

Variables

 action
 
 allowedEDF
 

## Main

More...
 
 args
 
 cont
 load Luminosity info ## More...
 
 default
 
 description
 
 dest
 
 done
 
 eventsDict
 make EDF plots ## More...
 
 help
 
 inputGroup
 
 maxIntLum
 
 maxRun
 
 minIntLum
 
 minRun
 
 modeGroup
 
 nonSpaceRE
 
 options
 
 parser
 
 pieces
 
 plotGroup
 
 prevRecLumi
 
 rangeGroup
 
 recLumIndex
 
 recLumis
 look for which runs correspond to what total ## recorded integrated luminosity ## More...
 
 recLumValue
 
 sepRE
 
 totalWeight
 
 type
 

Function Documentation

◆ loadEvents()

def generateEDF.loadEvents (   filename,
  cont,
  options 
)

General Functions

Definition at line 240 of file generateEDF.py.

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

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

◆ makeEDFplot()

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

Definition at line 290 of file generateEDF.py.

References dqmMemoryStats.float, SiStripPI.max, SiStripPI.min, and print().

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

Variable Documentation

◆ action

generateEDF.action

Definition at line 576 of file generateEDF.py.

◆ allowedEDF

generateEDF.allowedEDF

## Main

command line options ##

Definition at line 560 of file generateEDF.py.

◆ args

generateEDF.args

Definition at line 615 of file generateEDF.py.

◆ cont

◆ default

generateEDF.default

Definition at line 567 of file generateEDF.py.

◆ description

generateEDF.description

Definition at line 561 of file generateEDF.py.

◆ dest

generateEDF.dest

Definition at line 566 of file generateEDF.py.

◆ done

generateEDF.done

Definition at line 657 of file generateEDF.py.

◆ eventsDict

generateEDF.eventsDict

make EDF plots ##

Definition at line 687 of file generateEDF.py.

◆ help

generateEDF.help

Definition at line 568 of file generateEDF.py.

◆ inputGroup

generateEDF.inputGroup

Definition at line 564 of file generateEDF.py.

◆ maxIntLum

generateEDF.maxIntLum

Definition at line 632 of file generateEDF.py.

◆ maxRun

generateEDF.maxRun

Definition at line 630 of file generateEDF.py.

◆ minIntLum

generateEDF.minIntLum

Definition at line 631 of file generateEDF.py.

◆ minRun

generateEDF.minRun

Definition at line 629 of file generateEDF.py.

◆ modeGroup

generateEDF.modeGroup

Definition at line 565 of file generateEDF.py.

◆ nonSpaceRE

generateEDF.nonSpaceRE

Definition at line 18 of file generateEDF.py.

◆ options

generateEDF.options

Definition at line 615 of file generateEDF.py.

◆ parser

generateEDF.parser

Definition at line 561 of file generateEDF.py.

◆ pieces

generateEDF.pieces

Definition at line 641 of file generateEDF.py.

◆ plotGroup

generateEDF.plotGroup

Definition at line 562 of file generateEDF.py.

◆ prevRecLumi

generateEDF.prevRecLumi

Definition at line 656 of file generateEDF.py.

◆ rangeGroup

generateEDF.rangeGroup

Definition at line 563 of file generateEDF.py.

◆ recLumIndex

generateEDF.recLumIndex

Definition at line 654 of file generateEDF.py.

◆ recLumis

generateEDF.recLumis

look for which runs correspond to what total ## recorded integrated luminosity ##

Definition at line 639 of file generateEDF.py.

◆ recLumValue

generateEDF.recLumValue

Definition at line 644 of file generateEDF.py.

◆ sepRE

generateEDF.sepRE

Definition at line 17 of file generateEDF.py.

◆ totalWeight

◆ type

generateEDF.type

Definition at line 566 of file generateEDF.py.