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) |
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.
00021 : 00022 ''' 00023 search in the list of (pattern,afterglowfactor) for a match in regex 00024 ''' 00025 for (apattern,cfactor) in afterglowPatterns: 00026 if re.match(apattern,fillscheme): 00027 return cfactor 00028 return 1.0 00029 00030 #======================================================================================================= 00031 #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.
00084 : 00085 if bxlumi<=0:#do nothing about the negative bx lumi 00086 return bxlumi 00087 correctbxlumi=bxlumi*norm*constfactor*afterglowfactor*driftfactor 00088 if ncollidingbx and ncollidingbx!=0: 00089 dldt=avglumi/float(ncollidingbx) 00090 nonlinearTerm=1.0+nonlinear_1*dldt+nonlinear_2*dldt*dldt 00091 correctbxlumi=correctbxlumi/nonlinearTerm 00092 #print 'avglumi,nonlinearfactor,nonlinearTerm ',avglumi,nonlinearfactor,nonlinearTerm 00093 #print 'bxlumi,avglumi,norm,const,after',bxlumi,avglumi,norm,constfactor,afterglowfactor,correctbxlumi 00094 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.
00096 : 00097 ''' 00098 input : 00099 avglumi : normalized lumi with 6370 00100 constfactor,afterglowfactor,ncollidingbx,nonlinear_1,nonlinear_2 00101 driftfactor: default 00102 ''' 00103 #print avglumi,constfactor,afterglowfactor,ncollidingbx,nonlinear_1,nonlinear_2,driftfactor 00104 instlumi=avglumi*afterglowfactor*constfactor*driftfactor 00105 if ncollidingbx and ncollidingbx!=0: 00106 dldt=avglumi/float(ncollidingbx) 00107 nonlinearTerm=1.0+nonlinear_1*dldt+nonlinear_2*dldt*dldt 00108 instlumi=instlumi/nonlinearTerm 00109 #print 'avglumi,const,after,nonlinear,instlumi ',avglumi,constfactor,afterglowfactor,nonlinearfactor,instlumi 00110 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.
00112 : 00113 ''' 00114 decide on the corrections to apply in the input range depending on amodetag,egev and runrange 00115 select fillschemepattern,correctionfactor from fillscheme; 00116 [(fillschemepattern,afterglow),...] 00117 select fillnum,runnum,fillscheme,ncollidingbunches,egev from cmsrunsummary where amodetag='PROTPYHS' and egev>3000 00118 {runnum: (fillnum,fillscheme,ncollidingbunches),...} 00119 input: correctionTerm correction terms used in the formula 00120 output: 00121 {runnum:(constantfactor,afterglowfactor,ncollidingbx,nonlinearfactor1,nonlinearfactor2)} 00122 ''' 00123 runs=[] 00124 result={} 00125 constfactor=1.0 #default 00126 afterglow=1.0 #default 00127 ncollidingbunches=0 #default 00128 nonlinear_1=1.0 #default 00129 nonlinear_2=1.0 #default 00130 if isinstance(inputRange,str): 00131 runs.append(int(inputRange)) 00132 else: 00133 runs=inputRange 00134 for r in runs: 00135 if r<150008 : 00136 result[r]=(constfactor,afterglow,ncollidingbunches,nonlinear_1, nonlinear_2) 00137 afterglows=[] 00138 s=nameDealer.fillschemeTableName() 00139 r=nameDealer.cmsrunsummaryTableName() 00140 qHandle=schema.newQuery() 00141 try: 00142 qHandle.addToTableList(s) 00143 qResult=coral.AttributeList() 00144 qResult.extend('FILLSCHEMEPATTERN','string') 00145 qResult.extend('CORRECTIONFACTOR','float') 00146 qHandle.defineOutput(qResult) 00147 qHandle.addToOutputList('FILLSCHEMEPATTERN') 00148 qHandle.addToOutputList('CORRECTIONFACTOR') 00149 cursor=qHandle.execute() 00150 while cursor.next(): 00151 fillschemePattern=cursor.currentRow()['FILLSCHEMEPATTERN'].data() 00152 afterglowfac=cursor.currentRow()['CORRECTIONFACTOR'].data() 00153 afterglows.append((fillschemePattern,afterglowfac)) 00154 except : 00155 del qHandle 00156 raise 00157 del qHandle 00158 qHandle=schema.newQuery() 00159 try: 00160 qHandle.addToTableList(r) 00161 qHandle.addToOutputList('FILLNUM', 'fillnum') 00162 qHandle.addToOutputList('RUNNUM', 'runnum') 00163 qHandle.addToOutputList('FILLSCHEME','fillscheme') 00164 qHandle.addToOutputList('NCOLLIDINGBUNCHES','ncollidingbunches') 00165 qResult=coral.AttributeList() 00166 qResult.extend('fillnum','unsigned int') 00167 qResult.extend('runnum','unsigned int') 00168 qResult.extend('fillscheme','string') 00169 qResult.extend('ncollidingbunches','unsigned int') 00170 qConditionStr='AMODETAG=:amodetag AND EGEV>=:egev'#filter out lowenergy and non-proton runs 00171 qCondition=coral.AttributeList() 00172 qCondition.extend('amodetag','string') 00173 qCondition.extend('egev','unsigned int') 00174 qCondition['amodetag'].setData('PROTPHYS') 00175 qCondition['egev'].setData(3000) 00176 qHandle.defineOutput(qResult) 00177 qHandle.setCondition(qConditionStr,qCondition) 00178 cursor=qHandle.execute() 00179 while cursor.next(): 00180 runnum=cursor.currentRow()['runnum'].data() 00181 #print 'runnum ',runnum 00182 if runnum not in runs or result.has_key(runnum): 00183 continue 00184 fillnum=cursor.currentRow()['fillnum'].data() 00185 afterglow=1.0 00186 constfactor=correctionTerm.constfactor 00187 nonlinear_1=correctionTerm.t1 00188 nonlinear_2=correctionTerm.t2 00189 ncollidingbunches=0 00190 if cursor.currentRow()['ncollidingbunches']: 00191 ncollidingbunches=cursor.currentRow()['ncollidingbunches'].data() 00192 fillscheme='' 00193 if cursor.currentRow()['fillscheme']: 00194 fillscheme=cursor.currentRow()['fillscheme'].data() 00195 if fillscheme and len(fillscheme)!=0: 00196 if fillnum>=2124: #afterglow'salready applied by lumidaq in hf root for fill<2124 00197 afterglow=afterglowByFillscheme(fillscheme,afterglows) 00198 result[runnum]=(constfactor,afterglow,ncollidingbunches,nonlinear_1,nonlinear_2) 00199 except : 00200 del qHandle 00201 raise 00202 del qHandle 00203 for run in runs: 00204 if run not in result.keys(): 00205 result[run]=(constfactor,afterglow,ncollidingbunches,nonlinear_1,nonlinear_2) 00206 return result 00207 #======================================================================================================= 00208 #below : below correction formula version_1, default untill April 2012, no more used. 00209 #====================================================================================================== 00210 #def applyfinecorrectionBX(bxlumi,avglumi,norm,constfactor,afterglowfactor,nonlinearfactor): 00211 # if bxlumi<=0: 00212 # return bxlumi 00213 # correctbxlumi=bxlumi*norm*constfactor*afterglowfactor 00214 # if constfactor!=1.0 and nonlinearfactor!=0: 00215 # if avglumi<0: 00216 # avglumi=0.0 00217 # nonlinearTerm=1.0+avglumi*nonlinearfactor#0.076/ncollidinbunches 00218 # correctbxlumi=correctbxlumi/nonlinearTerm 00219 # #print 'avglumi,nonlinearfactor,nonlinearTerm ',avglumi,nonlinearfactor,nonlinearTerm 00220 # #print 'bxlumi,avglumi,norm,const,after',bxlumi,avglumi,norm,constfactor,afterglowfactor,correctbxlumi 00221 # return correctbxlumi 00222 00223 #def applyfinecorrection(avglumi,constfactor,afterglowfactor,nonlinearfactor): 00224 # instlumi=avglumi*afterglowfactor*constfactor 00225 # if nonlinearfactor!=0 and constfactor!=1.0: 00226 # nonlinearTerm=1.0+avglumi*nonlinearfactor#0.076/ncollidinbunches 00227 # instlumi=instlumi/nonlinearTerm 00228 # #print 'avglumi,const,after,nonlinear,instlumi ',avglumi,constfactor,afterglowfactor,nonlinearfactor,instlumi 00229 # return instlumi 00230 00231 #def correctionsForRange(schema,inputRange,correctionTerm): 00232 # ''' 00233 # select fillschemepattern,correctionfactor from fillscheme; 00234 # [(fillschemepattern,afterglow),...] 00235 # select fillnum,runnum,fillscheme,ncollidingbunches,egev from cmsrunsummary where amodetag='PROTPYHS' and egev>3000 00236 # {runnum: (fillnum,fillscheme,ncollidingbunches),...} 00237 # output: 00238 # {runnum:(constantfactor,afterglowfactor,nonlinearfactor)} 00239 # ''' 00240 # runs=[] 00241 # result={} 00242 # if isinstance(inputRange,str): 00243 # runs.append(int(inputRange)) 00244 # else: 00245 # runs=inputRange 00246 # for r in runs: 00247 # if r<150008 : 00248 # result[r]=(1.0,1.0,0.0) 00249 # afterglows=[] 00250 # constfactor=correctionTerm.constfactor 00251 # s=nameDealer.fillschemeTableName() 00252 # r=nameDealer.cmsrunsummaryTableName() 00253 # qHandle=schema.newQuery() 00254 # try: 00255 # qHandle.addToTableList(s) 00256 # qResult=coral.AttributeList() 00257 # qResult.extend('FILLSCHEMEPATTERN','string') 00258 # qResult.extend('CORRECTIONFACTOR','float') 00259 # qHandle.defineOutput(qResult) 00260 # qHandle.addToOutputList('FILLSCHEMEPATTERN') 00261 # qHandle.addToOutputList('CORRECTIONFACTOR') 00262 # cursor=qHandle.execute() 00263 # while cursor.next(): 00264 # fillschemePattern=cursor.currentRow()['FILLSCHEMEPATTERN'].data() 00265 # afterglowfac=cursor.currentRow()['CORRECTIONFACTOR'].data() 00266 # afterglows.append((fillschemePattern,afterglowfac)) 00267 # except : 00268 # del qHandle 00269 # raise 00270 # del qHandle 00271 # qHandle=schema.newQuery() 00272 # try: 00273 # qHandle.addToTableList(r) 00274 # qHandle.addToOutputList('FILLNUM', 'fillnum') 00275 # qHandle.addToOutputList('RUNNUM', 'runnum') 00276 # qHandle.addToOutputList('FILLSCHEME','fillscheme') 00277 # qHandle.addToOutputList('NCOLLIDINGBUNCHES','ncollidingbunches') 00278 # qResult=coral.AttributeList() 00279 # qResult.extend('fillnum','unsigned int') 00280 # qResult.extend('runnum','unsigned int') 00281 # qResult.extend('fillscheme','string') 00282 # qResult.extend('ncollidingbunches','unsigned int') 00283 # qConditionStr='AMODETAG=:amodetag AND EGEV>=:egev' 00284 # qCondition=coral.AttributeList() 00285 # qCondition.extend('amodetag','string') 00286 # qCondition.extend('egev','unsigned int') 00287 # qCondition['amodetag'].setData('PROTPHYS') 00288 # qCondition['egev'].setData(3000) 00289 # qHandle.defineOutput(qResult) 00290 # qHandle.setCondition(qConditionStr,qCondition) 00291 # cursor=qHandle.execute() 00292 # while cursor.next(): 00293 # runnum=cursor.currentRow()['runnum'].data() 00294 # #print 'runnum ',runnum 00295 # if runnum not in runs or result.has_key(runnum): 00296 # continue 00297 # fillnum=cursor.currentRow()['fillnum'].data() 00298 # constfactor=correctionTerm.constfactor 00299 # afterglow=1.0 00300 # nonlinear=correctionTerm.t1 00301 # nonlinearPerBX=0.0 00302 # ncollidingbunches=0 00303 # if cursor.currentRow()['ncollidingbunches']: 00304 # ncollidingbunches=cursor.currentRow()['ncollidingbunches'].data() 00305 # fillscheme='' 00306 # if cursor.currentRow()['fillscheme']: 00307 # fillscheme=cursor.currentRow()['fillscheme'].data() 00308 # if fillscheme and len(fillscheme)!=0: 00309 # afterglow=afterglowByFillscheme(fillscheme,afterglows) 00310 # if ncollidingbunches and ncollidingbunches!=0: 00311 # nonlinearPerBX=float(1)/float(ncollidingbunches) 00312 # nonlinear=nonlinearPerBX*nonlinear 00313 # result[runnum]=(constfactor,afterglow,nonlinear) 00314 # except : 00315 # del qHandle 00316 # raise 00317 # del qHandle 00318 # for run in runs: 00319 # if run not in result.keys(): 00320 # result[run]=(1.0,1.0,0.0) #those have no fillscheme 2011 runs 00321 # return result 00322 #======================================================================================================= 00323 #below : correction on pixellumi, afterglow only #======================================================================================================
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.
00033 : 00034 ''' 00035 select intglumi from intglumi where runnum=:runnum and startrun=:startrun 00036 input : inputRange. str if a single run, [runs] if a list of runs 00037 output: {run:driftcorrection} 00038 ''' 00039 result={} 00040 runs=[] 00041 if isinstance(inputRange,str): 00042 runs.append(int(inputRange)) 00043 else: 00044 runs=inputRange 00045 for r in runs: 00046 defaultresult=1.0 00047 intglumi=0.0 00048 lint=0.0 00049 if r<150008 :# no drift corrections for 2010 data 00050 result[r]=defaultresult 00051 continue 00052 if r>189738: # no drift correction for 2012 data 00053 result[r]=defaultresult 00054 continue 00055 qHandle=schema.newQuery() 00056 try: 00057 qHandle.addToTableList(nameDealer.intglumiTableName()) 00058 qResult=coral.AttributeList() 00059 qResult.extend('INTGLUMI','float') 00060 qHandle.addToOutputList('INTGLUMI') 00061 qConditionStr='RUNNUM=:runnum AND STARTRUN=:startrun' 00062 qCondition=coral.AttributeList() 00063 qCondition.extend('runnum','unsigned int') 00064 qCondition.extend('startrun','unsigned int') 00065 qCondition['runnum'].setData(int(r)) 00066 qCondition['startrun'].setData(int(startrun)) 00067 qHandle.setCondition(qConditionStr,qCondition) 00068 qHandle.defineOutput(qResult) 00069 cursor=qHandle.execute() 00070 while cursor.next(): 00071 intglumi=cursor.currentRow()['INTGLUMI'].data() 00072 lint=intglumi*6.37*1.0e-9 #(convert to /fb) 00073 #print lint 00074 except : 00075 del qHandle 00076 raise 00077 del qHandle 00078 if not lint: 00079 print '[WARNING] null intglumi for run ',r,' ' 00080 result[r]=defaultresult+correctionTerm.drift*lint 00081 #print 'lint ',lint,' result ',result 00082 return result
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.
00325 : 00326 ''' 00327 select fillschemepattern,correctionfactor from fillscheme; 00328 [(fillschemepattern,afterglow),...] 00329 select fillnum,runnum,fillscheme from cmsrunsummary where amodetag='PROTPHYS' 00330 {runnum: (fillnum,fillscheme),...} 00331 output: 00332 {runnum:(afterglowfactor)} 00333 ''' 00334 runs=[] 00335 result={} 00336 if isinstance(inputRange,str): 00337 runs.append(int(inputRange)) 00338 else: 00339 runs=inputRange 00340 afterglows=[] 00341 s=nameDealer.fillschemeTableName() 00342 r=nameDealer.cmsrunsummaryTableName() 00343 qHandle=schema.newQuery() 00344 try: 00345 qHandle.addToTableList(s) 00346 qResult=coral.AttributeList() 00347 qResult.extend('FILLSCHEMEPATTERN','string') 00348 qResult.extend('PIXELCORRECTIONFACTOR','float') 00349 qHandle.defineOutput(qResult) 00350 qHandle.addToOutputList('FILLSCHEMEPATTERN') 00351 qHandle.addToOutputList('PIXELCORRECTIONFACTOR') 00352 cursor=qHandle.execute() 00353 while cursor.next(): 00354 fillschemePattern=cursor.currentRow()['FILLSCHEMEPATTERN'].data() 00355 afterglowfac=cursor.currentRow()['PIXELCORRECTIONFACTOR'].data() 00356 afterglows.append((fillschemePattern,afterglowfac)) 00357 except : 00358 del qHandle 00359 raise 00360 del qHandle 00361 qHandle=schema.newQuery() 00362 try: 00363 qConditionStr='FILLNUM>:minfillnum' 00364 qCondition=coral.AttributeList() 00365 qCondition.extend('minfillnum','unsigned int') 00366 qCondition['minfillnum'].setData(1600) 00367 qHandle.addToTableList(r) 00368 qHandle.addToOutputList('FILLNUM', 'fillnum') 00369 qHandle.addToOutputList('RUNNUM', 'runnum') 00370 qHandle.addToOutputList('FILLSCHEME','fillscheme') 00371 qResult=coral.AttributeList() 00372 qResult.extend('fillnum','unsigned int') 00373 qResult.extend('runnum','unsigned int') 00374 qResult.extend('fillscheme','string') 00375 qHandle.setCondition(qConditionStr,qCondition) 00376 qHandle.defineOutput(qResult) 00377 cursor=qHandle.execute() 00378 while cursor.next(): 00379 runnum=cursor.currentRow()['runnum'].data() 00380 if runnum not in runs or result.has_key(runnum): 00381 continue 00382 fillnum=cursor.currentRow()['fillnum'].data() 00383 afterglow=1.0 00384 fillscheme='' 00385 if cursor.currentRow()['fillscheme']: 00386 fillscheme=cursor.currentRow()['fillscheme'].data() 00387 if fillscheme and len(fillscheme)!=0: 00388 afterglow=afterglowByFillscheme(fillscheme,afterglows) 00389 result[runnum]=afterglow 00390 except : 00391 del qHandle 00392 raise 00393 del qHandle 00394 for run in runs: 00395 if run not in result.keys(): 00396 result[run]=1.0 #those have no fillscheme 00397 return result
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.