### Es importante indicar (cuando proceda) que isdata = 0 para que se aplique la normalizacion treeMC = Sample.Tree(fileName=helper.selectSamples( WORKPATH + 'dat/Samples_cern.dat', Backgrounds, 'MC'), name='MC', isdata=0) treeSI = Sample.Tree(fileName=helper.selectSamples( WORKPATH + 'dat/Samples_cern.dat', Signals, 'SI'), name='SI', isdata=0) ############# DEFINICION DE CORTES ### Como ejemplo pongo algunos de los cortes basicos de los displaced global muon pais (DMDM) ### Hay algunos definidos en include/CutManager, pero desde aqui podeis definir los que querais ### La sintaxis es la que se utilizaria con el metodo .Draw de un TTree normal cuts = CutManager.CutManager() # Clase CutManager haveDMDM = cuts.brackets('nDMDMBase > 0') # Corte 1 lowPhi = cuts.brackets( 'fabs(DMDMBase_dPhi[DMDMBase_maxIxy])< 3.14/2.0') # Corte 2 allcuts = cuts.AddListB([haveDMDM, lowPhi]) # Combinamos ambos en un unico string ############# EJEMPLOS: ### --> Ejemplo de coger un TH1F con getTH1F(): ### Nombre del histograma: 'hBCK' (fondo con treeMC) y 'hSig' (senyal con treeSI) ### Normalizado a la lumi ### Variable que ploteamos: Distancia transversa del vertice del primer DMDM candidate ### En 20 bins, de 0 a 10 (nos pintara overflow tambien) ### options: Nunca lo uso ### xlabel: El label del eje x
hist_E_relPFIso = r.TH1F("hist_E_relPFIso", "", 50, 0, 1) hist_E_relPFIso_log = r.TH1F("hist_E_relPFIso_log", "", len(bin_iso_log) -1, bin_iso_log) hist_M_relPFIso = r.TH1F("hist_M_relPFIso", "", 50, 0, 1) hist_M_relPFIso_log = r.TH1F("hist_M_relPFIso_log", "", len(bin_iso_log) -1, bin_iso_log) ######################### #### Load sample #### ######################### treeBKG = Sample.Tree( fileName = helper.selectSamples(GALAPAGOPATH + 'dat/Samples_cern_UltraLegacy.dat', ['WW_postVFP', 'WZ_postVFP'], 'MC'), name = '2016', isdata = 0 ) ################################### #### Loop over tree events #### ################################### cm = CutManager.CutManager() for b in treeBKG.blocks: for s in b.samples: for t in s.ttrees: print('New tree with:', t.GetEntries()) for e,ev in enumerate(t): if e > 500000: break #if not eval(cm.epath2016): continue # Count number of hard process leptons: hasLepton = False for j in range(0, ev.nHardProcessParticle):
def __init__(self, outdir, treename, blockname, samplename, samplenumber, lumiweight, isdata, year = '2016'): ### outdir: Path where the root file will be stored ### treename: Name of the (Galapago) Tree (MC; DATA; SI) ### blockname: Name of the (Galapago) Block ### samplename: Name of the sample ### samplenumber: Number of the sample file/ttree self.outdir = outdir if self.outdir[-1] != '/': self.outdir = self.outdir + '/' self.filename = self.outdir + '{0}__{1}__{2}__{3}.root'.format(treename, blockname, samplename, str(samplenumber)) self.treename = treename self.blockname = blockname self.samplename = samplename self.samplenumber = samplenumber self.lumiweight = lumiweight self.isdata = isdata self.year = year self.cm = CutManager.CutManager() self.sufix = '__{0}__{1}__{2}__{3}'.format(treename, blockname, samplename, str(samplenumber)) ## Init histogram efficiencies self.declareEfficiencies() #### ------------------------------ #### ---- Set year configuration #### ------------------------------ self.mumu_path = 'False' self.mumu_selection = 'False' self.ee_path = 'False' self.ee_selection = 'False' if year=='2016': self.mumu_path = self.cm.mupath2016 self.ee_path = self.cm.epath2016 self.mumu_selection = self.cm.MM_BS2016 self.ee_selection = self.cm.EE_BS2016 elif year=='2017': self.ee_path = self.cm.epath2017 self.ee_selection = self.cm.EE_BS2017 elif year=='2018': self.mumu_path = self.cm.mupath2018 self.ee_path = self.cm.epath2018 self.mumu_selection = self.cm.MM_BS2018 self.ee_selection = self.cm.EE_BS2018 #### ------------------------------ #### ---- Regions initialization #### ------------------------------ self.dielectronRegions = [] # region name : region cut self.declareDielectronRegions() self.dimuonRegions = [] # region name : region cut self.declareDimuonRegions() #### ------------------------------- #### ---- Histogram initialization #### ------------------------------- self.hEE_yield = r.TH1F('hEE_yield' + self.sufix, ';Passed photon trigger;', 1, 0, 1) self.hEE_nBSEE = {} self.hEE_nPU = {} self.hEE_dPhi = {} self.hEE_dPhi_inv = {} self.hEE_mass = {} self.hEE_cosAlpha = {} self.hEE_trackIxy = {} self.hEE_trackIxy_log = {} self.hEE_trackDxy = {} self.hEE_sigmaD = {} self.hEE_Lxy = {} self.hEE_Ixy = {} self.hEE_leadingEt = {} self.hEE_subleadingEt = {} self.hEE_normalizedChi2 = {} self.hEE_vx_vy = {} for region in self.dielectronRegions: region_name = region[0] self.declareDielectronHistograms(region_name) self.hMM_yield = r.TH1F('hMM_yield' + self.sufix, ';Passed muon trigger;', 1, 0, 1) self.hMM_nBSMM = {} self.hMM_nPU = {} self.hMM_dPhi = {} self.hMM_dPhi_inv = {} self.hMM_mass = {} self.hMM_cosAlpha = {} self.hMM_trackIxy = {} self.hMM_trackIxy_log = {} self.hMM_trackDxy = {} self.hMM_sigmaD = {} self.hMM_Lxy = {} self.hMM_Ixy = {} self.hMM_leadingPt = {} self.hMM_subleadingPt = {} self.hMM_normalizedChi2 = {} self.hMM_vx_vy = {} for region in self.dimuonRegions: region_name = region[0] self.declareDimuonHistograms(region_name) #### -------------------------------- #### ---- Apply sumw2 to histograms #### -------------------------------- for attr, value in self.__dict__.items(): if attr[0] == 'h': if type(value) == dict: for key in value.keys(): value[key].Sumw2() else: value.Sumw2()
treeEGDATA = Sample.Tree(fileName=helper.selectSamples( WORKPATH + filename, DoubleEG, 'DATA'), name='DATA', isdata=1) treeMuonDATA = Sample.Tree(fileName=helper.selectSamples( WORKPATH + filename, DoubleMuon, 'DATA'), name='DATA', isdata=1) treeMC = Sample.Tree(fileName=helper.selectSamples(WORKPATH + filename, Backgrounds, 'MC'), name='MC', isdata=0) ############# Cut definition cuts = CutManager.CutManager() EESR = cuts.AddListB( [cuts.nTrack, cuts.EEChannel, cuts.haveEEBase, cuts.EESR_dPhi]) EECR = cuts.AddListB( [cuts.nTrack, cuts.EEChannel, cuts.haveEEBase, cuts.EECR_dPhi]) MMSR = cuts.AddListB([ cuts.nTrack, cuts.MMChannel, cuts.haveMM, cuts.MMSR_dPhi, cuts.cosmicRejection ]) MMCR = cuts.AddListB([ cuts.nTrack, cuts.MMChannel, cuts.haveMM, cuts.MMCR_dPhi, cuts.cosmicRejection ]) ############# Plotting start_time = time.time()