CMS 3D CMS Logo

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 = "/"
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.

00109               :
00110     rls=[]
00111     bxlist=[]
00112     allmeas={}
00113     
00114     DIRES=['X0','Y0','Z0','width_X0','Width_Y0','Sigma_Z0','dxdz','dydz']
00115     # DIRES=['X0']
00116     rootfile="BxAnalysis_Fill_"+FILL+".root"
00117     filein=TFile(rootfile)
00118     for dire in DIRES:
00119         filein.cd(dire)
00120         # get list of histograms
00121         histolist=gDirectory.GetListOfKeys()
00122         iter = histolist.MakeIterator()
00123         key = iter.Next()
00124         while key:
00125             if key.GetClassName() == 'TH1F':
00126                 td = key.ReadObj()
00127                 histoname = td.GetName()
00128                 if "bx" in histoname:
00129 #                    print histoname
00130                     bx=histoname.split('_')[-1]
00131                     if bx not in bxlist:
00132 # this is to be removed                        
00133 #                        if len(bxlist)>=2:
00134 #                            key = iter.Next()
00135 #                            continue
00136 # end to be removed                        
00137                         bxlist.append(bx)
00138                         allmeas[bx]={}
00139 #                    print bx,histoname
00140                     histo=gDirectory.Get(histoname)
00141                     nbin=histo.GetNbinsX()
00142 
00143                     thisbx=allmeas[bx]
00144                     
00145                     for bin in range(1,nbin+1):
00146                         label=histo.GetXaxis().GetBinLabel(bin)
00147                         label=label.strip()
00148                         if ":" not in label:
00149                             # not a valid label of type run:lumi-lumi, skip it
00150                             continue
00151                         
00152                         cont=histo.GetBinContent(bin)
00153                         if cont!=cont:
00154                             # it's a nan
00155                             cont=-999.0
00156                         err=histo.GetBinError(bin)
00157                         if err!=err:
00158                             err=-999.0
00159                         #                        if len(bxlist)==1:
00160                         #                            rls.append(label)
00161                         #                            print label
00162                         #                        else:
00163                         if label not in rls:
00164                             print "New range:",label," found in ",histoname
00165                             rls.append(label)
00166                                 
00167                         if label in thisbx.keys():
00168                             thismeas=thisbx[label]
00169                         else:
00170                             thisbx[label]=bsmeas()
00171                             thismeas=thisbx[label]
00172                         #  now filling up
00173                         if dire=='X0':
00174                             thismeas.x=cont
00175                             thismeas.ex=err
00176                         if dire=='Y0':
00177                             thismeas.y=cont
00178                             thismeas.ey=cont
00179                         if dire=='Z0':
00180                             thismeas.z=cont
00181                             thismeas.ez=err
00182                         if dire=='width_X0':
00183                             thismeas.wx=cont
00184                             thismeas.ewx=err
00185                         if dire=='Width_Y0':
00186                             thismeas.wy=cont
00187                             thismeas.ewy=err
00188                         if dire=='Sigma_Z0':
00189                             thismeas.wz=cont
00190                             thismeas.ewz=err
00191                         if dire=='dxdz':
00192                             thismeas.dxdz=cont
00193                             thismeas.edxdz=err
00194                         if dire=='dydz':
00195                             thismeas.dydz=cont
00196                             thismeas.edydz=err
00197 
00198     
00199             key = iter.Next()
00200         
00201         
00202     #    for name in pippo:
00203     #        print name
00204     
00205     filein.Close()
00206 
00207     # let's try to show it
00208 #    for bx in allmeas.keys():
00209 #        print "bx=",bx
00210 #        bxmeas=allmeas[bx]
00211 #        for meas in bxmeas.keys():
00212 #            print "meas time=",meas
00213 #            thismeas=bxmeas[meas]
00214 #            print thismeas.x,thismeas.ex,thismeas.y,thismeas.ey,thismeas.z,thismeas.ez
00215 #            print thismeas.wx,thismeas.ewx,thismeas.wy,thismeas.ewy,thismeas.wz,thismeas.ewz
00216 #            print thismeas.dxdz,thismeas.edxdz,thismeas.dydz,thismeas.edydz
00217     return allmeas

def lumiregperbunch::timeof (   run,
  lumisection 
)

Definition at line 39 of file lumiregperbunch.py.

00040                            :
00041     # first check if this run is already in the list, otherwise read it
00042     if run not in runlstime.keys():
00043         print "Reading lumi time from lumireg localcopy files"
00044         filename="localcopy/BeamFitResults_Run"+run+".txt"
00045         if not os.path.exists(filename):
00046             print "WARNING: file ",filename," does not exist. Returning null."
00047             return -1
00048 
00049         # reading file
00050         lstime={}
00051         in_file = open(filename)
00052         pieces = paragraphs(in_file,start_of_new_beamspot_measurement,True)
00053         for piece in pieces:
00054             if len(piece) < 1:
00055                 continue
00056             try:
00057                 tmp = BeamspotMeasurement(piece)
00058             except Exception, err:
00059                 print >> sys.stderr, \
00060                       "    ERROR Found corrupt " \
00061                       "beamspot measurement entry!"
00062                 print >> sys.stderr, \
00063                       "    !!! %s !!!" % str(err)
00064                 continue
00065             # Argh!
00066             runfromfile=tmp.run_number
00067             (lumimin,lumimax)=tmp.lumi_range
00068             time_begin=tmp.time_begin
00069             time_end=tmp.time_end
00070             time_begin=calendar.timegm(time_begin.timetuple())
00071             time_end=calendar.timegm(time_end.timetuple())-23 # assume end of lumisection
00072             lstime[lumimin]=time_begin
00073             lstime[lumimax]=time_end
00074             
00075         # order lumisections and make a list
00076         lslist=lstime.keys()
00077         lslist.sort()
00078         lstimesorted=[]
00079         for ls in lslist:
00080             lstimesorted.append((ls,lstime[ls]))
00081         runlstime[run]=lstimesorted
00082 
00083         #            print runfromfile
00084         #            print lumirange
00085         #            print time_begin, calendar.timegm(time_begin.timetuple())
00086         #            print time_end, calendar.timegm(time_end.timetuple())
00087         
00088         in_file.close()
00089     # now give a time
00090     dcloselumi=999999
00091     closelumi=-1
00092     closetime=-1
00093     lstimesorted=runlstime[run]
00094     
00095     for pair in lstimesorted:
00096         (lumi,time)=pair
00097         if abs(lumisection-lumi)<dcloselumi:
00098             dcloselumi=abs(lumisection-lumi)
00099             closelumi=lumi
00100             closetime=time
00101     if closelumi!=-1:
00102         finaltime=closetime+(lumisection-closelumi)*23
00103     else:
00104         finaltime=-1
00105         
00106     return finaltime
00107 


Variable Documentation

tuple lumiregperbunch::allmeas = readroot()

Definition at line 224 of file lumiregperbunch.py.

Definition at line 229 of file lumiregperbunch.py.

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

Definition at line 271 of file lumiregperbunch.py.

Definition at line 270 of file lumiregperbunch.py.

Definition at line 9 of file lumiregperbunch.py.

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.

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(':')
tuple lumiregperbunch::sortedtimes = lines.keys()

Definition at line 272 of file lumiregperbunch.py.

Definition at line 244 of file lumiregperbunch.py.

Definition at line 267 of file lumiregperbunch.py.