Beispiel #1
0
 def __init__(self, *args, **kwargs):
     super(JetClusterizer, self).__init__(*args, **kwargs)
     args = self.cfg_ana.fastjet_args
     self.clusterize = None
     self.njets = 0
     if 'ptmin' in args and 'njets' in args:
         raise ValueError('cannot specify both ptmin and njets arguments')
     if len(args) == 1:       
         if 'ptmin' in args:
             self.clusterizer = CCJetClusterizer(0)
             def clusterize():
                 return self.clusterizer.make_inclusive_jets(args['ptmin'],
                                                             0.4) 
             self.clusterize = clusterize
         elif 'njets' in args:
             self.njets = args['njets']
             self.clusterizer = CCJetClusterizer(1)
             def clusterize():
                 return self.clusterizer.make_exclusive_jets(self.njets) 
             self.clusterize = clusterize
         else:
             raise ValueError('specify either ptmin or njets') 
     elif len(args) == 3:
         if 'R' in args and 'p' in args and 'emin' in args:
             self.clusterizer = CCJetClusterizer(2, args['R'], args['p'])
             def clusterize():
                 return self.clusterizer.make_inclusive_jets(args['emin']) 
             self.clusterize = clusterize
Beispiel #2
0
    def __init__(self, *args, **kwargs):
        super(JetClusterizer, self).__init__(*args, **kwargs)
        args = self.cfg_ana.fastjet_args
        self.clusterize = None
        self.njets = 0
        if 'ptmin' in args and 'njets' in args:
            raise ValueError('cannot specify both ptmin and njets arguments')
        if len(args) == 1:
            if 'ptmin' in args:
                self.clusterizer = CCJetClusterizer(0)

                def clusterize():
                    return self.clusterizer.make_inclusive_jets(args['ptmin'])

                self.clusterize = clusterize
            elif 'njets' in args:
                self.njets = args['njets']
                self.clusterizer = CCJetClusterizer(1)

                def clusterize():
                    return self.clusterizer.make_exclusive_jets(self.njets)

                self.clusterize = clusterize
            else:
                raise ValueError('specify either ptmin or njets')
        elif len(args) == 3:
            if 'R' in args and 'p' in args and 'emin' in args:
                self.clusterizer = CCJetClusterizer(2, args['R'], args['p'])

                def clusterize():
                    return self.clusterizer.make_inclusive_jets(args['emin'])

                self.clusterize = clusterize
class JetClusterizer(Analyzer):
    '''Jet clusterizer. 
    
    Makes use of the JetClusterizer class compiled in the analysis-cpp package. 

    Example configuration: 

    papas_jets = cfg.Analyzer(
       JetClusterizer,
       instance_label = 'papas', 
       particles = 'papas_rec_particles'
    )

    particles: Name of the input particle collection.
    The output jet collection name is built from the instance_label, 
    in this case "papas_jets".
    '''

    def __init__(self, *args, **kwargs):
        super(JetClusterizer, self).__init__(*args, **kwargs)
        min_e = 0.
        self.clusterizer = CCJetClusterizer(min_e)

    def validate(self, jet):
        constits = jet.constituents
        keys = set(jet.constituents.keys())
        all_possible = set([211, 22, 130, 11, 13, 1, 2])
        if not keys.issubset(all_possible):
            print constits
            assert(False)
        sume = 0. 
        for component in jet.constituents.values():
            if component.e() - jet.e() > 1e-5:
                import pdb; pdb.set_trace()
            sume += component.e()
        if jet.e() - sume > 1e-5:
            import pdb; pdb.set_trace()
                
                
    def process(self, event):
        particles = getattr(event, self.cfg_ana.particles)
        # removing neutrinos
        particles = [ptc for ptc in particles if abs(ptc.pdgid()) not in [12,14,16]]
        self.clusterizer.clear();
        for ptc in particles:
            self.clusterizer.add_p4( ptc.p4() )
        self.clusterizer.clusterize()
        jets = []
        for jeti in range(self.clusterizer.n_jets()):
            jet = Jet( self.clusterizer.jet(jeti) )
            jet.constituents = JetConstituents()
            jets.append( jet )
            for consti in range(self.clusterizer.n_constituents(jeti)):
                constituent_index = self.clusterizer.constituent_index(jeti, consti)
                constituent = particles[constituent_index]
                jet.constituents.append(constituent)
            jet.constituents.sort()
            self.validate(jet)
        setattr(event, self.instance_label, jets)
