Ejemplo n.º 1
0
 def __init__(self, filename=None, data=False, debug=False):
     setPlotStyle()
     self.commandLine = CommandLineHandler('[' + self.__class__.__name__ +
                                           ']')
     self.key = 'L1MuonPresent' if data else 'L1MuonTruth'
     self.data = data
     self.DEBUG = debug
     self.filename = filename
     if self.DEBUG:
         self.debug("Creating plot module %s" % self.__class__.__name__)
     if filename != None:
         self.fileHandler = self.createFileHandler(filename)
     pass
Ejemplo n.º 2
0
	def __init__(self,filename = None,data = False, debug = False):
		setPlotStyle()
		self.commandLine = CommandLineHandler('[' + self.__class__.__name__ + ']')
		self.key = 'L1MuonPresent' if data else 'L1MuonTruth'
		self.data = data
		self.DEBUG = debug
		if filename != None:
			self.fileHandler = self.createFileHandler(filename)
		pass
Ejemplo n.º 3
0
	def __init__(self,filename,debug,data = False):
		self.commandLine = CommandLineHandler('[TimeWindow] ')
		self.fileHandler = RootFileHandler(filename)
		self.fileHandler.printStatus()
		if( not os.path.exists('plots')):
			os.mkdir('plots')
		if( not os.path.exists('plots/efficiencyWithTime')):
			os.mkdir('plots/efficiencyWithTime')
		setPlotStyle()
		self.data = data
Ejemplo n.º 4
0
class Plot:
	def __init__(self,filename = None,data = False, debug = False):
		setPlotStyle()
		self.commandLine = CommandLineHandler('[' + self.__class__.__name__ + '] ')
		self.key = 'L1MuonPresent' if data else 'L1MuonTruth'
		self.data = data
		self.DEBUG = debug
		if filename != None:
			self.fileHandler = self.createFileHandler(filename)
		pass
	
	def createFileHandler(self,filename):
		fh = RootFileHandler(filename)
		fh.printStatus()
		return fh
	
	def createPlotSubdir(self,subdirname):
		if( not os.path.exists('plots')):
			os.mkdir('plots')
		if( not os.path.exists('plots/' + subdirname)):
			os.mkdir('plots/' + subdirname)
		self.plotSubdir = 'plots/' + subdirname
		return
	
	#Save a canvas as gif file with the source data file name attached
	def storeCanvas(self,canvas,plotname):
		if(plotname.find('/') != -1):
			if( not os.path.exists(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])):
				os.makedirs(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])
				
		canvas.SaveAs('%s/%s_%s.gif'%(self.plotSubdir,plotname,self.fileHandler.filename))
		canvas.SaveAs('%s/%s_%s.png'%(self.plotSubdir,plotname,self.fileHandler.filename))
		return
	
	def drawLabel(self):
		label = None
		if self.data:
			label = drawLabelCmsPrivateData()
		else:
			label = drawLabelCmsPrivateSimulation()
		return label
	
	def debug(self,string):
		self.commandLine.debug(string)
	
	def warning(self,string):
		self.commandLine.warning(string)
		
	def error(self,string):
		self.commandLine.error(string)
		
	def output(self,string):
		self.commandLine.output(string)
