CMS 3D CMS Logo

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

Functions

def CacheFilePath
 
def GetXLocator
 
def PlotPeakPUAllYears
 
def processdata
 
def TweakPlot
 

Variables

tuple accel_mode = cfg_parser.get("general", "accel_mode")
 
 amodetag_bug_workaround = False
 
tuple arg_parser = optparse.OptionParser(description=desc_str)
 
 beam_energy = None
 
dictionary beam_energy_defaults
 
 beam_energy_from_cfg = None
 
tuple beam_energy_tmp = cfg_parser.get("general", "beam_energy")
 
 beam_fluctuation = None
 
dictionary beam_fluctuation_defaults
 
 beam_fluctuation_from_cfg = None
 
tuple beam_fluctuation_tmp = cfg_parser.get("general", "beam_fluctuation")
 
tuple cache_file_dir = cfg_parser.get("general", "cache_dir")
 
dictionary cfg_defaults
 
tuple cfg_parser = ConfigParser.SafeConfigParser(cfg_defaults)
 
list color_scheme_names = [i.strip() for i in color_scheme_names_tmp.split(",")]
 
tuple color_scheme_names_tmp = cfg_parser.get("general", "color_schemes")
 
list config_file_name = args[0]
 
tuple date_begin = datetime.datetime.strptime(tmp, DATE_FMT_STR_CFG)
 
 date_end = None
 
string DATE_FMT_STR_AXES = "%-d %b"
 
string DATE_FMT_STR_CFG = "%Y-%m-%d"
 
string DATE_FMT_STR_LUMICALC = "%m/%d/%y %H:%M:%S"
 
string DATE_FMT_STR_LUMICALC_DAY = "%m/%d/%y"
 
string DATE_FMT_STR_OUT = "%Y-%m-%d %H:%M"
 
string desc_str = "test pu"
 
string help = "Ignore all cached lumiCalc results "
 
 ignore_cache = options.ignore_cache
 
list KNOWN_ACCEL_MODES
 
int LEAD_SCALE_FACTOR = 82
 
dictionary lumi_data_by_fill_per_year = {}
 
tuple lumicalc_flags_from_cfg = cfg_parser.get("general", "lumicalc_flags")
 
tuple lumicalc_script = cfg_parser.get("general", "lumicalc_script")
 
int NUM_SEC_IN_LS = 2
 
tuple oracle_connection_string = cfg_parser.get("general", "oracle_connection")
 
list particle_type_str = particle_type_strings[accel_mode]
 
dictionary particle_type_strings
 
tuple path_name = CacheFilePath(cache_file_dir)
 
tuple tmp = cfg_parser.get("general", "date_begin")
 
tuple today = datetime.datetime.utcnow()
 
tuple use_oracle = (len(oracle_connection_string) != 0)
 
tuple verbose = cfg_parser.getboolean("general", "verbose")
 
tuple year_begin = date_begin.isocalendar()
 
tuple year_end = date_end.isocalendar()
 
list years = [2010,2011,2012]
 

Function Documentation

def create_public_peakpu_plots.CacheFilePath (   cache_file_dir,
  day = None 
)

Definition at line 109 of file create_public_peakpu_plots.py.

110 def CacheFilePath(cache_file_dir, day=None):
111  cache_file_path = os.path.abspath(cache_file_dir)
112  if day:
113  cache_file_name = "lumicalc_cache_%s.csv" % day.isoformat()
114  cache_file_path = os.path.join(cache_file_path, cache_file_name)
115  return cache_file_path
116 
def create_public_peakpu_plots.GetXLocator (   ax)
Pick a DateLocator based on the range of the x-axis.

Definition at line 117 of file create_public_peakpu_plots.py.

References bookConverter.min, and TweakPlot().

Referenced by TweakPlot().

118 def GetXLocator(ax):
119  """Pick a DateLocator based on the range of the x-axis."""
120  (x_lo, x_hi) = ax.get_xlim()
121  num_days = x_hi - x_lo
122  min_num_ticks = min(num_days, 5)
123  locator = matplotlib.dates.AutoDateLocator(minticks=min_num_ticks,
124  maxticks=None)
125  # End of GetLocator().
126  return locator
def create_public_peakpu_plots.PlotPeakPUAllYears (   lumi_data_by_fill_per_year)
Mode 1: years side-by-side

Definition at line 408 of file create_public_peakpu_plots.py.

References public_plots_tools.AddLogo(), public_plots_tools.SavePlot(), and TweakPlot().

