CMS 3D CMS Logo

Classes | Functions | Variables
lumiCorrections Namespace Reference

Classes

class  correctionTerm
 
class  nonlinearSingle
 
class  nonlinearV2
 
class  nonlinearV3
 

Functions

def afterglowByFillscheme (fillscheme, afterglowPatterns)
 
def applyfinecorrectionBXV2 (bxlumi, avglumi, norm, constfactor, afterglowfactor, ncollidingbx, nonlinear_1, nonlinear_2, driftfactor)
 
def applyfinecorrectionV2 (avglumi, constfactor, afterglowfactor, ncollidingbx, nonlinear_1, nonlinear_2, driftfactor)
 
def correctionsForRangeV2 (schema, inputRange, correctionTerm)
 
def driftcorrectionsForRange (schema, inputRange, correctionTerm, startrun=160403)
 
def pixelcorrectionsForRange (schema, inputRange)
 

Variables

 authpath
 
 cpp2sqltype
 
 debugON
 
 driftresult
 
 isReadOnly
 
 myconstr
 
 schema
 
 session
 
 svc
 
 True
 

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

Definition at line 83 of file lumiCorrections.py.

References objects.autophobj.float.

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

References objects.autophobj.float.

95 def applyfinecorrectionV2(avglumi,constfactor,afterglowfactor,ncollidingbx,nonlinear_1,nonlinear_2,driftfactor):
96  '''
97  input :
98  avglumi : normalized lumi with 6370
99  constfactor,afterglowfactor,ncollidingbx,nonlinear_1,nonlinear_2
100  driftfactor: default
101  '''
102  #print avglumi,constfactor,afterglowfactor,ncollidingbx,nonlinear_1,nonlinear_2,driftfactor
103  instlumi=avglumi*afterglowfactor*constfactor*driftfactor
104  if ncollidingbx and ncollidingbx!=0:
105  dldt=avglumi/float(ncollidingbx)
106  nonlinearTerm=1.0+nonlinear_1*dldt+nonlinear_2*dldt*dldt
107  instlumi=instlumi/nonlinearTerm
108  #print 'avglumi,const,after,nonlinear,instlumi ',avglumi,constfactor,afterglowfactor,nonlinearfactor,instlumi
109  return instlumi
110 
def applyfinecorrectionV2(avglumi, constfactor, afterglowfactor, ncollidingbx, nonlinear_1, nonlinear_2, driftfactor)
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(), data, nameDealer.fillschemeTableName(), createfilelist.int, and GetRecoTauVFromDQM_MC_cff.next.

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

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

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

Variable Documentation

lumiCorrections.authpath

Definition at line 402 of file lumiCorrections.py.

lumiCorrections.cpp2sqltype

Definition at line 403 of file lumiCorrections.py.

lumiCorrections.debugON

Definition at line 402 of file lumiCorrections.py.

lumiCorrections.driftresult

Definition at line 407 of file lumiCorrections.py.

lumiCorrections.isReadOnly

Definition at line 403 of file lumiCorrections.py.

lumiCorrections.myconstr

Definition at line 401 of file lumiCorrections.py.

lumiCorrections.schema

Definition at line 405 of file lumiCorrections.py.

lumiCorrections.session

Definition at line 403 of file lumiCorrections.py.

lumiCorrections.svc

Definition at line 402 of file lumiCorrections.py.

lumiCorrections.True

Definition at line 403 of file lumiCorrections.py.