Ejemplo n.º 5
0
class Plot:
	def __init__(self,filename = None,data = False, debug = False):
		setPlotStyle()
		self.commandLine = CommandLineHandler('[' + self.__class__.__name__ + ']')
		self.key = 'L1MuonPresent' if data else 'L1MuonTruth'
		self.data = data
		self.DEBUG = debug
		self.filename = filename
		if self.DEBUG:
			self.debug("Creating plot module %s" % self.__class__.__name__)
		if filename != None:
			self.fileHandler = self.createFileHandler(filename)
		pass
	
	def setModuleName(self,moduleName):
		self.fileHandler.setModuleName(moduleName)
	
	def createFileHandler(self,filename):
		fh = RootFileHandler(filename,debug=self.DEBUG)
		fh.printStatus()
		return fh
	
	def getGitCommitHash(self):
		cmd = shlex.split("git show --abbrev-commit")
		process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		gitOutput,err = process.communicate()
		gch = 'None'
		firstLine = gitOutput.split('\n')[0]
		if firstLine.find('commit') != -1:
			gch = firstLine.split(' ')[-1]
		return gch
	
	def createPlotSubdir(self,subdirname):
		if( not os.path.exists('plots')):
			if self.DEBUG:
				self.debug('Creating dir plots')
			os.mkdir('plots')
		gitCommitHash = self.getGitCommitHash()
		if( not os.path.exists('plots/' + gitCommitHash)):
			if self.DEBUG: self.debug('Creating dir plots/' + gitCommitHash)
			os.mkdir('plots/' + gitCommitHash)
		if( not os.path.exists('plots/' + gitCommitHash + '/' + subdirname)):
			if self.DEBUG: self.debug('Creating dir plots/' + gitCommitHash + '/' + subdirname)
			os.mkdir('plots/' + gitCommitHash + '/' + subdirname)
		self.plotSubdir = 'plots/' + gitCommitHash + '/' + subdirname
		return
	
	#Save a canvas as gif file with the source data file name attached
	def storeCanvas(self,canvas,plotname,drawMark = True, drawLabel = True, markPosition = None, labelPosition = None,
				marginRight=0.1, marginLeft=0.1,marginTop=.05):
		# Do the following to overcome the late binding in python which evaluates
		# the default objects only once and persists the information
		if markPosition == None:
			markPosition = {'x1ndc' : marginLeft - 0.007, 'y1ndc' : 0.95, 'x2ndc' : marginLeft + 0.226, 'y2ndc' : 0.99}
			
		if labelPosition == None:
			labelPosition = {'x1ndc' : .7 - marginRight, 'y1ndc' : 0.95, 'x2ndc' : 1 - marginRight, 'y2ndc' : 0.98}
		
		if(plotname.find('/') != -1):
			if( not os.path.exists(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])):
				os.makedirs(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])
				
		canvas.cd().SetTopMargin(marginTop)
		canvas.cd().SetRightMargin(marginRight)
		canvas.cd().SetLeftMargin(marginLeft)

		if drawMark:
			mark = drawWaterMark(markPosition = markPosition)
		if drawLabel:		
			label = self.drawLabel(labelPosition = labelPosition)
		
		canvas.Update()
		canvas.SaveAs('%s/%s_%s.gif'%(self.plotSubdir,plotname,self.fileHandler.filename))
		canvas.SaveAs('%s/%s_%s.png'%(self.plotSubdir,plotname,self.fileHandler.filename))
		canvas.SaveAs('%s/%s_%s.pdf'%(self.plotSubdir,plotname,self.fileHandler.filename))
				
		return
	
	def drawLabel(self,labelPosition = {'x1ndc' : 0.6, 'y1ndc' : 0.95, 'x2ndc' : 0.9, 'y2ndc' : 0.98}):
		if self.data:
			label = drawLabelCmsPrivateData(labelPosition['x1ndc'],labelPosition['y1ndc'],labelPosition['x2ndc'],labelPosition['y2ndc'])
		else:
			label = drawLabelCmsPrivateSimulation(labelPosition['x1ndc'],labelPosition['y1ndc'],labelPosition['x2ndc'],labelPosition['y2ndc'])
		return label
	
	def debug(self,string):
		self.commandLine.debug(string)
	
	def warning(self,string):
		self.commandLine.warning(string)
		
	def error(self,string):
		self.commandLine.error(string)
		
	def output(self,string):
		self.commandLine.output(CliColors.BOLD + '<' + inspect.stack()[1][3] + '>  ' + CliColors.ENDC + str(string))
		
	def printProgress(self,done,total,updateEvery = 1000):
		if done == total or not (done % updateEvery):
			self.commandLine.printProgress(done, total)
