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 106 of file lumiregperbunch.py.

References edm.print().

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

Definition at line 40 of file lumiregperbunch.py.

References funct.abs(), edm.print(), and str.

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 as err:
59  print(" ERROR Found corrupt " \
60  "beamspot measurement entry!", file=sys.stderr)
61  print(" !!! %s !!!" % str(err), file=sys.stderr)
62  continue
63  # Argh!
64  runfromfile=tmp.run_number
65  (lumimin,lumimax)=tmp.lumi_range
66  time_begin=tmp.time_begin
67  time_end=tmp.time_end
68  time_begin=calendar.timegm(time_begin.timetuple())
69  time_end=calendar.timegm(time_end.timetuple())-23 # assume end of lumisection
70  lstime[lumimin]=time_begin
71  lstime[lumimax]=time_end
72 
73  # order lumisections and make a list
74  lslist=sorted(lstime.keys())
75  lstimesorted=[]
76  for ls in lslist:
77  lstimesorted.append((ls,lstime[ls]))
78  runlstime[run]=lstimesorted
79 
80  # print runfromfile
81  # print lumirange
82  # print time_begin, calendar.timegm(time_begin.timetuple())
83  # print time_end, calendar.timegm(time_end.timetuple())
84 
85  in_file.close()
86  # now give a time
87  dcloselumi=999999
88  closelumi=-1
89  closetime=-1
90  lstimesorted=runlstime[run]
91 
92  for pair in lstimesorted:
93  (lumi,time)=pair
94  if abs(lumisection-lumi)<dcloselumi:
95  dcloselumi=abs(lumisection-lumi)
96  closelumi=lumi
97  closetime=time
98  if closelumi!=-1:
99  finaltime=closetime+(lumisection-closelumi)*23
100  else:
101  finaltime=-1
102 
103  return finaltime
104 
105 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def timeof(run, lumisection)
#define str(s)

Variable Documentation

lumiregperbunch.allmeas

Definition at line 222 of file lumiregperbunch.py.

lumiregperbunch.bxmeas

Definition at line 227 of file lumiregperbunch.py.

lumiregperbunch.file

Definition at line 269 of file lumiregperbunch.py.

lumiregperbunch.filename

Definition at line 268 of file lumiregperbunch.py.

lumiregperbunch.FILL

Definition at line 10 of file lumiregperbunch.py.

lumiregperbunch.line

Definition at line 246 of file lumiregperbunch.py.

lumiregperbunch.lines

Definition at line 228 of file lumiregperbunch.py.

lumiregperbunch.lumimax

Definition at line 236 of file lumiregperbunch.py.

lumiregperbunch.lumimid

Definition at line 238 of file lumiregperbunch.py.

lumiregperbunch.lumimin

Definition at line 234 of file lumiregperbunch.py.

lumiregperbunch.lumirange

Definition at line 233 of file lumiregperbunch.py.

lumiregperbunch.meastime

Definition at line 239 of file lumiregperbunch.py.

lumiregperbunch.OUTDIR

Definition at line 11 of file lumiregperbunch.py.

lumiregperbunch.rfbucket

Definition at line 267 of file lumiregperbunch.py.

lumiregperbunch.runlstime

Definition at line 13 of file lumiregperbunch.py.

lumiregperbunch.runno
lumiregperbunch.sortedtimes

Definition at line 270 of file lumiregperbunch.py.

lumiregperbunch.thismeas

Definition at line 242 of file lumiregperbunch.py.

lumiregperbunch.WORKDIR

Definition at line 265 of file lumiregperbunch.py.