Exemple #1
0
	def __init__(self,size):
		""" The initializator of Particle1D representation,
		size parameter must be specified """
		ParticleBase.__init__(self)
		self.position = []
		self.ownBestPosition = []
		self.velocity = []
		self.dimmensionsSize = size
		self.position_initializator.set(Consts.CDefP1DPosListInit)
		self.velocity_initializator.set(Consts.CDefP1DVelListInit)
		self.position_communicator.set(Consts.P1DPosCommunicator)
		self.information_communicator.set(Consts.P1DInfoCommunicator)
Exemple #2
0
    def __init__(self, size):
        """ The initializator of Particle1D representation,
		size parameter must be specified """
        ParticleBase.__init__(self)
        self.position = []
        self.ownBestPosition = []
        self.velocity = []
        self.dimmensionsSize = size
        self.position_initializator.set(Consts.CDefP1DPosListInit)
        self.velocity_initializator.set(Consts.CDefP1DVelListInit)
        self.position_communicator.set(Consts.P1DPosCommunicator)
        self.information_communicator.set(Consts.P1DInfoCommunicator)
Exemple #3
0
	def copy(self, g):
		"""Copy particle to 'g''
		Example:
			>>> particle_origin.copy(particle_destination)
		
		:param g: the destination Particle1D instance
		
		"""
		ParticleBase.copy(self,g)
		g.dimmensionsSize = self.dimmensionsSize
		g.velocity = self.velocity[:]
		g.position = self.position[:]
		g.ownBestPosition = self.ownBestPosition[:]
Exemple #4
0
    def copy(self, g):
        """Copy particle to 'g''
		Example:
			>>> particle_origin.copy(particle_destination)
		
		:param g: the destination Particle1D instance
		
		"""
        ParticleBase.copy(self, g)
        g.dimmensionsSize = self.dimmensionsSize
        g.velocity = self.velocity[:]
        g.position = self.position[:]
        g.ownBestPosition = self.ownBestPosition[:]
Exemple #5
0
	def __repr__(self):
		""""Return a string representation of the Particle """
		ret = ParticleBase.__repr__(self)
		ret += "-Particle1D\n"
		ret += "\tDimmensions size:\t %s\n" % (self.dimmensionsSize,)
		#ret += "\tPosition:\t\t %s\n\n" %(self.position,)
		ret += "\tBestPosition:\t\t %s\n\n" %(self.ownBestPosition,)
		return ret