class EventHypothesis(object):

    clusterizer = JetClusterizer(1)

    def __init__(self, taus, jets):
        qqjetsp = [jet for jet in jets if jet not in taus]
        # assert(len(qqjetsp) == 2)
        self.zed = Resonance(qqjetsp, 23, 1)
        self.higgs = Resonance2(taus[0], taus[1], 25, 1)
        self.taus = taus
        self.jets2 = qqjetsp
        self.zed2 = self.zed

    def force_2_jets(self, particles):
        self.__class__.clusterizer.clear()
        other_particles = []
        for ptc in particles:
            keep = True
            for tau in self.taus:
                if ptc in tau.constituents.particles:
                    keep = False
            if keep:
                self.__class__.clusterizer.add_p4(ptc.p4())
                other_particles.append(ptc)
        assert (len(other_particles) +
                len(self.taus[0].constituents.particles) +
                len(self.taus[1].constituents.particles) == len(particles))
        njets = 2
        if len(other_particles) < njets:
            return False
        self.__class__.clusterizer.make_exclusive_jets(njets)
        assert (self.__class__.clusterizer.n_jets() == njets)
        jets = []
        for jeti in range(self.__class__.clusterizer.n_jets()):
            jet = Jet(self.__class__.clusterizer.jet(jeti))
            jet.constituents = JetConstituents()
            for consti in range(
                    self.__class__.clusterizer.n_constituents(jeti)):
                constituent_index = self.__class__.clusterizer.constituent_index(
                    jeti, consti)
                constituent = particles[constituent_index]
                jet.constituents.append(constituent)
            jet.constituents.sort()
            jets.append(jet)
        self.jets2 = jets
        self.zed2 = Resonance2(jets[0], jets[1], 23, 1)
        return True

    def beta4_rescale(self):
        all_jets = list(self.jets2)
        all_jets.extend(self.taus)
        jets_rescaled = copy.deepcopy(all_jets)
        beta4(jets_rescaled, Collider.SQRTS)
        self.jets2_r = jets_rescaled[:2]
        self.taus_r = jets_rescaled[2:]
        self.zed2_r = Resonance2(self.jets2_r[0], self.jets2_r[1], 23, 1)
        self.higgs_r = Resonance2(self.taus_r[0], self.taus_r[1], 25, 1)
