CMS 3D CMS Logo

Classes | Functions | Variables
lumiregperbunch Namespace Reference

Classes

class  bsmeas
 

Functions

def readroot ()
 
def timeof (run, lumisection)
 

Variables

 allmeas
 
 bxmeas
 
 file
 
 filename
 
 FILL
 
 line
 
 lines
 
 lumimax
 
 lumimid
 
 lumimin
 
 lumirange
 
 meastime
 
 OUTDIR
 
 rfbucket
 
 runlstime
 
 runno
 
 sortedtimes
 
 thismeas
 
 WORKDIR
 

Function Documentation

def lumiregperbunch.readroot ( )

Definition at line 108 of file lumiregperbunch.py.

108 def readroot():
109  rls=[]
110  bxlist=[]
111  allmeas={}
112 
113  DIRES=['X0','Y0','Z0','width_X0','Width_Y0','Sigma_Z0','dxdz','dydz']
114  # DIRES=['X0']
115  rootfile="BxAnalysis_Fill_"+FILL+".root"
116  filein=TFile(rootfile)
117  for dire in DIRES:
118  filein.cd(dire)
119  # get list of histograms
120  histolist=gDirectory.GetListOfKeys()
121  iter = histolist.MakeIterator()
122  key = iter.Next()
123  while key:
124  if key.GetClassName() == 'TH1F':
125  td = key.ReadObj()
126  histoname = td.GetName()
127  if "bx" in histoname:
128 # print histoname
129  bx=histoname.split('_')[-1]
130  if bx not in bxlist:
131 # this is to be removed
132 # if len(bxlist)>=2:
133 # key = iter.Next()
134 # continue
135 # end to be removed
136  bxlist.append(bx)
137  allmeas[bx]={}
138 # print bx,histoname
139  histo=gDirectory.Get(histoname)
140  nbin=histo.GetNbinsX()
141 
142  thisbx=allmeas[bx]
143 
144  for bin in range(1,nbin+1):
145  label=histo.GetXaxis().GetBinLabel(bin)
146  label=label.strip()
147  if ":" not in label:
148  # not a valid label of type run:lumi-lumi, skip it
149  continue
150 
151  cont=histo.GetBinContent(bin)
152  if cont!=cont:
153  # it's a nan
154  cont=-999.0
155  err=histo.GetBinError(bin)
156  if err!=err:
157  err=-999.0
158  # if len(bxlist)==1:
159  # rls.append(label)
160  # print label
161  # else:
162  if label not in rls:
163  print "New range:",label," found in ",histoname
164  rls.append(label)
165 
166  if label in thisbx.keys():
167  thismeas=thisbx[label]
168  else:
169  thisbx[label]=bsmeas()
170  thismeas=thisbx[label]
171  # now filling up
172  if dire=='X0':
173  thismeas.x=cont
174  thismeas.ex=err
175  if dire=='Y0':
176  thismeas.y=cont
177  thismeas.ey=cont
178  if dire=='Z0':
179  thismeas.z=cont
180  thismeas.ez=err
181  if dire=='width_X0':
182  thismeas.wx=cont
183  thismeas.ewx=err
184  if dire=='Width_Y0':
185  thismeas.wy=cont
186  thismeas.ewy=err
187  if dire=='Sigma_Z0':
188  thismeas.wz=cont
189  thismeas.ewz=err
190  if dire=='dxdz':
191  thismeas.dxdz=cont
192  thismeas.edxdz=err
193  if dire=='dydz':
194  thismeas.dydz=cont
195  thismeas.edydz=err
196 
197 
198  key = iter.Next()
199 
200 
201  # for name in pippo:
202  # print name
203 
204  filein.Close()
205 
206  # let's try to show it
207 # for bx in allmeas.keys():
208 # print "bx=",bx
209 # bxmeas=allmeas[bx]
210 # for meas in bxmeas.keys():
211 # print "meas time=",meas
212 # thismeas=bxmeas[meas]
213 # print thismeas.x,thismeas.ex,thismeas.y,thismeas.ey,thismeas.z,thismeas.ez
214 # print thismeas.wx,thismeas.ewx,thismeas.wy,thismeas.ewy,thismeas.wz,thismeas.ewz
215 # print thismeas.dxdz,thismeas.edxdz,thismeas.dydz,thismeas.edydz
216  return allmeas
217 
def lumiregperbunch.timeof (   run,
  lumisection 
)