Exemple #6
0
 def __repr__(self):
     """"Return a string representation of the Particle """
     ret = ParticleBase.__repr__(self)
     ret += "-Particle1D\n"
     ret += "\tDimmensions size:\t %s\n" % (self.dimmensionsSize, )
     #ret += "\tPosition:\t\t %s\n\n" %(self.position,)
     ret += "\tBestPosition:\t\t %s\n\n" % (self.ownBestPosition, )
     return ret
  def exec_event(self):

    # calculate nvetex info
    nvtx_prim = 0
    nvtx_pile = 0
    for i in range(0,self.ch.vxp_n):
      if   self.ch.vxp_type[i]==1 and self.ch.vxp_nTracks[i]>=4: nvtx_prim+=1
      elif self.ch.vxp_type[i]==3 and self.ch.vxp_nTracks[i]>=2: nvtx_pile+=1


    # Select Taus 
    taus  = self.tau_selector.select()

    for tau in taus:
      self.resetBranches()
      
      # set the event properties agains, since we clear for each tau
      self.setBranch( 'averageIntPerXing', self.ch.averageIntPerXing )
      self.setBranch( 'actualIntPerXing',  self.ch.actualIntPerXing )
      self.setBranch( 'NPrimaryVtx',       nvtx_prim )
      self.setBranch( 'NPileupVtx',        nvtx_pile )
      
      index = tau.index
      # Writeout Variables 
      self.setBranch( 'tau_pt', self.ch.tau_pt[index] )
      self.setBranch( 'tau_m', self.ch.tau_m[index] )
      self.setBranch( 'tau_eta', self.ch.tau_eta[index] )
      self.setBranch( 'tau_phi', self.ch.tau_phi[index] )
      self.setBranch( 'tau_charge', self.ch.tau_charge[index] )
      self.setBranch( 'tau_BDTEleScore', self.ch.tau_BDTEleScore[index] )
      self.setBranch( 'tau_BDTJetScore', self.ch.tau_BDTJetScore[index] )
      self.setBranch( 'tau_likelihood', self.ch.tau_likelihood[index] )
      self.setBranch( 'tau_electronVetoLoose', self.ch.tau_electronVetoLoose[index] )
      self.setBranch( 'tau_electronVetoMedium', self.ch.tau_electronVetoMedium[index] )
      self.setBranch( 'tau_electronVetoTight', self.ch.tau_electronVetoTight[index] )
      self.setBranch( 'tau_muonVeto', self.ch.tau_muonVeto[index] )
      self.setBranch( 'tau_tauCutLoose', self.ch.tau_tauCutLoose[index] )
      self.setBranch( 'tau_tauCutMedium', self.ch.tau_tauCutMedium[index] )
      self.setBranch( 'tau_tauCutTight', self.ch.tau_tauCutTight[index] )
      self.setBranch( 'tau_tauLlhLoose', self.ch.tau_tauLlhLoose[index] )
      self.setBranch( 'tau_tauLlhMedium', self.ch.tau_tauLlhMedium[index] )
      self.setBranch( 'tau_tauLlhTight', self.ch.tau_tauLlhTight[index] )
      self.setBranch( 'tau_JetBDTSigLoose', self.ch.tau_JetBDTSigLoose[index] )
      self.setBranch( 'tau_JetBDTSigMedium', self.ch.tau_JetBDTSigMedium[index] )
      self.setBranch( 'tau_JetBDTSigTight', self.ch.tau_JetBDTSigTight[index] )
      self.setBranch( 'tau_EleBDTLoose', self.ch.tau_EleBDTLoose[index] )
      self.setBranch( 'tau_EleBDTMedium', self.ch.tau_EleBDTMedium[index] )
      self.setBranch( 'tau_EleBDTTight', self.ch.tau_EleBDTTight[index] )
      self.setBranch( 'tau_author', self.ch.tau_author[index] )
      self.setBranch( 'tau_numTrack', self.ch.tau_numTrack[index] )

      # do trigger matching
      for trigger in self.triggers:
       
        # check trigger configured
        if not hasattr( self.ch, trigger): continue

        # get event decision
        passed_event = getattr(self.ch,trigger)
        if not passed_event: continue
        self.setBranch( trigger, 1 )

        # get trigger match  --> maybe make a common function to construct trigger containers
        if not hasattr(self.ch,'trig_EF_tau_%s'%trigger):
          print 'WARNING trying to access branch that doesnt exist: ', self.ch,'trig_EF_tau_%s'%trigger
          continue
        trigger_objects = getattr(self.ch,'trig_EF_tau_%s'%trigger)
        matched = 0
        for i in range(0,self.ch.trig_EF_tau_n):
          if not trigger_objects[i]: continue
          eftau = ParticleBase( i, 
              _pt = self.ch.trig_EF_tau_pt[i],
              _eta = self.ch.trig_EF_tau_eta[i],
              _phi = self.ch.trig_EF_tau_phi[i],
              _m = self.ch.trig_EF_tau_m[i]
              )
          if eftau.DeltaR(tau)>self.max_dr: continue
          matched = 1
          break
        self.setBranch( '%s_match'%trigger, matched )

      # do trigger matching for emulated 1 triggers
      for basename in self.emulated_1trigger_basenames:
       
        # check trigger configured
        if not hasattr( self.ch, basename): continue

        indicies = self.getIndiciesPassedEmulated1Trigger( basename )
        if len(indicies)<=0: continue
        self.setBranch( '%s1'%basename, 1 )

        # get trigger match  --> maybe make a common function to construct trigger containers
        matched = 0
        for i in range(0,len(indicies)):
          trig_index = indicies[i]
          eftau = ParticleBase( trig_index, 
              _pt = self.ch.trig_EF_tau_pt[trig_index],
              _eta = self.ch.trig_EF_tau_eta[trig_index],
              _phi = self.ch.trig_EF_tau_phi[trig_index],
              _m = self.ch.trig_EF_tau_m[trig_index]
              )
          if eftau.DeltaR(tau)>self.max_dr: continue
          matched = 1
          break
        self.setBranch( '%s1_match'%basename, matched )

       
  

      self.fill()