Beispiel #5
0
class JetClusterizer(Analyzer):
    '''Jet clusterizer based on fastjet (kt-ee algorithm)
    
    This analyzer, specific to the FCC,
    makes use of the JetClusterizer class compiled in the fcc-physics package.

    Example configuration::

        from heppy.analyzers.fcc.JetClusterizer import JetClusterizer
        jets = cfg.Analyzer(
          JetClusterizer,
          output = 'jets',
          particles = 'particles_not_zed',
          fastjet_args = dict(njets = 2)  
        )
    
    @param output: name of the output collection of L{jets<heppy.particles.jet.Jet>}. 
      Each jet is attached a L{JetConstituents<heppy.particles.jet.JetConstituents>} object
      as C{jet.constituents}.

    @param particles: name of the input collection of particle-like objects. 
      These objects should have a p4(). 
    
    @param fastjet_args: fastjet arguments. 
      you should provide either one or the other of the following arguments:
       - ptmin : pt threshold in GeV for exclusive jet reconstruction 
       - njets : number of jets for inclusive jet reconstruction 
       
    '''

    def __init__(self, *args, **kwargs):
        super(JetClusterizer, self).__init__(*args, **kwargs)
        args = self.cfg_ana.fastjet_args
        self.clusterize = None
        self.njets = 0
        if 'ptmin' in args and 'njets' in args:
            raise ValueError('cannot specify both ptmin and njets arguments')
        if len(args) == 1:       
            if 'ptmin' in args:
                self.clusterizer = CCJetClusterizer(0)
                def clusterize():
                    return self.clusterizer.make_inclusive_jets(args['ptmin'],
                                                                0.4) 
                self.clusterize = clusterize
            elif 'njets' in args:
                self.njets = args['njets']
                self.clusterizer = CCJetClusterizer(1)
                def clusterize():
                    return self.clusterizer.make_exclusive_jets(self.njets) 
                self.clusterize = clusterize
            else:
                raise ValueError('specify either ptmin or njets') 
        elif len(args) == 3:
            if 'R' in args and 'p' in args and 'emin' in args:
                self.clusterizer = CCJetClusterizer(2, args['R'], args['p'])
                def clusterize():
                    return self.clusterizer.make_inclusive_jets(args['emin']) 
                self.clusterize = clusterize
        
    def validate(self, jet):
        constits = jet.constituents
        keys = set(jet.constituents.keys())
        all_possible = set([211, 22, 130, 11, 13, 1, 2])
        if not keys.issubset(all_possible):
            print constits
            assert(False)
        sume = 0. 
        for component in jet.constituents.values():
            if component.e() - jet.e() > 1e-5:
                import pdb; pdb.set_trace()
            sume += component.e()
        if jet.e() - sume > 1e-5:
            import pdb; pdb.set_trace()
                
                
    def process(self, event):
        '''Process event.
        
        The event must contain:
         - self.cfg_ana.particles: the list of particles to be clustered
         
        This method creates:
         - event.<self.cfg_ana.output>: the list of L{jets<heppy.particles.jet.Jet>}. 
        '''
        particles = getattr(event, self.cfg_ana.particles)
        # removing neutrinos
        particles = [ptc for ptc in particles if abs(ptc.pdgid()) not in [12,14,16]]
        if len(particles) < self.njets:
            if hasattr(self.cfg_ana, 'njets_required') and self.cfg_ana.njets_required == False:
                # not enough particles for the required number of jets,
                # making no jet
                setattr(event, self.cfg_ana.output, [])
                return True                

            else:
                # njets_required not provided, or njets_required set to True
                err = 'Cannot make {} jets with {} particles -> Event discarded'.format(
                    self.njets, len(particles)
                )
                self.mainLogger.error(err)
                # killing the sequence, as the user requests exactly njets
                return False
        # enough particles to make the required number of jets
        self.clusterizer.clear()
        for ptc in particles:
            self.clusterizer.add_p4( ptc.p4() )
        self.clusterize()
        jets = []
        if self.cfg_ana.verbose:
            print self.clusterizer.n_jets(), 'jets:'
        for jeti in range(self.clusterizer.n_jets()):
            jet = Jet( self.clusterizer.jet(jeti) )
            jet.constituents = JetConstituents()
            jets.append( jet )
            for consti in range(self.clusterizer.n_constituents(jeti)):
                constituent_index = self.clusterizer.constituent_index(jeti, consti)
                constituent = particles[constituent_index]
                jet.constituents.append(constituent)
            jet.constituents.sort()
            self.validate(jet)
            if self.cfg_ana.verbose:
                print '\t', jet
        setattr(event, self.cfg_ana.output, jets)
 def __init__(self, *args, **kwargs):
     super(JetClusterizer, self).__init__(*args, **kwargs)
     min_e = 0.
     self.clusterizer = CCJetClusterizer(min_e)
class JetClusterizer(Analyzer):

    def __init__(self, *args, **kwargs):
        super(JetClusterizer, self).__init__(*args, **kwargs)
        self.clusterizer = CCJetClusterizer()

    def validate(self, jet):
        constits = jet.constituents
        keys = set(jet.constituents.keys())
        all_possible = set({211, 22, 130, 11, 13})
        if not keys.issubset(all_possible):
            print constits
            assert(False)
        sume = 0. 
        for component in jet.constituents.values():
            if component.e() - jet.e() > 1e-5:
                import pdb; pdb.set_trace()
            sume += component.e()
        if jet.e() - sume > 1e-5:
            import pdb; pdb.set_trace()
                
                
    def process(self, event):
        particles = getattr(event, self.cfg_ana.particles)
        # removing neutrinos
        particles = [ptc for ptc in particles if abs(ptc.pdgid()) not in [12,14,16]]
        self.clusterizer.clear();
        for ptc in particles:
            self.clusterizer.add_p4( ptc.p4() )
        self.clusterizer.clusterize()
        self.mainLogger.info( 'njets = {n}'.format(
            n=self.clusterizer.n_jets())
        )
        jets = []
        for jeti in range(self.clusterizer.n_jets()):
            jet = Jet( self.clusterizer.jet(jeti) )
            jet.constituents = JetConstituents()
            jets.append( jet )
            self.mainLogger.info( '\t{jet}'.format(jet=jet))
            for consti in range(self.clusterizer.n_constituents(jeti)):
                constituent_index = self.clusterizer.constituent_index(jeti, consti)
                constituent = particles[constituent_index]
                jet.constituents.append(constituent)
            jet.constituents.sort()
            self.mainLogger.info( '{jet}'.format(jet=str(jet.constituents)))
            self.validate(jet)
        setattr(event, '_'.join([self.instance_label,'jets']), jets)
