CMS 3D CMS Logo

normFunctors.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import re,ast
4  '''
5  luminorm and correction functions.
6  The result of the functions are correction factors, not final luminosity
7  all functions take 5 run time parameters, and arbituary named params
8  '''
9 
10  def fPoly(self,luminonorm,intglumi,nBXs,whatev,whatav,a0=1.0,a1=0.0,a2=0.0,drift=0.0,c1=0.0,afterglow=''):
11  '''
12  input: luminonorm unit Hz/ub
13  output: correction factor to be applied on lumi in Hz/ub
14  '''
15  avglumi=0.
16  if c1 and nBXs>0:
17  avglumi=c1*luminonorm/nBXs
18  Afterglow=1.0
19  if len(afterglow)!=0:
20  afterglowmap=ast.literal_eval(afterglow)
21  for (bxthreshold,correction) in afterglowmap:
22  if nBXs >= bxthreshold :
23  Afterglow = correction
24  driftterm=1.0
25  if drift and intglumi:
26  driftterm=1.0+drift*intglumi
27  result=a0*Afterglow/(1+a1*avglumi+a2*avglumi*avglumi)*driftterm
28  return result
29 
30  def fPolyScheme(self,luminonorm,intglumi,nBXs,fillschemeStr,fillschemePatterns,a0=1.0,a1=0.0,a2=0.0,drift=0.0,c1=0.0):
31  '''
32  input: luminonorm unit Hz/ub
33  input: fillschemePatterns [(patternStr,afterglow])
34  output: correction factor to be applied on lumi in Hz/ub
35  '''
36  avglumi=0.
37  if c1 and nBXs>0:
38  avglumi=c1*luminonorm/nBXs
39  Afterglow=1.0
40  if fillschemeStr and fillschemePatterns:
41  for apattern,cfactor in fillschemePatterns.items():
42  if re.match(apattern,fillschemeStr):
43  Afterglow=cfactor
44  driftterm=1.0
45  if drift and intglumi:
46  driftterm=1.0+drift*intglumi
47  result=a0*Afterglow/(1+a1*avglumi+a2*avglumi*avglumi)*driftterm
48  return result
49 
50 def normFunctionCaller(funcName,*args,**kwds):
52  try:
53  myfunc=getattr(fac,funcName,None)
54  except AttributeError:
55  print('[ERROR] unknown correction function '+funcName)
56  raise
57  if callable(myfunc):
58  return myfunc(*args,**kwds)
59  else:
60  raise ValueError('uncallable function '+funcName)
61 if __name__ == '__main__':
62  #sim run 176796,ls=6
63  luminonorm=0.5061*1.0e3
64  intglumi=3.309 #/fb
65  nBXs=1331
66  constParams={'a0':1.0}
67  argvals=[luminonorm,intglumi,nBXs,0.0,0.0]
68  print('no correction lumi in Hz/ub ',luminonorm*normFunctionCaller('fPoly',*argvals,**constParams))
69  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)]'}
70  print('poly corrected lumi in Hz/ub',luminonorm*normFunctionCaller('fPoly',*argvals,**polyParams))
71  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)]'}
72  print('poly corrected without drift in Hz/ub ',luminonorm*normFunctionCaller('fPoly',*argvals,**polyParams))
73  constParams={'a0':7.268}
74  print('const corrected lumi in Hz/ub',luminonorm*normFunctionCaller('fPoly',*argvals,**constParams))
def normFunctionCaller(funcName, args, kwds)
Definition: normFunctors.py:50
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def fPoly(self, luminonorm, intglumi, nBXs, whatev, whatav, a0=1.0, a1=0.0, a2=0.0, drift=0.0, c1=0.0, afterglow='')
Definition: normFunctors.py:10
def fPolyScheme(self, luminonorm, intglumi, nBXs, fillschemeStr, fillschemePatterns, a0=1.0, a1=0.0, a2=0.0, drift=0.0, c1=0.0)
Definition: normFunctors.py:30