Exemple #8
0
    def select(self):
        self.clear_particles()

        # require TTree to be loaded
        if not self.ch:
            print 'ElectronSelector. Warning! No input TTree'
            return

        # Loop over taus and select candidates
        for i in range(0, self.ch.el_n):
            et = self.ch.el_cl_E[i] / cosh(self.ch.el_tracketa[i])
            eta = self.ch.el_tracketa[i]
            phi = self.ch.el_trackphi[i]
            p = ParticleBase(
                _index=i,
                _pt=et,
                _eta=eta,
                _phi=phi,
                _m=0.,
            )

            if p.Pt() < self.min_pt: continue
            if abs(p.Eta()) > self.max_eta: continue

            #crack region
            for region in self.excluded_eta_regions:
                cleta = self.ch.el_cl_eta[i]
                if abs(cleta) >= region[0] and abs(cleta) <= region[1]:
                    continue

            #authors
            if self.allowed_authors:
                if not self.allowed_authors.count(self.ch.el_author[i]):
                    continue

            # Isolation
            if self.ch.el_nucone40[i] > self.max_nucone40: continue
            if self.ch.el_ptcone40[i] / p.Pt() > self.max_ptcone40rel: continue
            if self.ch.el_Etcone20[i] / p.Pt() > self.max_etcone20rel: continue

            #cleaning
            if self.req_cleaning:
                if (self.ch.el_OQ[i] & 1446) != 0: continue

            # isEM ID
            if self.req_medium_old:
                if (self.ch.el_isEM[i] & egammaPID.ElectronMedium) != 0:
                    continue
            if self.req_tight_old:
                if (self.ch.el_isEM[i] & egammaPID.ElectronTight) != 0:
                    continue
            if self.req_medium:
                if (self.ch.el_medium[i] != 1): continue
            if self.req_tight:
                if (self.ch.el_tight[i] != 1): continue

            # isEM ID PP
            if self.recalculate_isEMplusplus:
                patch = ElectronIDpatch(
                    self.ch.el_cl_E[i], self.ch.el_etas2[i],
                    self.ch.el_Ethad[i], self.ch.el_Ethad1[i],
                    self.ch.el_reta[i], self.ch.el_weta2[i], self.ch.el_f1[i],
                    self.ch.el_f3[i], self.ch.el_wstot[i],
                    self.ch.el_emaxs1[i], self.ch.el_Emax2[i],
                    self.ch.el_deltaeta1[i], self.ch.el_deltaeta2[i],
                    self.ch.el_trackqoverp[i], self.ch.el_trackd0_physics[i],
                    self.ch.el_TRTHighTOutliersRatio[i],
                    self.ch.el_nTRTHits[i], self.ch.el_nTRTOutliers[i],
                    self.ch.el_nSiHits[i], self.ch.el_nSCTOutliers[i],
                    self.ch.el_nPixelOutliers[i], self.ch.el_nPixHits[i],
                    self.ch.el_nBLHits[i], self.ch.el_nBLayerOutliers[i],
                    self.ch.el_expectHitInBLayer[i], self.ch.el_isEM[i])
                self.el_loosePP_decision, self.el_mediumPP_decision, self.el_tightPP_decision = patch.evaluate(
                )

                #if self.el_loosePP_decision != self.ch.el_loosePP[i] or self.el_mediumPP_decision != self.ch.el_mediumPP[i] or self.el_tightPP_decision != self.ch.el_tightPP[i]:
                #print "isEMpp: ", self.el_loosePP_decision, self.el_mediumPP_decision, self.el_tightPP_decision, "vs", self.ch.el_loosePP[i], self.ch.el_mediumPP[i], self.ch.el_tightPP[i]

            else:
                self.el_loosePP_decision = self.ch.el_loosePP[i]
                self.el_mediumPP_decision = self.ch.el_mediumPP[i]
                self.el_tightPP_decision = self.ch.el_tightPP[i]
            if self.req_loosePP:
                if (self.el_loosePP_decision != 1): continue
            if self.req_mediumPP:
                if (self.el_mediumPP_decision != 1): continue
            if self.req_tightPP:
                if (self.el_tightPP_decision != 1): continue

            #print 'passed el sel'
            self.add_particle(p)
        #end of loop

        self.sort_particles()
        return self.get_particles()