Beispiel #8
0
class JetClusterizer(Analyzer):
    '''Jet clusterizer based on fastjet (kt-ee algorithm)
    
    This analyzer, specific to the FCC,
    makes use of the JetClusterizer class compiled in the fcc-physics package.

    Example configuration::

        from heppy.analyzers.fcc.JetClusterizer import JetClusterizer
        jets = cfg.Analyzer(
          JetClusterizer,
          output = 'jets',
          particles = 'particles_not_zed',
          fastjet_args = dict(njets = 2)  
        )
    
    @param output: name of the output collection of L{jets<heppy.particles.jet.Jet>}. 
      Each jet is attached a L{JetConstituents<heppy.particles.jet.JetConstituents>} object
      as C{jet.constituents}.

    @param particles: name of the input collection of particle-like objects. 
      These objects should have a p4(). 
    
    @param fastjet_args: fastjet arguments. 
      you should provide either one or the other of the following arguments:
       - ptmin : pt threshold in GeV for exclusive jet reconstruction 
       - njets : number of jets for inclusive jet reconstruction 
       
    '''
    def __init__(self, *args, **kwargs):
        super(JetClusterizer, self).__init__(*args, **kwargs)
        args = self.cfg_ana.fastjet_args
        self.clusterize = None
        if 'ptmin' in args and 'njets' in args:
            raise ValueError('cannot specify both ptmin and njets arguments')
        if 'ptmin' in args:
            self.clusterizer = CCJetClusterizer(0)

            def clusterize():
                return self.clusterizer.make_inclusive_jets(args['ptmin'])

            self.clusterize = clusterize
        elif 'njets' in args:
            self.clusterizer = CCJetClusterizer(1)

            def clusterize():
                return self.clusterizer.make_exclusive_jets(args['njets'])

            self.clusterize = clusterize
        else:
            raise ValueError('specify either ptmin or njets')

    def validate(self, jet):
        constits = jet.constituents
        keys = set(jet.constituents.keys())
        all_possible = set([211, 22, 130, 11, 13, 1, 2])
        if not keys.issubset(all_possible):
            print constits
            assert (False)
        sume = 0.
        for component in jet.constituents.values():
            if component.e() - jet.e() > 1e-5:
                import pdb
                pdb.set_trace()
            sume += component.e()
        if jet.e() - sume > 1e-5:
            import pdb
            pdb.set_trace()

    def process(self, event):
        '''Process event.
        
        The event must contain:
         - self.cfg_ana.particles: the list of particles to be clustered
         
        This method creates:
         - event.<self.cfg_ana.output>: the list of L{jets<heppy.particles.jet.Jet>}. 
        '''
        particles = getattr(event, self.cfg_ana.particles)
        # removing neutrinos
        particles = [
            ptc for ptc in particles if abs(ptc.pdgid()) not in [12, 14, 16]
        ]
        self.clusterizer.clear()
        for ptc in particles:
            self.clusterizer.add_p4(ptc.p4())
        self.clusterize()
        jets = []
        for jeti in range(self.clusterizer.n_jets()):
            jet = Jet(self.clusterizer.jet(jeti))
            jet.constituents = JetConstituents()
            jets.append(jet)
            for consti in range(self.clusterizer.n_constituents(jeti)):
                constituent_index = self.clusterizer.constituent_index(
                    jeti, consti)
                constituent = particles[constituent_index]
                jet.constituents.append(constituent)
            jet.constituents.sort()
            self.validate(jet)
        setattr(event, self.cfg_ana.output, jets)
