CMS 3D CMS Logo

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

Classes

class  correctionTerm
 
class  nonlinearSingle
 
class  nonlinearV2
 
class  nonlinearV3
 

Functions

def afterglowByFillscheme
 
def applyfinecorrectionBXV2
 
def applyfinecorrectionV2
 
def correctionsForRangeV2
 
def driftcorrectionsForRange
 
def pixelcorrectionsForRange
 

Variables

tuple driftresult = driftcorrectionsForRange(schema,[160467,152611])
 
string myconstr = 'oracle://cms_orcoff_prep/cms_lumi_dev_offline'
 
tuple schema = session.nominalSchema()
 
tuple session = svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])
 
tuple svc = sessionManager.sessionManager(myconstr,authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)
 

Function Documentation

def lumiCorrections.afterglowByFillscheme (   fillscheme,
  afterglowPatterns 
)
search in the list of (pattern,afterglowfactor) for a match in regex

Definition at line 20 of file lumiCorrections.py.

Referenced by correctionsForRangeV2(), and pixelcorrectionsForRange().

20 
21 def afterglowByFillscheme(fillscheme,afterglowPatterns):
22  '''
23  search in the list of (pattern,afterglowfactor) for a match in regex
24  '''
25  for (apattern,cfactor) in afterglowPatterns:
26  if re.match(apattern,fillscheme):
27  return cfactor
28  return 1.0
29 
30 #=======================================================================================================
31 #below : correction formula version_2
#======================================================================================================
def lumiCorrections.applyfinecorrectionBXV2 (   bxlumi,
  avglumi,
  norm,
  constfactor,
  afterglowfactor,
  ncollidingbx,
  nonlinear_1,
  nonlinear_2,
  driftfactor 
)

Definition at line 83 of file lumiCorrections.py.

83 
84 def applyfinecorrectionBXV2(bxlumi,avglumi,norm,constfactor,afterglowfactor,ncollidingbx,nonlinear_1,nonlinear_2,driftfactor):
85  if bxlumi<=0:#do nothing about the negative bx lumi
86  return bxlumi
87  correctbxlumi=bxlumi*norm*constfactor*afterglowfactor*driftfactor
88  if ncollidingbx and ncollidingbx!=0:
89  dldt=avglumi/float(ncollidingbx)
90  nonlinearTerm=1.0+nonlinear_1*dldt+nonlinear_2*dldt*dldt
91  correctbxlumi=correctbxlumi/nonlinearTerm
92  #print 'avglumi,nonlinearfactor,nonlinearTerm ',avglumi,nonlinearfactor,nonlinearTerm
93  #print 'bxlumi,avglumi,norm,const,after',bxlumi,avglumi,norm,constfactor,afterglowfactor,correctbxlumi
94  return correctbxlumi
def lumiCorrections.applyfinecorrectionV2 (   avglumi,
  constfactor,
  afterglowfactor,
  ncollidingbx,
  nonlinear_1,
  nonlinear_2,
  driftfactor 
)
input :
     avglumi : normalized lumi with 6370
     constfactor,afterglowfactor,ncollidingbx,nonlinear_1,nonlinear_2
     driftfactor: default

Definition at line 95 of file lumiCorrections.py.

95 
96 def applyfinecorrectionV2(avglumi,constfactor,afterglowfactor,ncollidingbx,nonlinear_1,nonlinear_2,driftfactor):
97  '''
98  input :
99  avglumi : normalized lumi with 6370
100  constfactor,afterglowfactor,ncollidingbx,nonlinear_1,nonlinear_2
101  driftfactor: default
102  '''
103  #print avglumi,constfactor,afterglowfactor,ncollidingbx,nonlinear_1,nonlinear_2,driftfactor
104  instlumi=avglumi*afterglowfactor*constfactor*driftfactor
105  if ncollidingbx and ncollidingbx!=0:
106  dldt=avglumi/float(ncollidingbx)
107  nonlinearTerm=1.0+nonlinear_1*dldt+nonlinear_2*dldt*dldt
108  instlumi=instlumi/nonlinearTerm
109  #print 'avglumi,const,after,nonlinear,instlumi ',avglumi,constfactor,afterglowfactor,nonlinearfactor,instlumi
110  return instlumi
def lumiCorrections.correctionsForRangeV2 (   schema,
  inputRange,
  correctionTerm 
)
decide on the corrections to apply in the input range depending on amodetag,egev and runrange
select fillschemepattern,correctionfactor from fillscheme; 
   [(fillschemepattern,afterglow),...]