Exemple #9
0
  def select(self):
  
    self.tag_index[0] = -1
    self.probe_index[0] = -1
    self.vis_mass[0] = -1.

    # apply trigger if requested
    if self.trig_selector:
      if not self.trig_selector.select():
        #print 'Failed Trigger'
        return False
      #else:
      #  print 'Passed Trigger'


    # Select Particles
    taus  = self.tau_selector.select()
    muons = self.muon_selector.select()
    eles  = self.ele_selector.select()

    # Remove Overlap
    remove_overlap( muons, eles, 0.2 )
    remove_overlap( muons, taus, 0.4 )
    remove_overlap( eles,  taus, 0.4 )
   
    n_eles = len(eles)
    n_muons = len(muons)
    n_taus = len(taus)
    
    # Require probe tau candidate
    if n_taus == 0: return False

    # Require tag lepton candidate
    if self.channel == 1:
      if n_eles == 0: return False
    elif self.channel == 2:
      if n_muons == 0: return False

    # Choose tag 
    tag = None
    if self.channel == 1:   tag = eles[0]
    elif self.channel == 2: tag = muons[0]
    if not tag: return False
    self.tag_index[0] = tag.index

    # Choose probe
    probe = taus[0]
    self.probe_index[0] = probe.index

    
    # Dilepton veto
    if self.req_dilepton_veto: 
      if n_eles + n_muons > 1: return False

    # Define MET (problematic, since no corrections are applied)
    met_x = (self.ch.MET_LocHadTopo_etx
              + self.ch.MET_MuonBoy_etx
              - self.ch.MET_RefMuon_Track_etx)
    met_y = (self.ch.MET_LocHadTopo_ety
              + self.ch.MET_MuonBoy_ety
              - self.ch.MET_RefMuon_Track_ety)
    met_E = sqrt( met_x*met_x + met_y*met_y )
    met = ParticleBase( 0, _px = met_x, _py = met_y, _pz = 0., _E = met_E )

    # W suppression 
    sum_cos_dphi = cos(probe.DeltaPhi(met)) + cos(tag.DeltaPhi(met))
    if sum_cos_dphi < self.min_sum_cos_dphi: return False
    
    trans_mass = sqrt(2.*tag.Pt()*met.Pt()*(1. - cos(tag.DeltaPhi(met))))
    if trans_mass > self.max_trans_mass: return False

    # Lepton Isolation
    if self.channel == 1:
      if self.ch.el_nucone40[tag.index] > self.tag_max_nucone40: return False
      if self.ch.el_etcone20[tag.index]/probe.Pt() > self.tag_max_etcone20onpt: return False
    if self.channel == 2:
      if self.ch.mu_staco_nucone40[tag.index] > self.tag_max_nucone40: return False
      if self.ch.mu_staco_etcone20[tag.index]/probe.Pt() > self.tag_max_etcone20onpt: return False

    # opposite sign / not same sign
    probe_charge = self.ch.tau_charge[probe.index]
    tag_charge = 0.
    if   self.channel == 1: tag_charge = self.ch.el_charge[tag.index]
    elif self.channel == 2: tag_charge = self.ch.mu_staco_charge[tag.index]
    if self.req_os and (probe_charge * tag_charge) >= 0: return False
    if self.req_not_ss and (probe_charge * tag_charge) > 0: return False

    mvis=(tag+probe).M()
 
    #mass window cut
    if len(self.vis_mass_window) == 2 and not min(self.vis_mass_window) <  mvis <  max(self.vis_mass_window) : return False

    
    # write out visible mass for cross checking skim
    self.vis_mass[0] = mvis

    if self.tree: self.tree.Fill()

    return True