Beispiel #9
0
class JetClusterizer(Analyzer):
    '''Jet clusterizer. 
    
    Makes use of the JetClusterizer class compiled in the analysis-cpp package
    (this external package is the only dependence to the FCC software).

    Example configuration: 

    from heppy.analyzers.fcc.JetClusterizer import JetClusterizer
    jets = cfg.Analyzer(
      JetClusterizer,
      output = 'jets',
      particles = 'particles_not_zed',
      fastjet_args = dict( njets = 2)  
    )
    
    * output: name of the output collection of Jets. 
    Each jet is attached a JetConstituents object as jet.constituents.
    See the Jet and JetConstituents classes. 

    * particles: name of the input collection of particle-like objects. 
    These objects should have a p4(). 
    
    you should provide either one or the other of the following arguments:
    - ptmin : pt threshold for exclusive jet reconstruction 
    - njets : number of jets for inclusive jet reconstruction 

    A more flexible interface can easily be provided if needed, 
    contact Colin.
    '''

    def __init__(self, *args, **kwargs):
        super(JetClusterizer, self).__init__(*args, **kwargs)
        args = self.cfg_ana.fastjet_args
        self.clusterize = None
        if 'ptmin' in args and 'njets' in args:
            raise ValueError('cannot specify both ptmin and njets arguments')
        if 'ptmin' in args:
            self.clusterizer = CCJetClusterizer(0)
            def clusterize():
                return self.clusterizer.make_inclusive_jets(args['ptmin']) 
            self.clusterize = clusterize
        elif 'njets' in args:
            self.clusterizer = CCJetClusterizer(1)
            def clusterize():
                return self.clusterizer.make_exclusive_jets(args['njets']) 
            self.clusterize = clusterize
        else:
            raise ValueError('specify either ptmin or njets') 
        
    def validate(self, jet):
        constits = jet.constituents
        keys = set(jet.constituents.keys())
        all_possible = set([211, 22, 130, 11, 13, 1, 2])
        if not keys.issubset(all_possible):
            print constits
            assert(False)
        sume = 0. 
        for component in jet.constituents.values():
            if component.e() - jet.e() > 1e-5:
                import pdb; pdb.set_trace()
            sume += component.e()
        if jet.e() - sume > 1e-5:
            import pdb; pdb.set_trace()
                
                
    def process(self, event):
        particles = getattr(event, self.cfg_ana.particles)
        # removing neutrinos
        particles = [ptc for ptc in particles if abs(ptc.pdgid()) not in [12,14,16]]
        self.clusterizer.clear();
        for ptc in particles:
            self.clusterizer.add_p4( ptc.p4() )
        self.clusterize()
        jets = []
        for jeti in range(self.clusterizer.n_jets()):
            jet = Jet( self.clusterizer.jet(jeti) )
            jet.constituents = JetConstituents()
            jets.append( jet )
            for consti in range(self.clusterizer.n_constituents(jeti)):
                constituent_index = self.clusterizer.constituent_index(jeti, consti)
                constituent = particles[constituent_index]
                jet.constituents.append(constituent)
            jet.constituents.sort()
            self.validate(jet)
        setattr(event, self.cfg_ana.output, jets)
