test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
normFunctors.py
Go to the documentation of this file.
1 import re,ast
2 class normFunctionFactory(object):
3  '''
4  luminorm and correction functions.
5  The result of the functions are correction factors, not final luminosity
6  all functions take 5 run time parameters, and arbituary named params
7  '''
8 
9  def fPoly(self,luminonorm,intglumi,nBXs,whatev,whatav,a0=1.0,a1=0.0,a2=0.0,drift=0.0,c1=0.0,afterglow=''):
10  '''
11  input: luminonorm unit Hz/ub
12  output: correction factor to be applied on lumi in Hz/ub
13  '''
14  avglumi=0.
15  if c1 and nBXs>0:
16  avglumi=c1*luminonorm/nBXs
17  Afterglow=1.0
18  if len(afterglow)!=0:
19  afterglowmap=ast.literal_eval(afterglow)
20  for (bxthreshold,correction) in afterglowmap:
21  if nBXs >= bxthreshold :
22  Afterglow = correction
23  driftterm=1.0
24  if drift and intglumi:
25  driftterm=1.0+drift*intglumi
26  result=a0*Afterglow/(1+a1*avglumi+a2*avglumi*avglumi)*driftterm
27  return result
28 
29  def fPolyScheme(self,luminonorm,intglumi,nBXs,fillschemeStr,fillschemePatterns,a0=1.0,a1=0.0,a2=0.0,drift=0.0,c1=0.0):
30  '''
31  input: luminonorm unit Hz/ub
32  input: fillschemePatterns [(patternStr,afterglow])
33  output: correction factor to be applied on lumi in Hz/ub
34  '''
35  avglumi=0.
36  if c1 and nBXs>0:
37  avglumi=c1*luminonorm/nBXs
38  Afterglow=1.0
39  if fillschemeStr and fillschemePatterns:
40  for apattern,cfactor in fillschemePatterns.items():
41  if re.match(apattern,fillschemeStr):
42  Afterglow=cfactor
43  driftterm=1.0
44  if drift and intglumi:
45  driftterm=1.0+drift*intglumi
46  result=a0*Afterglow/(1+a1*avglumi+a2*avglumi*avglumi)*driftterm
47  return result
48 
49 def normFunctionCaller(funcName,*args,**kwds):
51  try:
52  myfunc=getattr(fac,funcName,None)
53  except AttributeError:
54  print '[ERROR] unknown correction function '+funcName
55  raise
56  if callable(myfunc):
57  return myfunc(*args,**kwds)
58  else:
59  raise ValueError('uncallable function '+funcName)
60 if __name__ == '__main__':
61  #sim run 176796,ls=6
62  luminonorm=0.5061*1.0e3
63  intglumi=3.309 #/fb
64  nBXs=1331
65  constParams={'a0':1.0}
66  argvals=[luminonorm,intglumi,nBXs,0.0,0.0]
67  print 'no correction lumi in Hz/ub ',luminonorm*normFunctionCaller('fPoly',*argvals,**constParams)
68  polyParams={'a0':7.268,'a1':0.063,'a2':-0.0037,'drift':0.01258,'c1':6.37,'afterglow':'[(213,0.992), (321,0.99), (423,0.988), (597,0.985), (700,0.984), (873,0.981), (1041,0.979), (1179,0.977),(1317,0.975)]'}
69  print 'poly corrected lumi in Hz/ub',luminonorm*normFunctionCaller('fPoly',*argvals,**polyParams)
70  polyParams={'a0':7.268,'a1':0.063,'a2':-0.0037,'drift':0.0,'c1':6.37,'afterglow':'[(213,0.992), (321,0.99), (423,0.988), (597,0.985), (700,0.984), (873,0.981), (1041,0.979), (1179,0.977),(1317,0.975)]'}
71  print 'poly corrected without drift in Hz/ub ',luminonorm*normFunctionCaller('fPoly',*argvals,**polyParams)
72  constParams={'a0':7.268}
73  print 'const corrected lumi in Hz/ub',luminonorm*normFunctionCaller('fPoly',*argvals,**constParams)
def normFunctionCaller
Definition: normFunctors.py:49