Ejemplo n.º 6
0
'''

cmsswSourceFiles = 'cmsswSourceFiles'
outputFileTrunk = 'sourceList'

globalTags = {
			'noPu':'autoCond[\'run2_mc\']',
			'pu':'autoCond[\'run2_mc\']',
			'design':'autoCond[\'run2_design\']',
			'data':'autoCond[\'run2_data\']'
			}

print 

cli = CommandLineHandler('[runParallel] ')

global configTemplate
configTemplate = os.environ['HOMUONTRIGGER_BASE'] + '/python/runConfig_template.py'
	
parser = argparse.ArgumentParser()

parser.add_argument('--nJobs','-n'
					,dest='nJobs'
					,type=int
					,help='Create N jobs')

parser.add_argument('--test'
					,dest='test'
					,action="store_true",default=False
					,help='Only submit one job for testing')
Ejemplo n.º 7
0
import sys
from ROOT import TCanvas, TLegend, THStack, TLegend
from plotting.RootFileHandler import RootFileHandler
from plotting.PlotStyle import setupAxes,setPlotStyle, colorRwthDarkBlue,\
 drawLabelCmsPrivateSimulation, colorRwthLightBlue, colorRwthGruen,\
 colorRwthTuerkis, colorRwthRot, colorRwthMagenta, setupPalette
from plotting.OutputModule import CommandLineHandler, CliColors
fileHandler = RootFileHandler(sys.argv[1])

setPlotStyle()
cli = CommandLineHandler('[QualityCodes] ')

qualityCodeDict = {
    1: 'Halo Muon',
    2: 'Very low qual. Type 1',
    3: 'Very low qual. Type 2',
    4: 'Very low qual. Type 3',
    5: 'unmatched RPC',
    6: 'unmatched DT or CSC',
    7: 'matched DT-RPC or CSC-RPC'
}

gridSizeDict = {0: 'Central', 1: '3x3', 2: '5x5'}


def plotQualityCodes():
    c = TCanvas('cQualityCodes')
    c.SetLogy()
    qualityCodes = fileHandler.getHistogram(
        'multiplicity/L1MuonQualityCodesCentral_Multiplicity')
    qualityCodesFail = fileHandler.getHistogram(
Ejemplo n.º 8
0
class Plot:
	def __init__(self,filename = None,data = False, debug = False):
		setPlotStyle()
		self.commandLine = CommandLineHandler('[' + self.__class__.__name__ + ']')
		self.key = 'L1MuonPresent' if data else 'L1MuonTruth'
		self.data = data
		self.DEBUG = debug
		if filename != None:
			self.fileHandler = self.createFileHandler(filename)
		pass
	
	def createFileHandler(self,filename):
		fh = RootFileHandler(filename)
		fh.printStatus()
		return fh
	
	def getGitCommitHash(self):
		cmd = shlex.split("git show --abbrev-commit")
		process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		gitOutput,err = process.communicate()
		gch = 'None'
		firstLine = gitOutput.split('\n')[0]
		if firstLine.find('commit') != -1:
			gch = firstLine.split(' ')[-1]
		return gch
	
	def createPlotSubdir(self,subdirname):
		if( not os.path.exists('plots')):
			self.debug('Creating dir plots')
			os.mkdir('plots')
		gitCommitHash = self.getGitCommitHash()
		if( not os.path.exists('plots/' + gitCommitHash)):
			self.debug('Creating dir plots/' + gitCommitHash)
			os.mkdir('plots/' + gitCommitHash)
		if( not os.path.exists('plots/' + gitCommitHash + '/' + subdirname)):
			self.debug('Creating dir plots/' + gitCommitHash + '/' + subdirname)
			os.mkdir('plots/' + gitCommitHash + '/' + subdirname)
		self.plotSubdir = 'plots/' + gitCommitHash + '/' + subdirname
		return
	
	#Save a canvas as gif file with the source data file name attached
	def storeCanvas(self,canvas,plotname):
		if(plotname.find('/') != -1):
			if( not os.path.exists(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])):
				os.makedirs(self.plotSubdir + '/' + plotname[0:plotname.rfind('/')])
				
		canvas.SaveAs('%s/%s_%s.gif'%(self.plotSubdir,plotname,self.fileHandler.filename))
		canvas.SaveAs('%s/%s_%s.png'%(self.plotSubdir,plotname,self.fileHandler.filename))
		return
	
	def drawLabel(self):
		label = None
		if self.data:
			label = drawLabelCmsPrivateData()
		else:
			label = drawLabelCmsPrivateSimulation()
		return label
	
	def debug(self,string):
		self.commandLine.debug(string)
	
	def warning(self,string):
		self.commandLine.warning(string)
		
	def error(self,string):
		self.commandLine.error(string)
		
	def output(self,string):
		self.commandLine.output(CliColors.BOLD + '<' + inspect.stack()[1][3] + '>  ' + CliColors.ENDC + str(string))
Ejemplo n.º 9
0
from matchingLibrary import calculateDeltaEta, calculateDeltaPhi
from numpy import math
from plotting.OutputModule import CommandLineHandler
from ROOT import gROOT
HO_BIN = math.pi / 36.
E_THR = 0.2

commandLine = CommandLineHandler('[HoMatcher] ')
gROOT.ProcessLine(".L $HOMUONTRIGGER_BASE/python/loader.C+")

from ROOT import HoRecHitData, L1MuonData


def isEtaPhiInGrid(l1Eta, l1Phi, hoEta, hoPhi, gridSize):
    deltaEta = calculateDeltaEta(l1Eta, hoEta)
    deltaPhi = calculateDeltaPhi(l1Phi, hoPhi)

    deltaIEta = 0
    deltaIPhi = 0

    if (deltaEta > HO_BIN / 2.):
        deltaIEta = 1 + int((deltaEta - HO_BIN / 2.) / HO_BIN)
    elif (deltaEta < -HO_BIN / 2.):
        deltaIEta = -1 + int((deltaEta + HO_BIN / 2.) / HO_BIN)

    if (deltaPhi > HO_BIN / 2.):
        deltaIPhi = 1 + int((deltaPhi - HO_BIN / 2.) / HO_BIN)
    elif (deltaPhi < -HO_BIN / 2.):
        deltaIPhi = -1 + int((deltaPhi + HO_BIN / 2.) / HO_BIN)

    if abs(deltaIEta) > gridSize or abs(deltaIPhi) > gridSize:
Ejemplo n.º 10
0
#!/bin/env python
import os
from ROOT import TChain,TFile,SetOwnership,Double
from plotting.OutputModule import CommandLineHandler

commandLine = CommandLineHandler('[RootFileHandler] ')

class RootFileHandler:
	#Look, how many files with the given name trunk in filename exist in the directory
	def getNumberOfFiles(self):
		fileCounter = 0
		self.fileNameList = []
		#cut away file extension
		if self.filename.rfind('.root') != -1:
			self.filename = self.filename[:-5]
		commandLine.debug(self.filepath)
		commandLine.debug(self.filename)
		for f in os.listdir(self.filepath):
			if f.find(self.filename) == 0:
				fileCounter += 1
				self.fileNameList.append(f)
		self.numberOfFiles = fileCounter
		pass
	
	#Initialize object
	def __init__(self,filename,debug = False):
		self.DEBUG = debug
		if filename[0] == '/':
			self.filepath = ''
		else:
			self.filepath = './'
Ejemplo n.º 11
0
import subprocess 
import json
import sys

from plotting.OutputModule import CommandLineHandler

cli = CommandLineHandler('[getFilesFromLumiJson] ')

jsonFile = sys.argv[1]
dataset = sys.argv[2]

inputJson = json.load(open(jsonFile))
output = file('files%s' % (dataset.replace('/','_')),'w+')

cli.output('Searching files for dataset')

for i,key in enumerate(inputJson.keys()):
	cmd = 'das_client.py --query=\"file dataset=%s run=%s\"' % (dataset,key)
	p = subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
	res,err = p.communicate()
	for line in res.split():
		if line.find('.root') == -1:
			pass
		else:
			output.write('root://xrootd.unl.edu/' + line + '\n')
			print line
	cli.printProgress(i+1,len(inputJson.keys()))
print
Ejemplo n.º 12
0
'''