Beispiel #10
0
class JetClusterizer(Analyzer):
    '''Jet clusterizer based on fastjet (kt-ee algorithm)
    
    This analyzer, specific to the FCC,
    makes use of the JetClusterizer class compiled in the fcc-physics package.

    Example configuration::

        from heppy.analyzers.fcc.JetClusterizer import JetClusterizer
        jets = cfg.Analyzer(
          JetClusterizer,
          output = 'jets',
          particles = 'particles_not_zed',
          algorithm = 'ee_kt',
          fastjet_args = dict(njets = 2)
        )
    
    @param output: name of the output collection of L{jets<heppy.particles.jet.Jet>}. 
      Each jet is attached a L{JetConstituents<heppy.particles.jet.JetConstituents>} object
      as C{jet.constituents}.

    @param particles: name of the input collection of particle-like objects. 
      These objects should have a p4(). 
    
    @param algorithm : jet algorithm to used.
      You should precise which algorithm you want use. Choose between ee_kt, ee_genkt, kt or anti_kt
 
    @param fastjet_args: fastjet arguments. 
      you should provide either one or the other of the following arguments:
       - ptmin : pt threshold in GeV for exclusive jet reconstruction 
       - njets : number of jets for inclusive jet reconstruction 

    '''
    def __init__(self, *args, **kwargs):
        super(JetClusterizer, self).__init__(*args, **kwargs)
        args = self.cfg_ana.fastjet_args
        self.clusterize = None
        self.njets = 0

        if 'ptmin' in args and 'njets' in args:
            raise ValueError('cannot specify both ptmin and njets arguments')

        if 'ptmin' in args:
            self.clusterizer = CCJetClusterizer(0, self.cfg_ana.algorithm)

            def clusterize():
                return self.clusterizer.make_inclusive_jets(args['ptmin'])

            self.clusterize = clusterize

        elif 'njets' in args:
            self.njets = args['njets']
            self.clusterizer = CCJetClusterizer(1, self.cfg_ana.algorithm)

            def clusterize():
                return self.clusterizer.make_exclusive_jets(self.njets)

            self.clusterize = clusterize

        else:
            raise ValueError('specify either ptmin or njets')

    def validate(self, jet):
        constits = jet.constituents
        keys = set(jet.constituents.keys())
        all_possible = set([211, 22, 130, 11, 13, 1, 2])
        if not keys.issubset(all_possible):
            print constits
            assert (False)
        sume = 0.
        for component in jet.constituents.values():
            if component.e() - jet.e() > 1e-5:
                import pdb
                pdb.set_trace()
            sume += component.e()
        if jet.e() - sume > 1e-5:
            import pdb
            pdb.set_trace()

    def process(self, event):
        '''Process event.
 
        The event must contain:
         - self.cfg_ana.particles: the list of particles to be clustered

        This method creates:
         - event.<self.cfg_ana.output>: the list of L{jets<heppy.particles.jet.Jet>}. 
        '''
        particles = getattr(event, self.cfg_ana.particles)
        # removing neutrinos
        particles = [
            ptc for ptc in particles if abs(ptc.pdgid()) not in [12, 14, 16]
        ]
        if len(particles) < self.njets:
            if hasattr(
                    self.cfg_ana,
                    'njets_required') and self.cfg_ana.njets_required == False:
                # not enough particles for the required number of jets,
                # making no jet
                setattr(event, self.cfg_ana.output, [])
                return True

            else:
                # njets_required not provided, or njets_required set to True
                err = 'Cannot make {} jets with {} particles -> Event discarded'.format(
                    self.njets, len(particles))
                self.mainLogger.error(err)
                # killing the sequence, as the user requests exactly njets
                return False
        # enough particles to make the required number of jets
        self.clusterizer.clear()
        for ptc in particles:
            self.clusterizer.add_p4(ptc.p4())
        self.clusterize()
        jets = []
        for jeti in range(self.clusterizer.n_jets()):
            jet = Jet(self.clusterizer.jet(jeti))
            jet.constituents = JetConstituents()
            jets.append(jet)
            for consti in range(self.clusterizer.n_constituents(jeti)):
                constituent_index = self.clusterizer.constituent_index(
                    jeti, consti)
                constituent = particles[constituent_index]
                jet.constituents.append(constituent)
            jet.constituents.sort()
            self.validate(jet)
        setattr(event, self.cfg_ana.output, jets)
Beispiel #11
0
class JetClusterizer(Analyzer):
    '''Jet clusterizer. 
    
    Makes use of the JetClusterizer class compiled in the analysis-cpp package
    (this external package is the only dependence to the FCC software).

    Example configuration: 

    from heppy.analyzers.fcc.JetClusterizer import JetClusterizer
    jets = cfg.Analyzer(
      JetClusterizer,
      output = 'jets',
      particles = 'particles_not_zed',
      fastjet_args = dict( njets = 2)  
    )
    
    * output: name of the output collection of Jets. 
    Each jet is attached a JetConstituents object as jet.constituents.
    See the Jet and JetConstituents classes. 

    * particles: name of the input collection of particle-like objects. 
    These objects should have a p4(). 
    
    you should provide either one or the other of the following arguments:
    - ptmin : pt threshold for exclusive jet reconstruction 
    - njets : number of jets for inclusive jet reconstruction 

    A more flexible interface can easily be provided if needed, 
    contact Colin.
    '''
    def __init__(self, *args, **kwargs):
        super(JetClusterizer, self).__init__(*args, **kwargs)
        args = self.cfg_ana.fastjet_args
        self.clusterize = None
        if 'ptmin' in args and 'njets' in args:
            raise ValueError('cannot specify both ptmin and njets arguments')
        if 'ptmin' in args:
            self.clusterizer = CCJetClusterizer(0)

            def clusterize():
                return self.clusterizer.make_inclusive_jets(args['ptmin'])

            self.clusterize = clusterize
        elif 'njets' in args:
            self.clusterizer = CCJetClusterizer(1)

            def clusterize():
                return self.clusterizer.make_exclusive_jets(args['njets'])

            self.clusterize = clusterize
        else:
            raise ValueError('specify either ptmin or njets')

    def validate(self, jet):
        constits = jet.constituents
        keys = set(jet.constituents.keys())
        all_possible = set([211, 22, 130, 11, 13, 1, 2])
        if not keys.issubset(all_possible):
            print constits
            assert (False)
        sume = 0.
        for component in jet.constituents.values():
            if component.e() - jet.e() > 1e-5:
                import pdb
                pdb.set_trace()
            sume += component.e()
        if jet.e() - sume > 1e-5:
            import pdb
            pdb.set_trace()

    def process(self, event):
        particles = getattr(event, self.cfg_ana.particles)
        # removing neutrinos
        particles = [
            ptc for ptc in particles if abs(ptc.pdgid()) not in [12, 14, 16]
        ]
        self.clusterizer.clear()
        for ptc in particles:
            self.clusterizer.add_p4(ptc.p4())
        self.clusterize()
        jets = []
        for jeti in range(self.clusterizer.n_jets()):
            jet = Jet(self.clusterizer.jet(jeti))
            jet.constituents = JetConstituents()
            jets.append(jet)
            for consti in range(self.clusterizer.n_constituents(jeti)):
                constituent_index = self.clusterizer.constituent_index(
                    jeti, consti)
                constituent = particles[constituent_index]
                jet.constituents.append(constituent)
            jet.constituents.sort()
            self.validate(jet)
        setattr(event, self.cfg_ana.output, jets)