Definition at line 39 of file lumiregperbunch.py.

References funct.abs(), and harvestTrackValidationPlots.str.

39 def timeof(run,lumisection):
40  # first check if this run is already in the list, otherwise read it
41  if run not in runlstime.keys():
42  print "Reading lumi time from lumireg localcopy files"
43  filename="localcopy/BeamFitResults_Run"+run+".txt"
44  if not os.path.exists(filename):
45  print "WARNING: file ",filename," does not exist. Returning null."
46  return -1
47 
48  # reading file
49  lstime={}
50  in_file = open(filename)
51  pieces = paragraphs(in_file,start_of_new_beamspot_measurement,True)
52  for piece in pieces:
53  if len(piece) < 1:
54  continue
55  try:
56  tmp = BeamspotMeasurement(piece)
57  except Exception as err:
58  print >> sys.stderr, \
59  " ERROR Found corrupt " \
60  "beamspot measurement entry!"
61  print >> sys.stderr, \
62  " !!! %s !!!" % str(err)
63  continue
64  # Argh!
65  runfromfile=tmp.run_number
66  (lumimin,lumimax)=tmp.lumi_range
67  time_begin=tmp.time_begin
68  time_end=tmp.time_end
69  time_begin=calendar.timegm(time_begin.timetuple())
70  time_end=calendar.timegm(time_end.timetuple())-23 # assume end of lumisection
71  lstime[lumimin]=time_begin
72  lstime[lumimax]=time_end
73 
74  # order lumisections and make a list
75  lslist=lstime.keys()
76  lslist.sort()
77  lstimesorted=[]
78  for ls in lslist:
79  lstimesorted.append((ls,lstime[ls]))
80  runlstime[run]=lstimesorted
81 
82  # print runfromfile
83  # print lumirange
84  # print time_begin, calendar.timegm(time_begin.timetuple())
85  # print time_end, calendar.timegm(time_end.timetuple())
86 
87  in_file.close()
88  # now give a time
89  dcloselumi=999999
90  closelumi=-1
91  closetime=-1
92  lstimesorted=runlstime[run]
93 
94  for pair in lstimesorted:
95  (lumi,time)=pair
96  if abs(lumisection-lumi)<dcloselumi:
97  dcloselumi=abs(lumisection-lumi)
98  closelumi=lumi
99  closetime=time
100  if closelumi!=-1:
101  finaltime=closetime+(lumisection-closelumi)*23
102  else:
103  finaltime=-1
104 
105  return finaltime
106 
107 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def timeof(run, lumisection)

Variable Documentation

lumiregperbunch.allmeas

Definition at line 224 of file lumiregperbunch.py.

lumiregperbunch.bxmeas

Definition at line 229 of file lumiregperbunch.py.

lumiregperbunch.file

Definition at line 271 of file lumiregperbunch.py.

lumiregperbunch.filename

Definition at line 270 of file lumiregperbunch.py.

lumiregperbunch.FILL

Definition at line 9 of file lumiregperbunch.py.

lumiregperbunch.line

Definition at line 248 of file lumiregperbunch.py.

lumiregperbunch.lines

Definition at line 230 of file lumiregperbunch.py.

lumiregperbunch.lumimax

Definition at line 238 of file lumiregperbunch.py.

lumiregperbunch.lumimid

Definition at line 240 of file lumiregperbunch.py.

lumiregperbunch.lumimin

Definition at line 236 of file lumiregperbunch.py.

lumiregperbunch.lumirange

Definition at line 235 of file lumiregperbunch.py.

lumiregperbunch.meastime

Definition at line 241 of file lumiregperbunch.py.

lumiregperbunch.OUTDIR

Definition at line 10 of file lumiregperbunch.py.

lumiregperbunch.rfbucket

Definition at line 269 of file lumiregperbunch.py.

lumiregperbunch.runlstime

Definition at line 12 of file lumiregperbunch.py.

lumiregperbunch.runno
lumiregperbunch.sortedtimes

Definition at line 272 of file lumiregperbunch.py.

lumiregperbunch.thismeas

Definition at line 244 of file lumiregperbunch.py.

lumiregperbunch.WORKDIR

Definition at line 267 of file lumiregperbunch.py.