CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
estimatePileup_makeJSON_2015 Namespace Reference

Functions

def CalcPileup
 

Variables

int aveLumi = 0
 
dictionary csvDict = {}
 
tuple events = open(options.csvInput, 'r')
 
dictionary GapDict = {}
 
string help = 'Use CSV file from lumiCalc.py instead of lumiDB'
 
int InGap = 0
 
tuple inputGroup = optparse.OptionGroup(parser, "Input Options")
 
int ipiece = 0
 
int LastDelivered = 0
 
tuple lastindex = len(OUTPUTLINE)
 
int lastLumiS = 0
 
list LastValidLumi = []
 
tuple LumiArray
 
tuple luminometer = str( pieces[14] )
 
string LumiString = "[%d,%2.4e,%2.4e,%2.4e],"
 
int OldRun = -1
 
list output = args[0]
 
tuple outputfile = open(output,'w')
 
string OUTPUTLINE = ""
 Let's start the fun. More...
 
tuple parameters = LumiQueryAPI.ParametersObject()
 

## Main Program

More...
 
tuple parser
 
list peakratio = lumiInfo[0]
 
tuple pieces = sepRE.split(line.strip())
 
list pileup = LastValidLumi[3]
 
tuple pileupGroup = optparse.OptionGroup(parser, "Pileup Options")
 
list record = lumiInfo[1]
 
dictionary runLumiDict = {}
 
tuple sepRE = re.compile(r'[\]\[\s,;:]+')
 
list trunc = OUTPUTLINE[0:lastindex]
 
list xingInstLumiArray
 

Function Documentation

def estimatePileup_makeJSON_2015.CalcPileup (   deadTable,
  parameters,
  luminometer,
  mode = 'deadtable' 
)
Given a deadtable, will calculate parameters of pileup distribution. Return formatted
string with LumiSection, LS integrated lumi, RMS of bunch to bunch lumi and pileup.

Definition at line 13 of file estimatePileup_makeJSON_2015.py.

References mathSSE.sqrt().

13 
14 def CalcPileup (deadTable, parameters, luminometer, mode='deadtable'):
15  '''Given a deadtable, will calculate parameters of pileup distribution. Return formatted
16  string with LumiSection, LS integrated lumi, RMS of bunch to bunch lumi and pileup.'''
17 
18  LumiString = ""
19  LumiArray = []
20 
21  for lumiSection, deadArray in sorted (deadTable.iteritems()):
22  numerator = 0
23  if luminometer == "HFOC":
24  threshold = 8.
25  else:
26  threshold = 1.2
27  if mode == 'csv':
28  numerator = float (deadArray[1])
29  denominator = float (deadArray[0])
30  instLumiArray = deadArray[2]
31  livetime = 1
32  if numerator < 0:
33  numerator = 0
34  if denominator:
35  livetime = numerator / denominator
36 
37 
38 
39  #print "params", parameters.lumiSectionLen, parameters.rotationTime
40 
41  else:
42  print "no csv input! Doh!"
43  return
44  # totalInstLumi = reduce(lambda x, y: x+y, instLumiArray) # not needed
45  if lumiSection > 0:
46  TotalLumi = 0
47  TotalInt = 0
48  TotalInt2 = 0
49  TotalWeight = 0
50  TotalWeight2 = 0
51  FilledXings = 0
52  for xing, xingInstLumi, xingDelvLumi in instLumiArray:
53  #print "Inputs: lum %d: idx %d IntL %f DelivL %f" % (lumiSection, xing, xingInstLumi, xingDelvLumi)
54  xingIntLumi = xingInstLumi * livetime # * parameters.lumiSectionLen
55  mean = xingInstLumi * parameters.rotationTime / parameters.lumiSectionLen
56  if mean > 100:
57  if runNumber:
58  print "mean number of pileup events > 100 for run %d, lum %d : m %f l %f" % \
59  (runNumber, lumiSection, mean, xingInstLumi)
60  else:
61  print "mean number of pileup events > 100 for lum %d: m %f l %f" % \
62  (lumiSection, mean, xingInstLumi)
63  #print "mean number of pileup events for lum %d: m %f idx %d l %f" % (lumiSection, mean, xing, xingIntLumi)
64 
65  if xingInstLumi > threshold:
66 
67  TotalLumi = TotalLumi+xingIntLumi
68  TotalInt+= mean*xingIntLumi
69  FilledXings = FilledXings+1
70  #print "xing inst lumi %f %f %d" % (xingIntLumi,TotalLumi,FilledXings)
71 
72  #compute weighted mean, then loop again to get weighted RMS
73  MeanInt = 0
74  if TotalLumi >0:
75  MeanInt = TotalInt/TotalLumi
76  for xing, xingInstLumi, xingDelvlumi in instLumiArray:
77  if xingInstLumi > threshold:
78  xingIntLumi = xingInstLumi * livetime # * parameters.lumiSectionLen
79  mean = xingInstLumi * parameters.rotationTime / parameters.lumiSectionLen
80  TotalInt2+= xingIntLumi*(mean-MeanInt)*(mean-MeanInt)
81  TotalWeight+= xingIntLumi
82  TotalWeight2+= xingIntLumi*xingIntLumi
83 
84 
85 
86  if ((lumiSection > 0)):
87  #print " LS, Total lumi, filled xings %d, %f, %d" %(lumiSection,TotalLumi,FilledXings)
88  if FilledXings > 0:
89  AveLumi = TotalLumi/FilledXings
90  else:
91  AveLumi = 0
92  RMSLumi = 0
93  Denom = TotalWeight*TotalWeight-TotalWeight2
94  if TotalLumi > 0 and Denom > 0:
95  RMSLumi = sqrt(TotalWeight/(TotalWeight*TotalWeight-TotalWeight2)*TotalInt2)
96  LumiString = "[%d,%2.4e,%2.4e,%2.4e]," % (lumiSection, TotalLumi, RMSLumi, MeanInt)
97  LumiArray.append(lumiSection)
98  LumiArray.append(TotalLumi) # should really weight by total lumi in LS
99  LumiArray.append(RMSLumi)
100  LumiArray.append(MeanInt)
101  lumiX=MeanInt*parameters.lumiSectionLen*FilledXings*(1./parameters.rotationTime)
102 
103  #print lumiX
104  # if TotalLumi<(lumiX*0.8):
105 # print lumiSection
106 # print FilledXings
107 # print TotalLumi
108 # print lumiX
109 # print numerator
110 # print denominator
111 
112  #print FilledXings
113  return LumiArray
114 
115 
T sqrt(T t)
Definition: SSEVec.h:18