409  def PlotPeakPUAllYears(lumi_data_by_fill_per_year):
410  """Mode 1: years side-by-side"""
411 
412  # Loop over all color schemes and plot.
413  for color_scheme_name in color_scheme_names:
414  print " color scheme '%s'" % color_scheme_name
415  color_scheme = ColorScheme(color_scheme_name)
416  color_by_year = color_scheme.color_by_year
417  logo_name = color_scheme.logo_name
418  file_suffix = color_scheme.file_suffix
419 
420  for type in ["lin", "log"]:
421  is_log = (type == "log")
422  aspect_ratio = matplotlib.figure.figaspect(1. / 2.5)
423  fig = plt.figure(figsize=aspect_ratio)
424  ax = fig.add_subplot(111)
425 
426  time_begin_ultimate = datetime.datetime.strptime(lumi_data_by_fill_per_year[years[0]][0][0],DATE_FMT_STR_LUMICALC).date()
427  str_begin_ultimate = time_begin_ultimate.strftime(DATE_FMT_STR_OUT)
428  for (year_index, year) in enumerate(years):
429 
430  lumi_data = lumi_data_by_fill_per_year[year]
431  times_tmp = [datetime.datetime.strptime(tmp,DATE_FMT_STR_LUMICALC).date() for tmp in lumi_data[0]]
432  times = [matplotlib.dates.date2num(i) for i in times_tmp] #x_axis
433  maxpus = lumi_data[1] # y_axis
434 
435  # NOTE: Special case for 2010.
436  label = None
437  if year == 2010 or year == 2011 :
438  label = r"%d, %s" % \
439  (year,r'7TeV $\sigma$=71.5mb')
440  else:
441  label = r"%d, %s" % \
442  (year,r'8TeV $\sigma$=73mb')
443  ax.plot(times,maxpus,
444  color=color_by_year[year],
445 # marker="none", linestyle="solid",
446  marker="o", linestyle='none',
447  linewidth=4,
448  label=label)
449  if is_log:
450  ax.set_yscale("log")
451 
452  time_begin = datetime.datetime(years[0], 1, 1, 0, 0, 0)
453  time_end = datetime.datetime(years[-1], 12, 16, 20, 50,9)
454  str_begin = time_begin.strftime(DATE_FMT_STR_OUT)
455  str_end = time_end.strftime(DATE_FMT_STR_OUT)
456 
457  num_cols = None
458  num_cols = len(years)
459  tmp_x = 0.095
460  tmp_y = .95
461 
462  leg = ax.legend(loc="upper left", bbox_to_anchor=(tmp_x, 0., 1., tmp_y),
463  frameon=False, ncol=num_cols)
464  for t in leg.get_texts():
465  t.set_font_properties(FONT_PROPS_TICK_LABEL)
466 
467  # Set titles and labels.
468  fig.suptitle(r"CMS peak interactions per crossing, %s" % particle_type_str,
469  fontproperties=FONT_PROPS_SUPTITLE)
470  ax.set_title("Data included from %s to %s UTC \n" % \
471  (str_begin_ultimate, str_end),
472  fontproperties=FONT_PROPS_TITLE)
473  ax.set_xlabel(r"Date (UTC)", fontproperties=FONT_PROPS_AX_TITLE)
474  ax.set_ylabel(r"Peak interactions per crossing",\
475  fontproperties=FONT_PROPS_AX_TITLE)
476 
477  # Add the logo.
478  #zoom = 1.7
479  zoom = .95
480  AddLogo(logo_name, ax, zoom=zoom)
481  extra_head_room = 0
482  if is_log:
483  #if mode == 1:
484  extra_head_room = 1
485  #elif mode == 2:
486  # extra_head_room = 2
487  TweakPlot(fig, ax, (time_begin, time_end),
488 # TweakPlot(fig, ax, (time_begin_ultimate, time_end),
489  add_extra_head_room=True)
490 
491  log_suffix = ""
492  if is_log:
493  log_suffix = "_log"
494  SavePlot(fig, "peak_pu_%s_%s%s" % \
495  (particle_type_str.lower(),
log_suffix, file_suffix))
def create_public_peakpu_plots.processdata (   years)

Definition at line 68 of file create_public_peakpu_plots.py.

References python.multivaluedict.append(), spr.find(), python.multivaluedict.map(), and split.