Beispiel #12
0
class JetClusterizer(Analyzer):
    '''Jet clusterizer. 
    
    Makes use of the JetClusterizer class compiled in the analysis-cpp package. 

    Example configuration: 

    papas_jets = cfg.Analyzer(
       JetClusterizer,
       instance_label = 'papas', 
       particles = 'papas_rec_particles', 
       ptmin = 1.  # for inclusive jets 
       # or 
       # njets = 2 # for exclusive jets
    )

    particles: Name of the input particle collection.
    The output jet collection name is built from the instance_label, 
    in this case "papas_jets". 
    
    you should provide either one or the other of the following arguments:
    - ptmin : pt threshold for exclusive jet reconstruction 
    - njets : number of jets for inclusive jet reconstruction 
    '''

    def __init__(self, *args, **kwargs):
        super(JetClusterizer, self).__init__(*args, **kwargs)
        args = self.cfg_ana.fastjet_args
        self.clusterize = None
        if 'ptmin' in args and 'njets' in args:
            raise ValueError('cannot specify both ptmin and njets arguments')
        if 'ptmin' in args:
            self.clusterizer = CCJetClusterizer(0)
            def clusterize():
                return self.clusterizer.make_inclusive_jets(args['ptmin']) 
            self.clusterize = clusterize
        elif 'njets' in args:
            self.clusterizer = CCJetClusterizer(1)
            def clusterize():
                return self.clusterizer.make_exclusive_jets(args['njets']) 
            self.clusterize = clusterize
        else:
            raise ValueError('specify either ptmin or njets') 
        
    def validate(self, jet):
        constits = jet.constituents
        keys = set(jet.constituents.keys())
        all_possible = set([211, 22, 130, 11, 13, 1, 2])
        if not keys.issubset(all_possible):
            print constits
            assert(False)
        sume = 0. 
        for component in jet.constituents.values():
            if component.e() - jet.e() > 1e-5:
                import pdb; pdb.set_trace()
            sume += component.e()
        if jet.e() - sume > 1e-5:
            import pdb; pdb.set_trace()
                
                
    def process(self, event):
        particles = getattr(event, self.cfg_ana.particles)
        # removing neutrinos
        particles = [ptc for ptc in particles if abs(ptc.pdgid()) not in [12,14,16]]
        self.clusterizer.clear();
        for ptc in particles:
            self.clusterizer.add_p4( ptc.p4() )
        self.clusterize()
        jets = []
        for jeti in range(self.clusterizer.n_jets()):
            jet = Jet( self.clusterizer.jet(jeti) )
            jet.constituents = JetConstituents()
            jets.append( jet )
            for consti in range(self.clusterizer.n_constituents(jeti)):
                constituent_index = self.clusterizer.constituent_index(jeti, consti)
                constituent = particles[constituent_index]
                jet.constituents.append(constituent)
            jet.constituents.sort()
            self.validate(jet)
        setattr(event, self.instance_label, jets)