select fillnum,runnum,fillscheme,ncollidingbunches,egev from cmsrunsummary where amodetag='PROTPYHS' and egev>3000
    {runnum: (fillnum,fillscheme,ncollidingbunches),...}
input: correctionTerm correction terms used in the formula
output:
    {runnum:(constantfactor,afterglowfactor,ncollidingbx,nonlinearfactor1,nonlinearfactor2)}

Definition at line 111 of file lumiCorrections.py.

References afterglowByFillscheme(), nameDealer.cmsrunsummaryTableName(), AlCaHLTBitMon_QueryRunRegistry.data, and nameDealer.fillschemeTableName().

112 def correctionsForRangeV2(schema,inputRange,correctionTerm):
113  '''
114  decide on the corrections to apply in the input range depending on amodetag,egev and runrange
115  select fillschemepattern,correctionfactor from fillscheme;
116  [(fillschemepattern,afterglow),...]
117  select fillnum,runnum,fillscheme,ncollidingbunches,egev from cmsrunsummary where amodetag='PROTPYHS' and egev>3000
118  {runnum: (fillnum,fillscheme,ncollidingbunches),...}
119  input: correctionTerm correction terms used in the formula
120  output:
121  {runnum:(constantfactor,afterglowfactor,ncollidingbx,nonlinearfactor1,nonlinearfactor2)}
122  '''
123  runs=[]
124  result={}
125  constfactor=1.0 #default
126  afterglow=1.0 #default
127  ncollidingbunches=0 #default
128  nonlinear_1=1.0 #default
129  nonlinear_2=1.0 #default
130  if isinstance(inputRange,str):
131  runs.append(int(inputRange))
132  else:
133  runs=inputRange
134  for r in runs:
135  if r<150008 :
136  result[r]=(constfactor,afterglow,ncollidingbunches,nonlinear_1, nonlinear_2)
137  afterglows=[]
140  qHandle=schema.newQuery()
141  try:
142  qHandle.addToTableList(s)
143  qResult=coral.AttributeList()
144  qResult.extend('FILLSCHEMEPATTERN','string')
145  qResult.extend('CORRECTIONFACTOR','float')
146  qHandle.defineOutput(qResult)
147  qHandle.addToOutputList('FILLSCHEMEPATTERN')
148  qHandle.addToOutputList('CORRECTIONFACTOR')
149  cursor=qHandle.execute()
150  while cursor.next():
151  fillschemePattern=cursor.currentRow()['FILLSCHEMEPATTERN'].data()
152  afterglowfac=cursor.currentRow()['CORRECTIONFACTOR'].data()
153  afterglows.append((fillschemePattern,afterglowfac))
154  except :
155  del qHandle
156  raise
157  del qHandle
158  qHandle=schema.newQuery()
159  try:
160  qHandle.addToTableList(r)
161  qHandle.addToOutputList('FILLNUM', 'fillnum')
162  qHandle.addToOutputList('RUNNUM', 'runnum')
163  qHandle.addToOutputList('FILLSCHEME','fillscheme')
164  qHandle.addToOutputList('NCOLLIDINGBUNCHES','ncollidingbunches')
165  qResult=coral.AttributeList()
166  qResult.extend('fillnum','unsigned int')
167  qResult.extend('runnum','unsigned int')
168  qResult.extend('fillscheme','string')
169  qResult.extend('ncollidingbunches','unsigned int')
170  qConditionStr='AMODETAG=:amodetag AND EGEV>=:egev'#filter out lowenergy and non-proton runs
171  qCondition=coral.AttributeList()
172  qCondition.extend('amodetag','string')
173  qCondition.extend('egev','unsigned int')
174  qCondition['amodetag'].setData('PROTPHYS')
175  qCondition['egev'].setData(3000)
176  qHandle.defineOutput(qResult)
177  qHandle.setCondition(qConditionStr,qCondition)
178  cursor=qHandle.execute()
179  while cursor.next():
180  runnum=cursor.currentRow()['runnum'].data()
181  #print 'runnum ',runnum
182  if runnum not in runs or result.has_key(runnum):
183  continue
184  fillnum=cursor.currentRow()['fillnum'].data()
185  afterglow=1.0
186  constfactor=correctionTerm.constfactor
187  nonlinear_1=correctionTerm.t1
188  nonlinear_2=correctionTerm.t2
189  ncollidingbunches=0
190  if cursor.currentRow()['ncollidingbunches']:
191  ncollidingbunches=cursor.currentRow()['ncollidingbunches'].data()
192  fillscheme=''
193  if cursor.currentRow()['fillscheme']:
194  fillscheme=cursor.currentRow()['fillscheme'].data()
195  if fillscheme and len(fillscheme)!=0:
196  if fillnum>=2124: #afterglow'salready applied by lumidaq in hf root for fill<2124
197  afterglow=afterglowByFillscheme(fillscheme,afterglows)
198  result[runnum]=(constfactor,afterglow,ncollidingbunches,nonlinear_1,nonlinear_2)
199  except :
200  del qHandle
201  raise
202  del qHandle
203  for run in runs:
204  if run not in result.keys():
205  result[run]=(constfactor,afterglow,ncollidingbunches,nonlinear_1,nonlinear_2)
206  return result
207 #=======================================================================================================
208 #below : below correction formula version_1, default untill April 2012, no more used.
209 #======================================================================================================
210 #def applyfinecorrectionBX(bxlumi,avglumi,norm,constfactor,afterglowfactor,nonlinearfactor):
211 # if bxlumi<=0:
212 # return bxlumi
213 # correctbxlumi=bxlumi*norm*constfactor*afterglowfactor
214 # if constfactor!=1.0 and nonlinearfactor!=0:
215 # if avglumi<0:
216 # avglumi=0.0
217 # nonlinearTerm=1.0+avglumi*nonlinearfactor#0.076/ncollidinbunches
218 # correctbxlumi=correctbxlumi/nonlinearTerm
219 # #print 'avglumi,nonlinearfactor,nonlinearTerm ',avglumi,nonlinearfactor,nonlinearTerm
220 # #print 'bxlumi,avglumi,norm,const,after',bxlumi,avglumi,norm,constfactor,afterglowfactor,correctbxlumi
221 # return correctbxlumi
222 
223 #def applyfinecorrection(avglumi,constfactor,afterglowfactor,nonlinearfactor):
224 # instlumi=avglumi*afterglowfactor*constfactor
225 # if nonlinearfactor!=0 and constfactor!=1.0:
226 # nonlinearTerm=1.0+avglumi*nonlinearfactor#0.076/ncollidinbunches
227 # instlumi=instlumi/nonlinearTerm
228 # #print 'avglumi,const,after,nonlinear,instlumi ',avglumi,constfactor,afterglowfactor,nonlinearfactor,instlumi
229 # return instlumi
230 
231 #def correctionsForRange(schema,inputRange,correctionTerm):
232 # '''
233 # select fillschemepattern,correctionfactor from fillscheme;
234 # [(fillschemepattern,afterglow),...]
235 # select fillnum,runnum,fillscheme,ncollidingbunches,egev from cmsrunsummary where amodetag='PROTPYHS' and egev>3000
236 # {runnum: (fillnum,fillscheme,ncollidingbunches),...}
237 # output:
238 # {runnum:(constantfactor,afterglowfactor,nonlinearfactor)}
239 # '''
240 # runs=[]
241 # result={}
242 # if isinstance(inputRange,str):
243 # runs.append(int(inputRange))
244 # else:
245 # runs=inputRange
246 # for r in runs:
247 # if r<150008 :
248 # result[r]=(1.0,1.0,0.0)
249 # afterglows=[]
250 # constfactor=correctionTerm.constfactor
251 # s=nameDealer.fillschemeTableName()
252 # r=nameDealer.cmsrunsummaryTableName()
253 # qHandle=schema.newQuery()
254 # try:
255 # qHandle.addToTableList(s)
256 # qResult=coral.AttributeList()
257 # qResult.extend('FILLSCHEMEPATTERN','string')
258 # qResult.extend('CORRECTIONFACTOR','float')
259 # qHandle.defineOutput(qResult)
260 # qHandle.addToOutputList('FILLSCHEMEPATTERN')
261 # qHandle.addToOutputList('CORRECTIONFACTOR')
262 # cursor=qHandle.execute()
263 # while cursor.next():
264 # fillschemePattern=cursor.currentRow()['FILLSCHEMEPATTERN'].data()
265 # afterglowfac=cursor.currentRow()['CORRECTIONFACTOR'].data()
266 # afterglows.append((fillschemePattern,afterglowfac))
267 # except :
268 # del qHandle
269 # raise
270 # del qHandle
271 # qHandle=schema.newQuery()
272 # try:
273 # qHandle.addToTableList(r)
274 # qHandle.addToOutputList('FILLNUM', 'fillnum')
275 # qHandle.addToOutputList('RUNNUM', 'runnum')
276 # qHandle.addToOutputList('FILLSCHEME','fillscheme')
277 # qHandle.addToOutputList('NCOLLIDINGBUNCHES','ncollidingbunches')
278 # qResult=coral.AttributeList()
279 # qResult.extend('fillnum','unsigned int')
280 # qResult.extend('runnum','unsigned int')
281 # qResult.extend('fillscheme','string')
282 # qResult.extend('ncollidingbunches','unsigned int')
283 # qConditionStr='AMODETAG=:amodetag AND EGEV>=:egev'
284 # qCondition=coral.AttributeList()
285 # qCondition.extend('amodetag','string')
286 # qCondition.extend('egev','unsigned int')
287 # qCondition['amodetag'].setData('PROTPHYS')
288 # qCondition['egev'].setData(3000)
289 # qHandle.defineOutput(qResult)
290 # qHandle.setCondition(qConditionStr,qCondition)
291 # cursor=qHandle.execute()
292 # while cursor.next():
293 # runnum=cursor.currentRow()['runnum'].data()
294 # #print 'runnum ',runnum
295 # if runnum not in runs or result.has_key(runnum):
296 # continue
297 # fillnum=cursor.currentRow()['fillnum'].data()
298 # constfactor=correctionTerm.constfactor
299 # afterglow=1.0
300 # nonlinear=correctionTerm.t1
301 # nonlinearPerBX=0.0
302 # ncollidingbunches=0
303 # if cursor.currentRow()['ncollidingbunches']:
304 # ncollidingbunches=cursor.currentRow()['ncollidingbunches'].data()
305 # fillscheme=''
306 # if cursor.currentRow()['fillscheme']:
307 # fillscheme=cursor.currentRow()['fillscheme'].data()
308 # if fillscheme and len(fillscheme)!=0:
309 # afterglow=afterglowByFillscheme(fillscheme,afterglows)
310 # if ncollidingbunches and ncollidingbunches!=0:
311 # nonlinearPerBX=float(1)/float(ncollidingbunches)
312 # nonlinear=nonlinearPerBX*nonlinear
313 # result[runnum]=(constfactor,afterglow,nonlinear)
314 # except :
315 # del qHandle
316 # raise
317 # del qHandle
318 # for run in runs:
319 # if run not in result.keys():
320 # result[run]=(1.0,1.0,0.0) #those have no fillscheme 2011 runs
321 # return result
322 #=======================================================================================================
323 #below : correction on pixellumi, afterglow only
#======================================================================================================
def fillschemeTableName
Definition: nameDealer.py:13
def cmsrunsummaryTableName
Definition: nameDealer.py:16
def lumiCorrections.driftcorrectionsForRange (   schema,
  inputRange,
  correctionTerm,
  startrun = 160403 
)
select intglumi from intglumi where runnum=:runnum and startrun=:startrun
input : inputRange. str if a single run, [runs] if a list of runs
output: {run:driftcorrection}