68 
69 def processdata(years):
70  results={}#{year:[[str,str],[pu,pu]]}
71  for y in years:
72  fills=[]#[fillnum]
73  maxputimelist=[]
74  maxpulist=[]
75  results[y]=[maxputimelist,maxpulist]
76  f=None
77  try:
78  lumifilename=str(y)+'lumibyls.csv'
79  f=open(lumifilename,'rb')
80  except IOError:
81  print 'failed to open file ',lumifilename
82  return result
83  freader=csv.reader(f,delimiter=',')
84  idx=0
85  for row in freader:
86  if idx==0:
87  idx=1
88  continue
89  if row[0].find('#')==1:
90  continue
91  [runnum,fillnum]=map(lambda i:int(i),row[0].split(':'))
92  avgpu=float(row[7])
93  if avgpu>50: continue
94  putime=row[2]
95  max_avgpu=avgpu
96  max_putime=putime
97  if fillnum not in fills:#new fill
98  fills.append(fillnum)
99  results[y][0].append(max_putime)
100  results[y][1].append(max_avgpu)
101  if avgpu>max_avgpu:
102  results[y][0][-1]=max_putime
103  results[y][1][-1]=max_avgpu
104  print results
105  return results
106 
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
double split
Definition: MVATrainer.cc:139
def create_public_peakpu_plots.TweakPlot (   fig,
  ax,
  time_begin,
  time_end,
  add_extra_head_room = False 
)

Definition at line 130 of file create_public_peakpu_plots.py.

References GetXLocator().

Referenced by GetXLocator(), and PlotPeakPUAllYears().

131  add_extra_head_room=False):
132 
133  # Fiddle with axes ranges etc.
134  ax.relim()
135  ax.autoscale_view(False, True, True)
136  for label in ax.get_xticklabels():
137  label.set_ha("right")
138  label.set_rotation(30.)
139 
140  # Bit of magic here: increase vertical scale by one tick to make
141  # room for the legend.
142  if add_extra_head_room:
143  y_ticks = ax.get_yticks()
144  (y_min, y_max) = ax.get_ylim()
145  is_log = (ax.get_yscale() == "log")
146  y_max_new = y_max
147  if is_log:
148  tmp = y_ticks[-1] / y_ticks[-2]
149  y_max_new = y_max * math.pow(tmp, add_extra_head_room)
150  else:
151  tmp = y_ticks[-1] - y_ticks[-2]
152  y_max_new = y_max + add_extra_head_room * tmp
153  ax.set_ylim(y_min, y_max_new)
154 
155  # Add a second vertical axis on the right-hand side.
156  ax_sec = ax.twinx()
157  ax_sec.set_ylim(ax.get_ylim())
158  ax_sec.set_yscale(ax.get_yscale())
159 
160  for ax_tmp in fig.axes:
161  for sub_ax in [ax_tmp.xaxis, ax_tmp.yaxis]:
162  for label in sub_ax.get_ticklabels():
163  label.set_font_properties(FONT_PROPS_TICK_LABEL)
164 
165  ax.set_xlim(time_begin, time_end)
166 
167  locator = GetXLocator(ax)
168  minorXlocator=matplotlib.ticker.AutoMinorLocator()
169  #ax.yaxis.set_major_locator(matplotlib.ticker.MultipleLocator(5))
170  #ax.yaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(5))
171  ax.xaxis.set_major_locator(locator)
172  ax.xaxis.set_minor_locator(minorXlocator)
173 
174  formatter = matplotlib.dates.DateFormatter(DATE_FMT_STR_AXES)
175  ax.xaxis.set_major_formatter(formatter)
176 
177  fig.subplots_adjust(top=.85, bottom=.14, left=.13, right=.91)
178  # End of TweakPlot().

Variable Documentation

string create_public_peakpu_plots.accel_mode = cfg_parser.get("general", "accel_mode")

Definition at line 225 of file create_public_peakpu_plots.py.

create_public_peakpu_plots.amodetag_bug_workaround = False

Definition at line 233 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.arg_parser = optparse.OptionParser(description=desc_str)

Definition at line 185 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.beam_energy = None

Definition at line 242 of file create_public_peakpu_plots.py.

dictionary create_public_peakpu_plots.beam_energy_defaults
Initial value:
1 = {
2  "PROTPHYS" : {2010 : 3500.,
3  2011 : 3500.,
4  2012 : 4000.,
5  2013 : 1380.1},
6  "IONPHYS" : {2010 : 3500.,
7  2011 : 3500.},
8  "PAPHYS" : {2013 : 4000.}
9  }

Definition at line 305 of file create_public_peakpu_plots.py.

create_public_peakpu_plots.beam_energy_from_cfg = None

Definition at line 243 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.beam_energy_tmp = cfg_parser.get("general", "beam_energy")

Definition at line 239 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.beam_fluctuation = None

Definition at line 255 of file create_public_peakpu_plots.py.

dictionary create_public_peakpu_plots.beam_fluctuation_defaults
Initial value:
1 = {
2  "PROTPHYS" : {2010 : .15,
3  2011 : .15,
4  2012 : .15,
5  2013 : .15},
6  "IONPHYS" : {2010 : .15,
7  2011 : .15},
8  "PAPHYS" : {2013 : .15}
9  }

Definition at line 314 of file create_public_peakpu_plots.py.

create_public_peakpu_plots.beam_fluctuation_from_cfg = None