cmsswSourceFiles = 'cmsswSourceFiles'
outputFileTrunk = 'sourceList'

globalTags = {
    'noPu': 'autoCond[\'run2_mc\']',
    'pu': 'autoCond[\'run2_mc\']',
    'design': 'autoCond[\'run2_design\']',
    'data': 'autoCond[\'run2_data\']'
}

print

cli = CommandLineHandler('[runParallel] ')

global configTemplate
configTemplate = os.environ[
    'HOMUONTRIGGER_BASE'] + '/python/runConfig_template.py'

parser = argparse.ArgumentParser()

parser.add_argument('--nJobs',
                    '-n',
                    dest='nJobs',
                    type=int,
                    help='Create N jobs')

parser.add_argument('--test',
                    dest='test',
Ejemplo n.º 13
0
class Plot:
    def __init__(self, filename=None, data=False, debug=False):
        setPlotStyle()
        self.commandLine = CommandLineHandler('[' + self.__class__.__name__ +
                                              ']')
        self.key = 'L1MuonPresent' if data else 'L1MuonTruth'
        self.data = data
        self.DEBUG = debug
        self.filename = filename
        if self.DEBUG:
            self.debug("Creating plot module %s" % self.__class__.__name__)
        if filename != None:
            self.fileHandler = self.createFileHandler(filename)
        pass

    def setModuleName(self, moduleName):
        self.fileHandler.setModuleName(moduleName)

    def createFileHandler(self, filename):
        fh = RootFileHandler(filename, debug=self.DEBUG)
        fh.printStatus()
        return fh

    def getGitCommitHash(self):
        cmd = shlex.split("git show --abbrev-commit")
        process = subprocess.Popen(cmd,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        gitOutput, err = process.communicate()
        gch = 'None'
        firstLine = gitOutput.split('\n')[0]
        if firstLine.find('commit') != -1:
            gch = firstLine.split(' ')[-1]
        return gch

    def createPlotSubdir(self, subdirname):
        if (not os.path.exists('plots')):
            if self.DEBUG:
                self.debug('Creating dir plots')
            os.mkdir('plots')
        gitCommitHash = self.getGitCommitHash()
        if (not os.path.exists('plots/' + gitCommitHash)):
            if self.DEBUG: self.debug('Creating dir plots/' + gitCommitHash)
            os.mkdir('plots/' + gitCommitHash)
        if (not os.path.exists('plots/' + gitCommitHash + '/' + subdirname)):
            if self.DEBUG:
                self.debug('Creating dir plots/' + gitCommitHash + '/' +
                           subdirname)
            os.mkdir('plots/' + gitCommitHash + '/' + subdirname)
        self.plotSubdir = 'plots/' + gitCommitHash + '/' + subdirname
        return

    #Save a canvas as gif file with the source data file name attached
    def storeCanvas(self,
                    canvas,
                    plotname,
                    drawMark=True,
                    markPosition={
                        'x1ndc': 0.093,
                        'y1ndc': 0.898,
                        'x2ndc': 0.319,
                        'y2ndc': 0.940
                    }):
        if (plotname.find('/') != -1):
            if (not os.path.exists(self.plotSubdir + '/' +
                                   plotname[0:plotname.rfind('/')])):
                os.makedirs(self.plotSubdir + '/' +
                            plotname[0:plotname.rfind('/')])

        canvas.cd()

        if drawMark:
            mark = drawWaterMark(markPosition=markPosition)

        canvas.Update()
        canvas.SaveAs('%s/%s_%s.gif' %
                      (self.plotSubdir, plotname, self.fileHandler.filename))
        canvas.SaveAs('%s/%s_%s.png' %
                      (self.plotSubdir, plotname, self.fileHandler.filename))
        return

    def drawLabel(self, x1ndc=0.6, y1ndc=0.90, x2ndc=0.9, y2ndc=0.93):
        label = None
        if self.data:
            label = drawLabelCmsPrivateData(x1ndc, y1ndc, x2ndc, y2ndc)
        else:
            label = drawLabelCmsPrivateSimulation(x1ndc, y1ndc, x2ndc, y2ndc)
        return label

    def debug(self, string):
        self.commandLine.debug(string)

    def warning(self, string):
        self.commandLine.warning(string)

    def error(self, string):
        self.commandLine.error(string)

    def output(self, string):
        self.commandLine.output(CliColors.BOLD + '<' + inspect.stack()[1][3] +
                                '>  ' + CliColors.ENDC + str(string))

    def printProgress(self, done, total, updateEvery=1000):
        if done == total or not (done % updateEvery):
            self.commandLine.printProgress(done, total)
Ejemplo n.º 14
0
#!/usr/bin/python
from plotting.OutputModule import CommandLineHandler
import sys, os
from plotting.RootFileHandler import RootFileHandler
from ROOT import TH1D, TCanvas, gROOT, TH2D
from OfflineAnalysis.matchingLibrary import calculateDeltaPhi, getDeltaEtaList, getDeltaPhiList
from OfflineAnalysis.HoMatcher import isHoHitInGrid, getEMaxHoHitInGrid, HO_BIN, getEMaxMatches
from plotting.Utils import comparePythonAndRoot2DHist, compareTwoRoot2DHists
import matplotlib
from matplotlib.colors import LogNorm

commandLine = CommandLineHandler('[makeDataTreeAnalysis] ')

import matplotlib.pyplot as plt
import numpy as np
import math

if len(sys.argv) < 2:
    print 'First argument has to be the file name scheme!'

if (not os.path.exists('plots')):
    os.mkdir('plots')
if (not os.path.exists('plots/dataTreeAnalysis')):
    os.mkdir('plots/dataTreeAnalysis')

gROOT.ProcessLine(".L $HOMUONTRIGGER_BASE/python/loader.C+")

fileHandler = RootFileHandler(sys.argv[1])
dataChain = fileHandler.getTChain()
nEvents = dataChain.GetEntries()