Definition at line 32 of file lumiCorrections.py.

References AlCaHLTBitMon_QueryRunRegistry.data, and nameDealer.intglumiTableName().

32 
33 def driftcorrectionsForRange(schema,inputRange,correctionTerm,startrun=160403):
34  '''
35  select intglumi from intglumi where runnum=:runnum and startrun=:startrun
36  input : inputRange. str if a single run, [runs] if a list of runs
37  output: {run:driftcorrection}
38  '''
39  result={}
40  runs=[]
41  if isinstance(inputRange,str):
42  runs.append(int(inputRange))
43  else:
44  runs=inputRange
45  for r in runs:
46  defaultresult=1.0
47  intglumi=0.0
48  lint=0.0
49  if r<150008 :# no drift corrections for 2010 data
50  result[r]=defaultresult
51  continue
52  if r>189738: # no drift correction for 2012 data
53  result[r]=defaultresult
54  continue
55  qHandle=schema.newQuery()
56  try:
57  qHandle.addToTableList(nameDealer.intglumiTableName())
58  qResult=coral.AttributeList()
59  qResult.extend('INTGLUMI','float')
60  qHandle.addToOutputList('INTGLUMI')
61  qConditionStr='RUNNUM=:runnum AND STARTRUN=:startrun'
62  qCondition=coral.AttributeList()
63  qCondition.extend('runnum','unsigned int')
64  qCondition.extend('startrun','unsigned int')
65  qCondition['runnum'].setData(int(r))
66  qCondition['startrun'].setData(int(startrun))
67  qHandle.setCondition(qConditionStr,qCondition)
68  qHandle.defineOutput(qResult)
69  cursor=qHandle.execute()
70  while cursor.next():
71  intglumi=cursor.currentRow()['INTGLUMI'].data()
72  lint=intglumi*6.37*1.0e-9 #(convert to /fb)
73  #print lint
74  except :
75  del qHandle
76  raise
77  del qHandle
78  if not lint:
79  print '[WARNING] null intglumi for run ',r,' '
80  result[r]=defaultresult+correctionTerm.drift*lint
81  #print 'lint ',lint,' result ',result
82  return result
def intglumiTableName
Definition: nameDealer.py:88
def lumiCorrections.pixelcorrectionsForRange (   schema,
  inputRange 
)
select fillschemepattern,correctionfactor from fillscheme; 
   [(fillschemepattern,afterglow),...]
