CMS 3D CMS Logo

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

Classes

class  bsmeas
 

Functions

def readroot
 
def timeof
 

Variables

tuple allmeas = readroot()
 
list bxmeas = allmeas[bx]
 
tuple file = open(filename,'w')
 
string filename = WORKDIR+"/"
 
string FILL = ''
 
tuple line = str(meastime)
 
dictionary lines = {}
 
tuple lumimax = lumirange.split('-')
 
tuple lumimid = int((int(lumimin)+int(lumimax))/2.)
 
tuple lumimin = lumirange.split('-')
 
tuple lumirange = meas.split(':')
 
tuple meastime = timeof(runno,lumimid)
 
string OUTDIR = "./perbunchfiles/"
 
tuple rfbucket = (int(bx)-1)
 
dictionary runlstime = {}
 
tuple runno = meas.split(':')
 
tuple sortedtimes = lines.keys()
 
list thismeas = bxmeas[meas]
 
 WORKDIR = OUTDIR+FILL
 

Function Documentation

def lumiregperbunch.readroot ( )

Definition at line 108 of file lumiregperbunch.py.

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

Definition at line 39 of file lumiregperbunch.py.

References funct.abs().

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

Variable Documentation

tuple lumiregperbunch.allmeas = readroot()

Definition at line 224 of file lumiregperbunch.py.

list lumiregperbunch.bxmeas = allmeas[bx]

Definition at line 229 of file lumiregperbunch.py.

tuple lumiregperbunch.file = open(filename,'w')

Definition at line 271 of file lumiregperbunch.py.

string lumiregperbunch.filename = WORKDIR+"/"

Definition at line 270 of file lumiregperbunch.py.

list lumiregperbunch.FILL = ''

Definition at line 9 of file lumiregperbunch.py.

tuple lumiregperbunch.line = str(meastime)

Definition at line 248 of file lumiregperbunch.py.

dictionary lumiregperbunch.lines = {}

Definition at line 230 of file lumiregperbunch.py.

tuple lumiregperbunch.lumimax = lumirange.split('-')

Definition at line 238 of file lumiregperbunch.py.

tuple lumiregperbunch.lumimid = int((int(lumimin)+int(lumimax))/2.)

Definition at line 240 of file lumiregperbunch.py.

tuple lumiregperbunch.lumimin = lumirange.split('-')

Definition at line 236 of file lumiregperbunch.py.

tuple lumiregperbunch.lumirange = meas.split(':')

Definition at line 235 of file lumiregperbunch.py.

tuple lumiregperbunch.meastime = timeof(runno,lumimid)

Definition at line 241 of file lumiregperbunch.py.

string lumiregperbunch.OUTDIR = "./perbunchfiles/"

Definition at line 10 of file lumiregperbunch.py.

tuple lumiregperbunch.rfbucket = (int(bx)-1)

Definition at line 269 of file lumiregperbunch.py.

dictionary lumiregperbunch.runlstime = {}

Definition at line 12 of file lumiregperbunch.py.

tuple lumiregperbunch.runno = meas.split(':')

Definition at line 233 of file lumiregperbunch.py.

Referenced by HcalTBWriter.extractEventInfo(), and LMFSeqDat.fetchByRunNumber().

tuple lumiregperbunch.sortedtimes = lines.keys()

Definition at line 272 of file lumiregperbunch.py.

list lumiregperbunch.thismeas = bxmeas[meas]

Definition at line 244 of file lumiregperbunch.py.

lumiregperbunch.WORKDIR = OUTDIR+FILL

Definition at line 267 of file lumiregperbunch.py.