CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 = sorted(lines.keys())
 
list thismeas = bxmeas[meas]
 
 WORKDIR = OUTDIR+FILL
 

Function Documentation

def lumiregperbunch.readroot ( )

Definition at line 107 of file lumiregperbunch.py.

References print(), and sistrip::SpyUtilities.range().

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
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def lumiregperbunch.timeof (   run,
  lumisection 
)

Definition at line 41 of file lumiregperbunch.py.

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

41 
42 def timeof(run,lumisection):
43  # first check if this run is already in the list, otherwise read it
44  if run not in runlstime.keys():
45  print("Reading lumi time from lumireg localcopy files")
46  filename="localcopy/BeamFitResults_Run"+run+".txt"
47  if not os.path.exists(filename):
48  print("WARNING: file ",filename," does not exist. Returning null.")
49  return -1
50 
51  # reading file
52  lstime={}
53  in_file = open(filename)
54  pieces = paragraphs(in_file,start_of_new_beamspot_measurement,True)
55  for piece in pieces:
56  if len(piece) < 1:
57  continue
58  try:
59  tmp = BeamspotMeasurement(piece)
60  except Exception as err:
61  print(" ERROR Found corrupt " \
62  "beamspot measurement entry!", file=sys.stderr)
63  print(" !!! %s !!!" % str(err), file=sys.stderr)
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=sorted(lstime.keys())
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 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define str(s)

Variable Documentation

tuple lumiregperbunch.allmeas = readroot()

Definition at line 223 of file lumiregperbunch.py.

list lumiregperbunch.bxmeas = allmeas[bx]

Definition at line 228 of file lumiregperbunch.py.

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

Definition at line 270 of file lumiregperbunch.py.

string lumiregperbunch.filename = WORKDIR+"/"

Definition at line 269 of file lumiregperbunch.py.

list lumiregperbunch.FILL = ''

Definition at line 11 of file lumiregperbunch.py.

tuple lumiregperbunch.line = str(meastime)

Definition at line 247 of file lumiregperbunch.py.

dictionary lumiregperbunch.lines = {}

Definition at line 229 of file lumiregperbunch.py.

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

Definition at line 237 of file lumiregperbunch.py.

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

Definition at line 239 of file lumiregperbunch.py.

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

Definition at line 235 of file lumiregperbunch.py.

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

Definition at line 234 of file lumiregperbunch.py.

tuple lumiregperbunch.meastime = timeof(runno,lumimid)

Definition at line 240 of file lumiregperbunch.py.

string lumiregperbunch.OUTDIR = "./perbunchfiles/"

Definition at line 12 of file lumiregperbunch.py.

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

Definition at line 268 of file lumiregperbunch.py.

dictionary lumiregperbunch.runlstime = {}

Definition at line 14 of file lumiregperbunch.py.

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

Definition at line 232 of file lumiregperbunch.py.

tuple lumiregperbunch.sortedtimes = sorted(lines.keys())

Definition at line 271 of file lumiregperbunch.py.

list lumiregperbunch.thismeas = bxmeas[meas]

Definition at line 243 of file lumiregperbunch.py.

lumiregperbunch.WORKDIR = OUTDIR+FILL

Definition at line 266 of file lumiregperbunch.py.