Exemple #10
0
	def select(self):
		self.clear_particles() 

    	# require TTree to be loaded
		if not self.ch:
			print 'TauSelector. Warning! No input TTree'
			return 


		# construct loose muons
		loose_muons = []
		if self.veto_loose_muon:
			for imu in range( 0,self.ch.mu_staco_n):
				if not self.ch.mu_staco_loose[imu]: continue
				loose_muons.append( ParticleBase( _index = imu,
					_pt  = self.ch.mu_staco_pt[imu],
					_eta = self.ch.mu_staco_eta[imu],
					_phi = self.ch.mu_staco_phi[imu],
					_m   = self.ch.mu_staco_m[imu] 
					) )

		# Loop over taus and select candidates
		for i in range(0,self.ch.tau_n):
			p = ParticleBase( _index = i, 
							_pt  = self.ch.tau_pt[i],
							_eta = self.ch.tau_eta[i],
							_phi = self.ch.tau_phi[i],
							_m   = self.ch.tau_m[i] )
		
			if p.Pt()       < self.min_pt : continue
			if abs(p.Eta()) > self.max_eta: continue
			
			if self.allowed_authors and not self.ch.tau_author[i] in self.allowed_authors: continue
			if self.allowed_tracks  and not self.ch.tau_numTrack[i] in self.allowed_tracks: continue
			if self.nonzero_tracks and not self.ch.tau_numTrack[i] > 0 : continue
			if self.req_unit_charge and not abs( self.ch_tau_charge[i] )==1: continue
		
			if self.req_truth and not self.ch.tau_trueTauAssoc_matched[i]: continue
			
			if self.req_cut_l and not self.ch.tau_tauCutLoose[i]: continue
			if self.req_cut_m and not self.ch.tau_tauCutMedium[i]: continue
			if self.req_cut_t and not self.ch.tau_tauCutTight[i]: continue
			if self.req_llh_l and not self.ch.tau_tauLlhLoose[i]: continue
			if self.req_llh_m and not self.ch.tau_tauLlhMedium[i]: continue
			if self.req_llh_t and not self.ch.tau_tauLlhTight[i]: continue
			
			if self.req_ecut_l and self.ch.tau_electronVetoLoose[i]: continue
			if self.req_ecut_m and self.ch.tau_electronVetoMedium[i]: continue
			if self.req_ecut_t and self.ch.tau_electronVetoTight[i]: continue
			if self.req_ebdt_l and self.ch.tau_EleBDTLoose[i]: continue
			if self.req_ebdt_m and self.ch.tau_EleBDTMedium[i]: continue
			if self.req_ebdt_t and self.ch.tau_EleBDTTight[i]: continue
			if self.min_bdt_ele_score and self.ch.tau_BDTEleScore[i] < self.min_bdt_ele_score: continue
		
			if self.req_muon_veto and self.ch.tau_muonVeto[i]: continue
			
			if self.min_bdt_jet_score and self.ch.tau_BDTJetScore[i] < self.min_bdt_jet_score: continue
			
			if self.veto_loose_muon:
				veto_tau = False
				for muon in loose_muons:
					if p.DeltaR(muon) < 0.2:
						veto_tau = True
						break
				if veto_tau: continue

			#added/modified to adapt the tau id patch
			if self.recalculate_tauID:
				# BDT is recalculated
				patch = TauIDpatch(self.year)
				pt =  self.ch.tau_pt[i]
				tracks = self.ch.tau_numTrack[i]
				bdtscore = self.ch.tau_BDTJetScore[i]
				
				if self.year == 2012:
					#print 'recalculating year 2012 pT= %f MeV, Ntrk = %d, bdt = %f'% (pt, tracks, bdtscore)
					self.decision_tau_JetBDTSigLoose, \
					self.decision_tau_JetBDTSigMedium, \
					self.decision_tau_JetBDTSigTight, \
					=  patch.passes_2012(pt, tracks, bdtscore)
					#print self.ch.tau_JetBDTSigLoose[i], self.ch.tau_JetBDTSigMedium[i], self.ch.tau_JetBDTSigTight[i], \
					#' vs ', self.decision_tau_JetBDTSigLoose, self.decision_tau_JetBDTSigMedium, self.decision_tau_JetBDTSigTight
				elif self.year == 2011:
					print "2011 is under contruction"
					continue
				else:
					raise ValueError("TauSelector: No tauid defined for year %d" % year)
			else:
				self.decision_tau_JetBDTSigLoose = self.ch.tau_JetBDTSigLoose[i]
				self.decision_tau_JetBDTSigMedium = self.ch.tau_JetBDTSigMedium[i]
				self.decision_tau_JetBDTSigTight = self.ch.tau_JetBDTSigTight[i]
			##
			if self.req_bdt_l and not self.decision_tau_JetBDTSigLoose: continue
			if self.req_bdt_m and not self.decision_tau_JetBDTSigMedium: continue
			if self.req_bdt_t and not self.decision_tau_JetBDTSigTight: continue
			
			
		
		

			
		

		
			self.add_particle(p)
		#end of loop
		
		self.sort_particles()
		return self.get_particles()