Variable Documentation

list estimatePileup_makeJSON_2015.aveLumi = 0

Definition at line 223 of file estimatePileup_makeJSON_2015.py.

dictionary estimatePileup_makeJSON_2015.csvDict = {}

Definition at line 172 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.events = open(options.csvInput, 'r')

Definition at line 160 of file estimatePileup_makeJSON_2015.py.

dictionary estimatePileup_makeJSON_2015.GapDict = {}

Definition at line 164 of file estimatePileup_makeJSON_2015.py.

string estimatePileup_makeJSON_2015.help = 'Use CSV file from lumiCalc.py instead of lumiDB'

Definition at line 136 of file estimatePileup_makeJSON_2015.py.

int estimatePileup_makeJSON_2015.InGap = 0

Definition at line 163 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.inputGroup = optparse.OptionGroup(parser, "Input Options")

Definition at line 133 of file estimatePileup_makeJSON_2015.py.

int estimatePileup_makeJSON_2015.ipiece = 0

Definition at line 179 of file estimatePileup_makeJSON_2015.py.

list estimatePileup_makeJSON_2015.LastDelivered = 0

Definition at line 166 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.lastindex = len(OUTPUTLINE)

Definition at line 242 of file estimatePileup_makeJSON_2015.py.

estimatePileup_makeJSON_2015.lastLumiS = 0

Definition at line 215 of file estimatePileup_makeJSON_2015.py.

estimatePileup_makeJSON_2015.LastValidLumi = []

Definition at line 165 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.LumiArray
Initial value:
1 = CalcPileup(lumiDict, parameters, luminometer,
2  mode='csv')

Definition at line 255 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.luminometer = str( pieces[14] )

Definition at line 199 of file estimatePileup_makeJSON_2015.py.

string estimatePileup_makeJSON_2015.LumiString = "[%d,%2.4e,%2.4e,%2.4e],"

Definition at line 226 of file estimatePileup_makeJSON_2015.py.

estimatePileup_makeJSON_2015.OldRun = -1

Definition at line 161 of file estimatePileup_makeJSON_2015.py.

list estimatePileup_makeJSON_2015.output = args[0]

Definition at line 148 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.outputfile = open(output,'w')

Definition at line 281 of file estimatePileup_makeJSON_2015.py.

estimatePileup_makeJSON_2015.OUTPUTLINE = ""

Let's start the fun.

Definition at line 154 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.parameters = LumiQueryAPI.ParametersObject()

## Main Program

Definition at line 130 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.parser
Initial value:
1 = optparse.OptionParser("Usage: %prog [--options] output.root",
2  description = "Script to estimate average instantaneous bunch crossing luminosity using xing instantaneous luminosity information. Output is JSON format file with one entry per LumiSection")

Definition at line 131 of file estimatePileup_makeJSON_2015.py.

list estimatePileup_makeJSON_2015.peakratio = lumiInfo[0]

Definition at line 221 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.pieces = sepRE.split(line.strip())

Definition at line 177 of file estimatePileup_makeJSON_2015.py.

list estimatePileup_makeJSON_2015.pileup = LastValidLumi[3]

Definition at line 222 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.pileupGroup = optparse.OptionGroup(parser, "Pileup Options")

Definition at line 134 of file estimatePileup_makeJSON_2015.py.

list estimatePileup_makeJSON_2015.record = lumiInfo[1]

Definition at line 217 of file estimatePileup_makeJSON_2015.py.

dictionary estimatePileup_makeJSON_2015.runLumiDict = {}

Definition at line 171 of file estimatePileup_makeJSON_2015.py.

tuple estimatePileup_makeJSON_2015.sepRE = re.compile(r'[\]\[\s,;:]+')

Definition at line 159 of file estimatePileup_makeJSON_2015.py.

list estimatePileup_makeJSON_2015.trunc = OUTPUTLINE[0:lastindex]

Definition at line 243 of file estimatePileup_makeJSON_2015.py.

list estimatePileup_makeJSON_2015.xingInstLumiArray
Initial value:
1 = [( int(orbit), float(lum), float(lumdelv) ) \
2  for orbit, lum, lumdelv in zip( pieces[15::3],
3  pieces[16::3],
4  pieces[17::3]) ]

Definition at line 200 of file estimatePileup_makeJSON_2015.py.