select fillnum,runnum,fillscheme from cmsrunsummary where amodetag='PROTPHYS' 
    {runnum: (fillnum,fillscheme),...}
output:
    {runnum:(afterglowfactor)}

Definition at line 324 of file lumiCorrections.py.

References afterglowByFillscheme(), nameDealer.cmsrunsummaryTableName(), AlCaHLTBitMon_QueryRunRegistry.data, and nameDealer.fillschemeTableName().

325 def pixelcorrectionsForRange(schema,inputRange):
326  '''
327  select fillschemepattern,correctionfactor from fillscheme;
328  [(fillschemepattern,afterglow),...]
329  select fillnum,runnum,fillscheme from cmsrunsummary where amodetag='PROTPHYS'
330  {runnum: (fillnum,fillscheme),...}
331  output:
332  {runnum:(afterglowfactor)}
333  '''
334  runs=[]
335  result={}
336  if isinstance(inputRange,str):
337  runs.append(int(inputRange))
338  else:
339  runs=inputRange
340  afterglows=[]
343  qHandle=schema.newQuery()
344  try:
345  qHandle.addToTableList(s)
346  qResult=coral.AttributeList()
347  qResult.extend('FILLSCHEMEPATTERN','string')
348  qResult.extend('PIXELCORRECTIONFACTOR','float')
349  qHandle.defineOutput(qResult)
350  qHandle.addToOutputList('FILLSCHEMEPATTERN')
351  qHandle.addToOutputList('PIXELCORRECTIONFACTOR')
352  cursor=qHandle.execute()
353  while cursor.next():
354  fillschemePattern=cursor.currentRow()['FILLSCHEMEPATTERN'].data()
355  afterglowfac=cursor.currentRow()['PIXELCORRECTIONFACTOR'].data()
356  afterglows.append((fillschemePattern,afterglowfac))
357  except :
358  del qHandle
359  raise
360  del qHandle
361  qHandle=schema.newQuery()
362  try:
363  qConditionStr='FILLNUM>:minfillnum'
364  qCondition=coral.AttributeList()
365  qCondition.extend('minfillnum','unsigned int')
366  qCondition['minfillnum'].setData(1600)
367  qHandle.addToTableList(r)
368  qHandle.addToOutputList('FILLNUM', 'fillnum')
369  qHandle.addToOutputList('RUNNUM', 'runnum')
370  qHandle.addToOutputList('FILLSCHEME','fillscheme')
371  qResult=coral.AttributeList()
372  qResult.extend('fillnum','unsigned int')
373  qResult.extend('runnum','unsigned int')
374  qResult.extend('fillscheme','string')
375  qHandle.setCondition(qConditionStr,qCondition)
376  qHandle.defineOutput(qResult)
377  cursor=qHandle.execute()
378  while cursor.next():
379  runnum=cursor.currentRow()['runnum'].data()
380  if runnum not in runs or result.has_key(runnum):
381  continue
382  fillnum=cursor.currentRow()['fillnum'].data()
383  afterglow=1.0
384  fillscheme=''
385  if cursor.currentRow()['fillscheme']:
386  fillscheme=cursor.currentRow()['fillscheme'].data()
387  if fillscheme and len(fillscheme)!=0:
388  afterglow=afterglowByFillscheme(fillscheme,afterglows)
389  result[runnum]=afterglow
390  except :
391  del qHandle
392  raise
393  del qHandle
394  for run in runs:
395  if run not in result.keys():
396  result[run]=1.0 #those have no fillscheme
397  return result
def fillschemeTableName
Definition: nameDealer.py:13
def cmsrunsummaryTableName
Definition: nameDealer.py:16

Variable Documentation

tuple lumiCorrections.driftresult = driftcorrectionsForRange(schema,[160467,152611])

Definition at line 407 of file lumiCorrections.py.

string lumiCorrections.myconstr = 'oracle://cms_orcoff_prep/cms_lumi_dev_offline'

Definition at line 401 of file lumiCorrections.py.

tuple lumiCorrections.schema = session.nominalSchema()

Definition at line 405 of file lumiCorrections.py.

tuple lumiCorrections.session = svc.openSession(isReadOnly=True,cpp2sqltype=[('unsigned int','NUMBER(10)'),('unsigned long long','NUMBER(20)')])

Definition at line 403 of file lumiCorrections.py.

tuple lumiCorrections.svc = sessionManager.sessionManager(myconstr,authpath='/afs/cern.ch/user/x/xiezhen',debugON=False)

Definition at line 402 of file lumiCorrections.py.