Exemple #11
0
    def select(self):
        self.clear_particles()

        # require TTree to be loaded
        if not self.ch:
            print 'Warning, no input TTree'
            return


#    print 'mu_staco_n: ', self.ch.mu_staco_n
# Loop over mu_stacos and select candidates
        for i in range(0, self.ch.mu_staco_n):
            p = ParticleBase(_index=i,
                             _pt=self.ch.mu_staco_pt[i],
                             _eta=self.ch.mu_staco_eta[i],
                             _phi=self.ch.mu_staco_phi[i],
                             _m=self.ch.mu_staco_m[i])

            if p.Pt() < self.min_pt: continue
            if abs(p.Eta()) > self.max_eta: continue

            if self.req_tight:
                if not self.ch.mu_staco_tight[i]: continue

            if self.req_combined:
                if not self.ch.mu_staco_isCombinedMuon[i]: continue

            if self.ch.mu_staco_z0_exPV[i] >= self.max_z0: continue

            if self.ch.mu_staco_nBLHits[i] < self.min_BLHits: continue
            if (self.ch.mu_staco_nPixHits[i] +
                    self.ch.mu_staco_nPixelDeadSensors[i] < self.min_PixHits):
                continue
            if (self.ch.mu_staco_nSCTHits[i] +
                    self.ch.mu_staco_nSCTDeadSensors[i] < self.min_SCTHits):
                continue
            if self.ch.mu_staco_nSCTHoles[i] > self.max_SCTHoles: continue

            # Isolation
            if self.ch.mu_staco_nucone40[i] > self.max_nucone40: continue
            if self.ch.mu_staco_ptcone40[i] / p.Pt() > self.max_ptcone40rel:
                continue
            if self.ch.mu_staco_etcone20[i] / p.Pt() > self.max_etcone20rel:
                continue

            # TRT cleaning
            if self.req_trt_cleaning:
                abs_eta = abs(p.Eta())
                n_Hits_TRT = self.ch.mu_staco_nTRTHits[i]
                n_Hits_TRT_Outliers = self.ch.mu_staco_nTRTOutliers[i]
                n_Hits_TRT_and_Outliers = n_Hits_TRT_Outliers + n_Hits_TRT
                if abs_eta < 1.9:
                    if not (n_Hits_TRT_and_Outliers > 5
                            and float(n_Hits_TRT_Outliers) /
                            float(n_Hits_TRT_and_Outliers) < 0.9):
                        continue
                elif abs_eta >= 1.9 and n_Hits_TRT_and_Outliers > 5 and float(
                        n_Hits_TRT_Outliers) / float(
                            n_Hits_TRT_and_Outliers) > 0.9:
                    continue

            self.add_particle(p)

        self.sort_particles()

        return self.get_particles()