Definition at line 256 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.beam_fluctuation_tmp = cfg_parser.get("general", "beam_fluctuation")

Definition at line 252 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.cache_file_dir = cfg_parser.get("general", "cache_dir")

Definition at line 218 of file create_public_peakpu_plots.py.

dictionary create_public_peakpu_plots.cfg_defaults
Initial value:
1 = {
2  "lumicalc_flags" : "",
3  "date_end" : None,
4  "color_schemes" : "Joe, Greg",
5  "beam_energy" : None,
6  "beam_fluctuation" : None,
7  "verbose" : False,
8  "oracle_connection" : None
9  }

Definition at line 198 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.cfg_parser = ConfigParser.SafeConfigParser(cfg_defaults)

Definition at line 207 of file create_public_peakpu_plots.py.

list create_public_peakpu_plots.color_scheme_names = [i.strip() for i in color_scheme_names_tmp.split(",")]

Definition at line 216 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.color_scheme_names_tmp = cfg_parser.get("general", "color_schemes")

Definition at line 215 of file create_public_peakpu_plots.py.

list create_public_peakpu_plots.config_file_name = args[0]

Definition at line 195 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.date_begin = datetime.datetime.strptime(tmp, DATE_FMT_STR_CFG)

Definition at line 267 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.date_end = None

Definition at line 269 of file create_public_peakpu_plots.py.

string create_public_peakpu_plots.DATE_FMT_STR_AXES = "%-d %b"

Definition at line 60 of file create_public_peakpu_plots.py.

string create_public_peakpu_plots.DATE_FMT_STR_CFG = "%Y-%m-%d"

Definition at line 61 of file create_public_peakpu_plots.py.

string create_public_peakpu_plots.DATE_FMT_STR_LUMICALC = "%m/%d/%y %H:%M:%S"

Definition at line 57 of file create_public_peakpu_plots.py.

string create_public_peakpu_plots.DATE_FMT_STR_LUMICALC_DAY = "%m/%d/%y"

Definition at line 58 of file create_public_peakpu_plots.py.

string create_public_peakpu_plots.DATE_FMT_STR_OUT = "%Y-%m-%d %H:%M"

Definition at line 59 of file create_public_peakpu_plots.py.

string create_public_peakpu_plots.desc_str = "test pu"

Definition at line 183 of file create_public_peakpu_plots.py.

string create_public_peakpu_plots.help = "Ignore all cached lumiCalc results "

Definition at line 187 of file create_public_peakpu_plots.py.

create_public_peakpu_plots.ignore_cache = options.ignore_cache

Definition at line 196 of file create_public_peakpu_plots.py.

list create_public_peakpu_plots.KNOWN_ACCEL_MODES
Initial value:
1 = ["PROTPHYS", "IONPHYS", "PAPHYS",
2  "2013_amode_bug_workaround"]

Definition at line 64 of file create_public_peakpu_plots.py.

int create_public_peakpu_plots.LEAD_SCALE_FACTOR = 82

Definition at line 66 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.lumi_data_by_fill_per_year = {}

Definition at line 381 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.lumicalc_flags_from_cfg = cfg_parser.get("general", "lumicalc_flags")

Definition at line 224 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.lumicalc_script = cfg_parser.get("general", "lumicalc_script")

Definition at line 223 of file create_public_peakpu_plots.py.

int create_public_peakpu_plots.NUM_SEC_IN_LS = 2

Definition at line 62 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.oracle_connection_string = cfg_parser.get("general", "oracle_connection")

Definition at line 291 of file create_public_peakpu_plots.py.

list create_public_peakpu_plots.particle_type_str = particle_type_strings[accel_mode]

Definition at line 303 of file create_public_peakpu_plots.py.

dictionary create_public_peakpu_plots.particle_type_strings
Initial value:
1 = {
2  "PROTPHYS" : "pp",
3  "IONPHYS" : "PbPb",
4  "PAPHYS" : "pPb"
5  }

Definition at line 298 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.path_name = CacheFilePath(cache_file_dir)

Definition at line 365 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.tmp = cfg_parser.get("general", "date_begin")

Definition at line 266 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.today = datetime.datetime.utcnow()

Definition at line 273 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.use_oracle = (len(oracle_connection_string) != 0)

Definition at line 292 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.verbose = cfg_parser.getboolean("general", "verbose")

Definition at line 220 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.year_begin = date_begin.isocalendar()

Definition at line 393 of file create_public_peakpu_plots.py.

tuple create_public_peakpu_plots.year_end = date_end.isocalendar()

Definition at line 394 of file create_public_peakpu_plots.py.

list create_public_peakpu_plots.years = [2010,2011,2012]

Definition at line 379 of file create_public_peakpu_plots.py.