6 Tools for handling beam spot data in ntuples or in COOL.
7 For functionality requiring COOL access, you'll probably need to use
8 Frontier outside of CERN. For example:
10 setenv FRONTIER_SERVER "(serverurl=http://squid-frontier.usatlas.bnl.gov:23128/frontieratbnl)"
12 __author__ =
'Juerg Beringer'
13 __version__ =
'$Id: BeamSpotData.py 759522 2016-07-04 12:47:58Z amorley $'
17 from array
import array
18 from math
import sqrt, atan
36 'nValid': {
'altfmt':
'%i',
'latexheader':
r'$n_{\mathrm{vtx}}$'},
39 'status': {
'fmt':
'%4i',
'altfmt':
'%4i',
'latexheader' :
'Status' },
40 'posX': {
'units':
'mm',
'fmt':
'%10.4f',
'latexheader':
'$x$ [mm]',
41 'altfmt':
'%10.3f',
'altlatexheader':
'\\lumposx [mm]',
42 'title':
'Beam Spot Position x',
'atit':
'Luminous centroid x [mm]',
'min': -2,
'max': 6},
43 'posY': {
'units':
'mm',
'fmt':
'%10.4f',
'latexheader':
'$y$ [mm]',
44 'altfmt':
'%10.3f',
'altlatexheader':
'\\lumposy [mm]',
45 'title':
'Beam Spot Position y',
'atit':
'Luminous centroid y [mm]',
'min': -2,
'max': 6},
46 'posZ': {
'units':
'mm',
'fmt':
'%10.2f',
'latexheader':
'$z$ [mm]',
47 'altfmt':
'%10.1f',
'altlatexheader':
'\\lumposz [mm]',
48 'title':
'Beam Spot Position z',
'atit':
'Luminous centroid z [mm]',
'min': -100,
'max': 100},
49 'sigmaX': {
'units':
'mm',
'fmt':
'%10.4f',
'latexheader':
r'$\sigma_x$ [mm]',
50 'altfmt':
'%10.0f',
'altfactor': 1000.,
'altlatexheader':
r'\\lumsigx [$\mu$m]',
51 'title':
'Beam Spot Size #sigma_{x}',
'atit':
'Luminous size #sigma_{x} [mm]',
'min': 0,
'max': 0.6},
52 'sigmaY': {
'units':
'mm',
'fmt':
'%10.4f',
'latexheader':
r'$\sigma_y$ [mm]',
53 'altfmt':
'%10.0f',
'altfactor': 1000.,
'altlatexheader':
r'\\lumsigy [$\mu$m]',
54 'title':
'Beam Spot Size #sigma_{y}',
'atit':
'Luminous size #sigma_{y} [mm]',
'min': 0,
'max': 0.6},
55 'sigmaZ': {
'units':
'mm',
'fmt':
'%10.2f',
'latexheader':
r'$\sigma_z$ [mm]',
56 'altfmt':
'%10.0f',
'altlatexheader':
'\\lumsigz [mm]',
57 'title':
'Beam Spot Size #sigma_{z}',
'atit':
'Luminous size #sigma_{z} [mm]',
'min': 0,
'max': 150},
58 'tiltX': {
'units':
'rad',
'fmt':
'%10.6f',
'latexheader':
'tilt$_{xz}$ [rad]',
59 'altfmt':
'%10.0f',
'altfactor': 1.E6,
'altlatexheader':
'\\lumtiltx [$\\mu$rad]',
60 'title':
'Beam Spot Tilt x-z',
'atit':
'Luminous region tilt in x-z [mrad]',
'arescale': 1000.,
'min': -2.,
'max': 4.},
61 'tiltY': {
'units':
'rad',
'fmt':
'%10.6f',
'latexheader':
'tilt$_{yz}$ [rad]',
62 'altfmt':
'%10.0f',
'altfactor': 1.E6,
'altlatexheader':
'\\lumtilty [$\\mu$rad]',
63 'title':
'Beam Spot Tilt y-z',
'atit':
'Luminous region tilt in y-z [mrad]',
'arescale': 1000.,
'min': -2.,
'max': 4.},
64 'posXErr': {
'units':
'mm',
'fmt':
'%10.4f',
65 'title':
'Uncertainty on Beam Spot Position',
'atit':
'Uncertainty on luminous centroid x [mm]',
'min': 0,
'max': .005},
66 'posYErr': {
'units':
'mm',
'fmt':
'%10.4f',
67 'title':
'Uncertainty on Beam Spot Position',
'atit':
'Uncertainty on luminous centroid y [mm]',
'min': 0,
'max': .005},
68 'posZErr': {
'units':
'mm',
'fmt':
'%10.2f',
69 'title':
'Uncertainty on Beam Spot Position',
'atit':
'Uncertainty on luminous centroid z [mm]',
'min': 0,
'max': 5},
70 'sigmaXErr': {
'units':
'mm',
'fmt':
'%10.3f',
71 'title':
'Uncertainty on Beam Spot Size',
'atit':
'Uncertainty on luminous size #sigma_{x} [mm]',
'min': 0,
'max': 0.005},
72 'sigmaYErr': {
'units':
'mm',
'fmt':
'%10.3f',
73 'title':
'Uncertainty on Beam Spot Size',
'atit':
'Uncertainty on luminous size #sigma_{y} [mm]',
'min': 0,
'max': 0.005},
74 'sigmaZErr': {
'units':
'mm',
'fmt':
'%10.2f',
75 'title':
'Uncertainty on Beam Spot Size',
'atit':
'Uncertainty on luminous size #sigma_{z} [mm]',
'min': 0,
'max': 5},
76 'tiltXErr': {
'units':
'rad',
'fmt':
'%10.6f',
77 'title':
'Uncertainty on Beam Spot Tilt',
'atit':
'Uncertainty on luminous region tilt in x-z [rad]',
'min': 0,
'max': .0001},
78 'tiltYErr': {
'units':
'rad',
'fmt':
'%10.6f',
79 'title':
'Uncertainty on Beam Spot Tilt',
'atit':
'Uncertainty on luminous region tilt in y-z [rad]',
'min': 0,
'max': .0001},
80 'rhoXY': {
'fmt':
'%10.3f',
'latexheader':
'$\\rho_{xy}$',
81 'altfmt':
'%10.2f',
'altfactor': 1.,
'altlatexheader':
'\\lumrhoxy',
82 'title':
'Beam Spot #rho_{xy}',
'atit':
'#rho',
'min': -1.,
'max': 1.5},
83 'rhoXYErr': {
'fmt':
'%10.3f',
84 'title':
'Uncertainty on Beam Spot #rho_{xy}',
'atit':
'Uncertainty on #rho',
'min': 0,
'max': .1},
85 'covSxSy': {
'fmt':
'%10.3f',
86 'title':
'Covariance of Beam Spot #sigma_{x}#sigma_{y}',
'atit':
'Covariance of #sigma_{x}#sigma_{y}',
'min': -.1,
'max': .1},
87 'covSxRhoXY':{
'fmt':
'%10.3f',
88 'title':
'Covariance of Beam Spot #sigma_{x}#rho_{xy}',
'atit':
'Covariance of #sigma_{x}#rho_{xy}',
'min': -.1,
'max': .1},
89 'covSyRhoXY':{
'fmt':
'%10.3f',
90 'title':
'Covariance of Beam Spot #sigma_{y}#rho_{xy}',
'atit':
'Covariance of #sigma_{y}#rho_{xy}',
'min': -.1,
'max': .1},
91 'k': {
'fmt':
'%10.3f',
'latexheader':
'k',
'altlatexheader':
'k',
92 'title':
'Error Scale Factor k',
'atit':
'k',
'min': 0.5,
'max': 2.0},
93 'kErr': {
'fmt':
'%10.3f',
94 'title':
'Uncertainty on Error Scale Factor k',
'atit':
'Uncertainty on k',
'min': 0,
'max': 0.2},
95 'sigmaXY': {
'fmt':
'%10.6f',
'latexheader':
r'$\sigma_{xy}$',
96 'title':
'Beam Spot Size #sigma_{xy}',
'atit':
'#sigma_{xy}',
'min': -0.0005,
'max': 0.0005},
100 varDefsTable = copy.deepcopy(varDefsGen)
101 varDefsTable[
'posX'][
'altfmt'] =
'%10.4f'
102 varDefsTable[
'posY'][
'altfmt'] =
'%10.4f'
103 varDefsTable[
'posZ'][
'altfmt'] =
'%10.4f'
104 varDefsTable[
'sigmaX'][
'altfmt'] =
'%10.1f'
105 varDefsTable[
'sigmaY'][
'altfmt'] =
'%10.1f'
106 varDefsTable[
'sigmaZ'][
'altfmt'] =
'%10.1f'
107 varDefsTable[
'tiltX'][
'altfmt'] =
'%10.1f'
108 varDefsTable[
'tiltY'][
'altfmt'] =
'%10.1f'
109 varDefsTable[
'rhoXY'][
'altfmt'] =
'%10.3f'
112 varDefsRun1 = copy.deepcopy(varDefsGen)
113 varDefsRun1[
'posX'][
'min'] = -1.
114 varDefsRun1[
'posX'][
'max'] = +1.
115 varDefsRun1[
'posY'][
'min'] = 0.
116 varDefsRun1[
'posY'][
'max'] = 2.
117 varDefsRun1[
'posZ'][
'min'] = -60.
118 varDefsRun1[
'posZ'][
'max'] = +60.
119 varDefsRun1[
'sigmaX'][
'max'] = 0.1
120 varDefsRun1[
'sigmaY'][
'max'] = 0.1
121 varDefsRun1[
'sigmaZ'][
'max'] = 80.
122 varDefsRun1[
'tiltX'][
'min'] = -0.4
123 varDefsRun1[
'tiltX'][
'max'] = +0.4
124 varDefsRun1[
'tiltY'][
'min'] = -0.4
125 varDefsRun1[
'tiltY'][
'max'] = +0.4
128 varDefsRun1VtxPaper = copy.deepcopy(varDefsGen)
129 varDefsRun1VtxPaper[
'posX'][
'atit'] =
'x [mm]'
130 varDefsRun1VtxPaper[
'posY'][
'atit'] =
'y [mm]'
131 varDefsRun1VtxPaper[
'posZ'][
'atit'] =
'z [mm]'
132 varDefsRun1VtxPaper[
'sigmaX'][
'atit'] =
'#sigma_{x} [mm]'
133 varDefsRun1VtxPaper[
'sigmaY'][
'atit'] =
'#sigma_{y} [mm]'
134 varDefsRun1VtxPaper[
'sigmaZ'][
'atit'] =
'#sigma_{z} [mm]'
137 varDefsMC14 = copy.deepcopy(varDefsGen)
138 varDefsMC14[
'posX'][
'min'] = -0.297
139 varDefsMC14[
'posX'][
'max'] = -0.287
140 varDefsMC14[
'posX'][
'ndivs'] = 502
141 varDefsMC14[
'posY'][
'min'] = 0.698
142 varDefsMC14[
'posY'][
'max'] = 0.708
143 varDefsMC14[
'posY'][
'ndivs'] = 502
144 varDefsMC14[
'posZ'][
'min'] = -14
145 varDefsMC14[
'posZ'][
'max'] = -4
146 varDefsMC14[
'posZ'][
'ndivs'] = 502
147 varDefsMC14[
'sigmaX'][
'min'] = 0.00
148 varDefsMC14[
'sigmaX'][
'max'] = 0.02
149 varDefsMC14[
'sigmaX'][
'ndivs'] = 502
150 varDefsMC14[
'sigmaY'][
'min'] = 0.00
151 varDefsMC14[
'sigmaY'][
'max'] = 0.02
152 varDefsMC14[
'sigmaY'][
'ndivs'] = 502
153 varDefsMC14[
'sigmaZ'][
'min'] = 40
154 varDefsMC14[
'sigmaZ'][
'max'] = 50
155 varDefsMC14[
'sigmaZ'][
'ndivs'] = 502
156 varDefsMC14[
'tiltX'][
'min'] = -0.1
157 varDefsMC14[
'tiltX'][
'max'] = -0.0
158 varDefsMC14[
'tiltX'][
'ndivs'] = 502
159 varDefsMC14[
'tiltY'][
'min'] = -0.1
160 varDefsMC14[
'tiltY'][
'max'] = -0.0
161 varDefsMC14[
'tiltY'][
'ndivs'] = 502
162 varDefsMC14[
'k'][
'min'] = 0.6
163 varDefsMC14[
'k'][
'max'] = 1.6
164 varDefsMC14[
'k'][
'ndivs'] = 510
167 varDefsMC14Profile = copy.deepcopy(varDefsGen)
168 varDefsMC14Profile[
'posX'][
'min'] = -0.297
169 varDefsMC14Profile[
'posX'][
'max'] = -0.287
170 varDefsMC14Profile[
'posX'][
'ndivs'] = 502
171 varDefsMC14Profile[
'posY'][
'min'] = 0.698
172 varDefsMC14Profile[
'posY'][
'max'] = 0.708
173 varDefsMC14Profile[
'posY'][
'ndivs'] = 502
174 varDefsMC14Profile[
'posZ'][
'min'] = -14
175 varDefsMC14Profile[
'posZ'][
'max'] = -4
176 varDefsMC14Profile[
'posZ'][
'ndivs'] = 502
177 varDefsMC14Profile[
'sigmaX'][
'min'] = 0.013
178 varDefsMC14Profile[
'sigmaX'][
'max'] = 0.018
179 varDefsMC14Profile[
'sigmaX'][
'ndivs'] = 505
180 varDefsMC14Profile[
'sigmaY'][
'min'] = 0.013
181 varDefsMC14Profile[
'sigmaY'][
'max'] = 0.018
182 varDefsMC14Profile[
'sigmaY'][
'ndivs'] = 505
183 varDefsMC14Profile[
'sigmaZ'][
'min'] = 45
184 varDefsMC14Profile[
'sigmaZ'][
'max'] = 50
185 varDefsMC14Profile[
'sigmaZ'][
'ndivs'] = 505
186 varDefsMC14Profile[
'tiltX'][
'min'] = -0.1
187 varDefsMC14Profile[
'tiltX'][
'max'] = -0.0
188 varDefsMC14Profile[
'tiltX'][
'ndivs'] = 502
189 varDefsMC14Profile[
'tiltY'][
'min'] = -0.1
190 varDefsMC14Profile[
'tiltY'][
'max'] = -0.0
191 varDefsMC14Profile[
'tiltY'][
'ndivs'] = 502
192 varDefsMC14Profile[
'k'][
'min'] = 0.9
193 varDefsMC14Profile[
'k'][
'max'] = 1.2
194 varDefsMC14Profile[
'k'][
'ndivs'] = 503
197 varDefsTruthCorr = copy.deepcopy(varDefsGen)
198 varDefsTruthCorr[
'posX'][
'atit'] =
'Luminous centroid x - generated value [mm]'
199 varDefsTruthCorr[
'posX'][
'min'] = -0.005
200 varDefsTruthCorr[
'posX'][
'max'] = 0.005
201 varDefsTruthCorr[
'posX'][
'ndivs'] = 502
202 varDefsTruthCorr[
'posY'][
'atit'] =
'Luminous centroid y - generated value [mm]'
203 varDefsTruthCorr[
'posY'][
'min'] = -0.005
204 varDefsTruthCorr[
'posY'][
'max'] = 0.005
205 varDefsTruthCorr[
'posY'][
'ndivs'] = 502
206 varDefsTruthCorr[
'posZ'][
'atit'] =
'Luminous centroid z - generated value [mm]'
207 varDefsTruthCorr[
'posZ'][
'min'] = -5.
208 varDefsTruthCorr[
'posZ'][
'max'] = 5.
209 varDefsTruthCorr[
'posZ'][
'ndivs'] = 502
210 varDefsTruthCorr[
'sigmaX'][
'atit'] =
'Luminous size #sigma_{x} - generated value [mm]'
211 varDefsTruthCorr[
'sigmaX'][
'min'] = -0.005
212 varDefsTruthCorr[
'sigmaX'][
'max'] = 0.005
213 varDefsTruthCorr[
'sigmaX'][
'ndivs'] = 502
214 varDefsTruthCorr[
'sigmaY'][
'atit'] =
'Luminous size #sigma_{y} - generated value [mm]'
215 varDefsTruthCorr[
'sigmaY'][
'min'] = -0.005
216 varDefsTruthCorr[
'sigmaY'][
'max'] = 0.005
217 varDefsTruthCorr[
'sigmaY'][
'ndivs'] = 502
218 varDefsTruthCorr[
'sigmaZ'][
'atit'] =
'Luminous size #sigma_{z} - generated value [mm]'
219 varDefsTruthCorr[
'sigmaZ'][
'min'] = -5.
220 varDefsTruthCorr[
'sigmaZ'][
'max'] = 5.
221 varDefsTruthCorr[
'sigmaZ'][
'ndivs'] = 502
222 varDefsTruthCorr[
'tiltX'][
'atit'] =
'Luminous region tilt in x-z - generated value [mrad]'
223 varDefsTruthCorr[
'tiltX'][
'min'] = -0.05
224 varDefsTruthCorr[
'tiltX'][
'max'] = 0.05
225 varDefsTruthCorr[
'tiltX'][
'ndivs'] = 502
226 varDefsTruthCorr[
'tiltY'][
'atit'] =
'Luminous region tilt in y-z - generated value [mrad]'
227 varDefsTruthCorr[
'tiltY'][
'min'] = -0.05
228 varDefsTruthCorr[
'tiltY'][
'max'] = 0.05
229 varDefsTruthCorr[
'tiltY'][
'ndivs'] = 502
230 varDefsTruthCorr[
'sigmaXY'][
'atit'] =
'#sigma_{xy} - generated value'
231 varDefsTruthCorr[
'sigmaXY'][
'min'] = -0.05e-3
232 varDefsTruthCorr[
'sigmaXY'][
'max'] = 0.05e-3
233 varDefsTruthCorr[
'sigmaXY'][
'ndivs'] = 502
237 def varDef(var,property,default='',useAlternate=False,override=None):
241 v = varDefs[var].
get(property,default)
243 v = varDefs[var].
get(
'alt'+property,v)
248 def fmtVal(var,value,strip=False,useAlternate=False):
249 fmt =
varDef(var,
'fmt',
'%s')
251 value *=
varDef(var,
'altfactor',1.)
252 fmt =
varDef(var,
'altfmt',fmt)
262 """Class to hold information about a single set of beam spot parameters.
263 The beam spot parametrization follows the COOL convention (see
264 https://twiki.cern.ch/twiki/bin/view/Atlas/CoolBeamSpotParameters)."""
268 propertyList = [
'sigmaXY',
'sigmaXYErr',
'thetaXY',
'thetaXYErr',
'defects',
'fullCorrelations',
'addScanVars']
272 def __init__(self, fullCorrelations=False, addScanVars=False):
425 from InDetBeamSpotExample.DQUtilities
import IDBSDefectEncoding
426 return IDBSDefectEncoding.intToDefectList(self.
defectWord)
429 if not BeamSpotValue.coolQuery:
431 BeamSpotValue.coolQuery = COOLQuery()
441 self.
fill = BeamSpotValue.coolQuery.getLHCInfo(self.
timeStart).
get(
'FillNumber',0)
446 if not BeamSpotValue.coolQuery:
448 BeamSpotValue.coolQuery = COOLQuery()
450 scanPars = BeamSpotValue.coolQuery.scanInfo(self.
run,self.
lbStart)
451 if scanPars
is not None:
475 if not BeamSpotValue.pseudoLbDict:
476 f =
open(pseudoLbFile)
477 for pLb, line
in enumerate(f):
478 tokens = line.split()
479 if len(tokens) < 5: tokens.append(0.0)
480 point, start, end, sep, acq = tokens
481 print (
"point %s %s %s %s" % (point,start,sep,acq))
485 print (
"Missing %s in pseudoLbDict" % self.
lbStart)
495 if not BeamSpotValue.coolQuery:
497 BeamSpotValue.coolQuery = COOLQuery()
500 self.
fill = BeamSpotValue.coolQuery.getLHCInfo(self.
timeStart).
get(
'FillNumber',0)
508 Fill DQ defects assuming that any defect is valid for the full fit range
510 from InDetBeamSpotExample.DQUtilities
import IDBSDefectEncoding
512 if not BeamSpotValue.defectData:
513 from InDetBeamSpotExample.DQUtilities
import IDBSDefectData
514 BeamSpotValue.defectData = IDBSDefectData()
516 defects = BeamSpotValue.defectData.defectsRange(self.
run, self.
lbStart, self.
lbEnd)
517 self.
defectWord = IDBSDefectEncoding.defectListToInt(defects)
524 s +=
'%s - %s\n' % (time.strftime(
'%a %b %d %X %Z %Y',time.localtime(self.
timeStart)),
525 time.strftime(
'%a %b %d %X %Z %Y',time.localtime(self.
timeEnd)))
526 for v
in [
'posX',
'posY',
'posZ',
527 'sigmaX',
'sigmaY',
'sigmaZ',
528 'tiltX',
'tiltY',
'sigmaXY',
'k']:
529 s +=
'... %6s: %s +- %s %s\n' % (v,
530 fmtVal(v,getattr(self,v)),
531 fmtVal(v,getattr(self,v+
'Err')),
536 """Get one-line summary info."""
537 return '[%i, %i - %i), fill %i, BCID %i: %i events, %i selected, status %i' % (self.
run,self.
lbStart,self.
lbEnd,
542 """Standard printout of beam spot parameters."""
549 """Get list of variable names in BeamSpotValue object."""
551 for name
in dir(self):
553 if name
in BeamSpotValue.propertyList:
555 o = getattr(self,name)
556 if isinstance(o,int)
or isinstance(o,float):
561 """Get ROOT type of variable (either /I or /F)."""
562 o = getattr(self,var)
563 if isinstance(o,int):
569 """Return a string with a C struct describing all data members of the instance.
570 Intended for creating ROOT tree buffer objects via ROOT.gROOT.ProcessLine()."""
571 s =
'struct BeamSpotNtBuf {'
573 o = getattr(self,name)
574 if isinstance(o,int):
575 s +=
' Int_t %s;' % name
576 if isinstance(o,float):
577 s +=
' Float_t %s;' % name
582 if self.
run != other.run:
584 if self.
bcid != other.bcid:
591 """A utility class for averaging beam spot data."""
593 def __init__(self,varList=None,weightedAverage=True):
597 self.
varList = [
'posX',
'posY',
'posZ',
'sigmaX',
'sigmaY',
'sigmaZ',
'tiltX',
'tiltY',
'rhoXY',
'k']
611 """Read iLumiCalc.exe ntuple with luminosity data, store data in self.lumiData dict."""
612 lumiFile = ROOT.TFile(lumiCalcNtupleName)
613 lumiNt = lumiFile.Get(
'LumiMetaData')
614 print (
'Reading',lumiNt.GetEntries(),
'entries from luminosity ntuple',lumiCalcNtupleName)
616 for j
in range(lumiNt.GetEntries()):
620 lumi = lumiNt.IntLumi
628 for (lb,lumi)
in lbdict.items():
630 print (
'... total luminosity = %6.1f / pb' % (lumiSum/1.E6))
634 """Add elements of BeamSpotValue b to average."""
637 if b.lbEnd <= b.lbStart:
638 print (
'ERROR: Illegal luminosity block range: [%i,%i]' % (b.lbStart,b.lbEnd))
640 for lb
in range(b.lbStart,b.lbEnd):
644 print (
'ERROR: missing luminosity information for run %i LB %i (in [%i,%i]) - weight set to zero!!' % (b.run,lb,b.lbStart,b.lbEnd))
648 val = getattr(b,parName)
649 valErr = getattr(b,parName+
'Err')
652 self.
sumxx[i] += val*val
658 print (
'WARNING: Divison by zero for parameter %s (val = %f valErr = %f)\n' % (parName,val,valErr))
663 self.
sumwx[i] += w*val
664 self.
sumwxx[i] += w*val*val
665 self.
sumwwee[i] += w*w*valErr*valErr
689 """A utility class for accumulating beam spot data into TGraphErrors."""
691 def __init__(self, timeAxis = False, bcidAxis = False, separationAxis = False):
706 def add(self,bs,what,arescale=1.):
707 """Add element what of BeamSpotValue bs to the graph."""
709 y = arescale*getattr(bs,what)
710 ey = arescale*getattr(bs,what+
'Err',0)
711 ex = (bs.lbEnd - bs.lbStart)/2.
712 x = self.
xoffset + bs.lbStart + ex
715 ex = (bs.timeEnd - bs.timeStart)/2.
716 x = self.
xoffset + bs.timeStart + ex
735 gr = ROOT.TGraphErrors(len(self.
x),self.
x,self.
y,self.
ex,self.
ey)
746 """Base class for containers of beam spot data such as ntuples or
747 information stored in COOL. Derived classes must implement method
748 allData() to iterate over all elements in the container."""
793 """Iterator to iterate over selected elements in the container."""
798 """Return next selected element in the container."""
802 """Return next selected element in the container."""
806 """Default generator to iterate over all data. Must be overridden by derived classes."""
807 raise StopIteration()
810 """Generator to iterate over selected elements in the container."""
817 if b.run<self.
runMin:
continue
818 if b.run>self.
runMax:
continue
821 if b.fill<self.
fillMin:
continue
822 if b.fill>self.
fillMax:
continue
823 if b.bcid<self.
bcidMin:
continue
824 if b.bcid>self.
bcidMax:
continue
825 if b.lbStart<self.
lbMin:
continue
826 if b.lbEnd-1>self.
lbMax:
continue
827 if b.timeStart<self.
timeMin:
continue
828 if b.timeEnd>self.
timeMax:
continue
834 from DQUtils.sugar
import RANGEIOV_VAL, RunLumi
835 from DQUtils
import IOVSet
847 for i, iov
in enumerate(self.
grlIOVs[idx:]):
848 if (test_iov.since >= iov.since
and test_iov.until <= iov.until):
866 print (
'\n%i entries selected out of total of %i entries in ntuple:' % (self.
nSel,self.
nTot))
870 print (
'... %s - %s' % (time.strftime(
'%a %b %d %X %Z %Y',time.localtime(self.
selTimeMin)),
871 time.strftime(
'%a %b %d %X %Z %Y',time.localtime(self.
selTimeMax))))
875 """Get a cache of all data in the form of a dict of runs, where each element
876 is a dict with a BeamSpotValue for each individual lumi blocks."""
882 if b.lbEnd-b.lbStart > 500:
883 print (
'WARNING: Cannot cache LB range %i ... %i for run %i' % (b.lbStart,b.lbEnd,r))
885 for i
in range(b.lbStart,b.lbEnd+1):
891 """Get one-line info of Ntuple. Should be overridden by derived classes."""
892 return "BeamSpotContainer base class"
895 """Get summary of cuts made when looping over selected data."""
902 s +=
' LB %7i ... %7i\n' % (self.
lbMin,self.
lbMax)
904 s +=
' %s - %s' % (time.strftime(
'%a %b %d %X %Z %Y',time.localtime(self.
timeMin)),
905 time.strftime(
'%a %b %d %X %Z %Y',time.localtime(self.
timeMax)))
906 s +=
' acquisition flag %7s' % self.
acqFlag
908 s +=
' GRL %s\n' % self.
grl
913 ROOT.gROOT.ProcessLine(
BeamSpotValue(fullCorrelations=
True,addScanVars=
True).getROOTStruct())
914 from ROOT
import BeamSpotNtBuf
915 from cppyy.ll
import cast
918 """BeamSpotContainer for master beam spot ntuple."""
920 def __init__(self,fileName,update=False,fullCorrelations=False,addScanVars=False):
921 BeamSpotContainer.__init__(self)
934 self.
nt = ROOT.TTree(self.
treeName,
'Master beam spot ntuple')
935 for v
in bs.varList():
936 varType = bs.getROOTType(v)
937 self.
nt.Branch(v,ROOT.addressof( self.
ntbuf,v), v+varType)
939 for v
in bs.varList():
940 self.
nt.SetBranchAddress(v,cast[
'void*'](ROOT.addressof(self.
ntbuf,v)))
942 self.
rootFile = ROOT.TFile(fileName)
945 raise ValueError (
'Tree %s not found in ntuple file %s' % (self.
treeName,self.
fileName))
966 setattr(bs,v,getattr(self.
nt,v,0))
970 for v
in bs.varList():
971 setattr(self.
ntbuf,v,getattr(bs,v))
977 s +=
' UPDATE MODE enabled\n'
978 s +=
' %s ntuple in tree %s\n' % (self.__class__.__name__,self.
treeName)
984 """BeamSpotContainer for ntuples created by InDetBeamSpotFinder."""
991 fitResultToStatusMap = {0: 0, 1: 3, 2: 0, 3: 0}
992 fitIdToStatusMap = {1: 0x38, 2: 0x40, 3: 0x10}
994 def __init__(self,fileName,treeName = 'BeamSpotNt',fullCorrelations=True):
995 BeamSpotContainer.__init__(self)
1002 raise ValueError (
'Tree %s not found in ntuple file %s' % (treeName,fileName))
1024 bs.run = self.
nt.run
1026 bs.bcid = self.
nt.bcid
1029 bs.lbStart = self.
nt.lumiStart
1030 bs.lbEnd = self.
nt.lumiStart+self.
nt.lumiRange
1031 bs.nEvents = self.
nt.nEvents
1033 bs.nValid = self.
nt.nValid
1037 bs.nVtxAll = self.
nt.nVtxAll
1041 bs.nVtxPrim = self.
nt.nVtxPrim
1044 bs.posX = self.
nt.xc
1045 bs.posY = self.
nt.yc
1047 bs.sigmaX = self.
nt.sx
1048 bs.sigmaY = self.
nt.sy
1049 bs.sigmaZ = self.
nt.sz
1050 bs.tiltX = self.
nt.ax
1051 bs.tiltY = self.
nt.ay
1052 bs.rhoXY = self.
nt.rhoxy
1054 bs.posXErr = sqrt(self.
nt.xcxc)
1055 bs.posYErr = sqrt(self.
nt.ycyc)
1056 bs.posZErr = sqrt(self.
nt.zz)
1057 bs.sigmaXErr = sqrt(self.
nt.sxsx)
1058 bs.sigmaYErr = sqrt(self.
nt.sysy)
1059 bs.sigmaZErr = sqrt(self.
nt.szsz)
1060 bs.tiltXErr = sqrt(self.
nt.axax)
1061 bs.tiltYErr = sqrt(self.
nt.ayay)
1062 bs.rhoXYErr = sqrt(self.
nt.rhoxyrhoxy)
1063 bs.kErr = sqrt(self.
nt.kk)
1064 bs.covSxSy = self.
nt.sxsy
1065 bs.covSxRhoXY = self.
nt.sxrhoxy
1066 bs.covSyRhoXY = self.
nt.syrhoxy
1068 bs.covXY = self.
nt.x0y0
1069 bs.covXZ = self.
nt.x0z
1070 bs.covXSx = self.
nt.x0sx
1071 bs.covXSy = self.
nt.x0sy
1072 bs.covXSz = self.
nt.x0sz
1073 bs.covXTiltX = self.
nt.x0ax
1074 bs.covXTiltY = self.
nt.x0ay
1075 bs.covXRhoXY = self.
nt.x0rhoxy
1076 bs.covXk = self.
nt.x0k
1078 bs.covYZ = self.
nt.y0z
1079 bs.covYSx = self.
nt.y0sx
1080 bs.covYSy = self.
nt.y0sy
1081 bs.covYSz = self.
nt.y0sz
1082 bs.covYTiltX = self.
nt.y0ax
1083 bs.covYTiltY = self.
nt.y0ay
1084 bs.covYRhoXY = self.
nt.y0rhoxy
1085 bs.covYk = self.
nt.y0k
1087 bs.covZSx = self.
nt.zsx
1088 bs.covZSy = self.
nt.zsy
1089 bs.covZSz = self.
nt.zsz
1090 bs.covZTiltX = self.
nt.zax
1091 bs.covZTiltY = self.
nt.zay
1092 bs.covZRhoXY = self.
nt.zrhoxy
1093 bs.covZk = self.
nt.zk
1095 bs.covTiltXTiltY = self.
nt.axay
1096 bs.covTiltXSx = self.
nt.axsx
1097 bs.covTiltXSy = self.
nt.axsy
1098 bs.covTiltXSz = self.
nt.axsz
1099 bs.covTiltXRhoXY = self.
nt.axrhoxy
1100 bs.covTiltXk = self.
nt.axk
1102 bs.covTiltYSx = self.
nt.aysx
1103 bs.covTiltYSy = self.
nt.aysy
1104 bs.covTiltYSz = self.
nt.aysz
1105 bs.covTiltYRhoXY = self.
nt.ayrhoxy
1106 bs.covTiltYk = self.
nt.ayk
1108 bs.covSxSz = self.
nt.sxsz
1109 bs.covSxk = self.
nt.sxk
1111 bs.covSySz = self.
nt.sysz
1112 bs.covSyk = self.
nt.syk
1114 bs.covSzRhoXY = self.
nt.szrhoxy
1115 bs.covSzk = self.
nt.szk
1117 bs.covRhoXYk = self.
nt.rhoxyk
1123 s +=
' %s ntuple in tree %s\n' % (self.__class__.__name__,self.
treeName)
1129 """BeamSpotContainer for beam spot information stored in COOL."""
1131 def __init__(self, tag, database='COOLOFL_INDET/CONDBR2', folder='/Indet/Beampos', fullCorrelations=False):
1132 BeamSpotContainer.__init__(self)
1136 from CoolConvUtilities
import AtlCoolLib
1137 self.
cooldb = AtlCoolLib.indirectOpen(database,
True,
True)
1140 self.
cooldb.closeDatabase()
1143 from PyCool
import cool
1148 iov2 = (self.
runMax+1) << 32
1149 if (iov2>cool.ValidityKeyMax):
1150 iov2=cool.ValidityKeyMax
1152 itr = folder.browseObjects(iov1, iov2, cool.ChannelSelection.all(), self.
tag)
1154 while itr.goToNext():
1156 obj = itr.currentRef()
1159 runBegin = since >> 32
1160 lumiBegin = since & 0xFFFFFFFF
1163 lumiUntil = until & 0xFFFFFFFF
1166 bs.run =
int(runBegin)
1167 bs.lbStart =
int(lumiBegin)
1168 bs.lbEnd =
int(lumiUntil)
1169 bs.posX =
float(obj.payloadValue(
'posX'))
1170 bs.posY =
float(obj.payloadValue(
'posY'))
1171 bs.posZ =
float(obj.payloadValue(
'posZ'))
1172 bs.sigmaX =
float(obj.payloadValue(
'sigmaX'))
1173 bs.sigmaY =
float(obj.payloadValue(
'sigmaY'))
1174 bs.sigmaZ =
float(obj.payloadValue(
'sigmaZ'))
1175 bs.tiltX =
float(obj.payloadValue(
'tiltX'))
1176 bs.tiltY =
float(obj.payloadValue(
'tiltY'))
1177 bs.status =
int(obj.payloadValue(
'status'))
1178 bs.posXErr =
float(obj.payloadValue(
'posXErr'))
1179 bs.posYErr =
float(obj.payloadValue(
'posYErr'))
1180 bs.posZErr =
float(obj.payloadValue(
'posZErr'))
1181 bs.sigmaXErr =
float(obj.payloadValue(
'sigmaXErr'))
1182 bs.sigmaYErr =
float(obj.payloadValue(
'sigmaYErr'))
1183 bs.sigmaZErr =
float(obj.payloadValue(
'sigmaZErr'))
1184 bs.tiltXErr =
float(obj.payloadValue(
'tiltXErr'))
1185 bs.tiltYErr =
float(obj.payloadValue(
'tiltYErr'))
1188 sigmaXYtmp =
float(obj.payloadValue(
'sigmaXY'))
1189 sigmaXtmp =
float(obj.payloadValue(
'sigmaX'))
1190 sigmaYtmp =
float(obj.payloadValue(
'sigmaY'))
1191 sigmaXYErrtmp =
float(obj.payloadValue(
'sigmaXYErr'))
1192 sigmaXErrtmp =
float(obj.payloadValue(
'sigmaXErr'))
1193 sigmaYErrtmp =
float(obj.payloadValue(
'sigmaYErr'))
1196 rhoXYtmp = sigmaXYtmp / sigmaXtmp / sigmaYtmp
1202 sumtmp = sigmaXYErrtmp * sigmaXYErrtmp / sigmaXYtmp / sigmaXYtmp
1203 sumtmp += sigmaXErrtmp * sigmaXErrtmp / sigmaXtmp / sigmaXtmp
1204 sumtmp += sigmaYErrtmp * sigmaYErrtmp / sigmaYtmp / sigmaYtmp
1205 rhoXYErrtmp = sqrt(rhoXYtmp * rhoXYtmp * sumtmp)
1209 bs.rhoXYErr = rhoXYErrtmp
1214 s =
'COOL database %s, tag %s:\n' % (self.
database,self.
tag)
1215 s +=
' %s ntuple, COOL folder %s\n' % (self.__class__.__name__,self.
folder)
1219 """BeamSpotContainer for beam spot information stored in online CSV files"""
1221 def __init__(self, filename='/afs/cern.ch/user/a/atlidbs/data/69OnlineBeamspots.csv', delim=','):
1222 BeamSpotContainer.__init__(self)
1235 bs.run =
int(row[
'run'])
1236 bs.lbStart =
int(row[
'firstLBN'])
1237 bs.lbEnd =
int(row[
'lastLBN'])
1238 bs.posX =
float(row[
'posX'])
1239 bs.posY =
float(row[
'posY'])
1240 bs.posZ =
float(row[
'posZ'])
1241 bs.sigmaX =
float(row[
'sigmaX'])
1242 bs.sigmaY =
float(row[
'sigmaY'])
1243 bs.sigmaZ =
float(row[
'sigmaZ'])
1244 bs.tiltX =
float(row[
'tiltX'])
1245 bs.tiltY =
float(row[
'tiltY'])
1246 bs.status =
int(row[
'status'])
1248 bs.posXErr =
float(row[
'posXE'])
1249 bs.posYErr =
float(row[
'posYE'])
1250 bs.posZErr =
float(row[
'posZE'])
1251 bs.sigmaXErr =
float(row[
'sigmaXE'])
1252 bs.sigmaYErr =
float(row[
'sigmaYE'])
1253 bs.sigmaZErr =
float(row[
'sigmaZE'])
1254 bs.tiltXErr =
float(row[
'tiltXE'])
1255 bs.tiltYErr =
float(row[
'tiltYE'])
1261 s =
'CSV file %s:\n' % self.filename
1262 s +=
' %s ntuple\n' % (self.__class__.__name__)
1266 if __name__ ==
'__main__':
1270 data =
BeamSpotNt(
'/afs/cern.ch/user/a/atlidbs/nt/beamspotnt-IndetBeampos-Oct10-Collision_7T_2010_07-v1.root')