Ejemplo n.º 1
0
    def test_papasevent(self):
        papasevent = PapasEvent(0)
        ecals = dict()
        tracks = dict()
        mixed = dict()

        for i in range(0, 2):
            uid = Identifier.make_id(Identifier.PFOBJECTTYPE.ECALCLUSTER, i,'t', 4.5)
            ecals[uid] = uid
        for i in range(0, 2):
            uid = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK, i, 's', 4.5)
            tracks[uid] = uid            
        
        lastid = Identifier.make_id(Identifier.PFOBJECTTYPE.ECALCLUSTER, 3, 't', 3)
        ecals[lastid] = lastid    
        
        papasevent.add_collection(ecals)
        papasevent.add_collection(tracks)
        
        #check that adding the same collection twice fails        
        self.assertRaises(ValueError, papasevent.add_collection, ecals)
        
        #check that adding a mixed collection fails
        mixed = ecals.copy()
        mixed.update(tracks)
        self.assertRaises(ValueError, papasevent.add_collection, mixed)
        
        #get we can get back collections OK
        self.assertTrue( papasevent.get_collection('zz') is None)
        self.assertTrue( len(papasevent.get_collection('et'))  == 3 )
        
        #check get_object
        self.assertTrue( Identifier.pretty(papasevent.get_object(lastid))  == 'et3' )
        self.assertTrue( papasevent.get_object(499)  is None )       
Ejemplo n.º 2
0
 def __init__(self, uid, layer):
     ''' uid is unique integer from 101-199 for ecal cluster
           unique integer from 201-299 for hcal cluster
           layer is ecal/hcal
     '''
     if (layer == 'ecal_in'):
         self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.ECALCLUSTER, 't')
     elif (layer == 'hcal_in'):
         self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.HCALCLUSTER,  't')
     else:
         assert false
     self.layer = layer
     self.uid = uid
     self.energy=0
Ejemplo n.º 3
0
 def __init__(self, id, layer):
     ''' id is unique integer from 101-199 for ecal cluster
           unique integer from 201-299 for hcal cluster
           layer is ecal/hcal
     '''
     if (layer == 'ecal_in'):
         self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.ECALCLUSTER)
     elif (layer == 'hcal_in'):
         self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.HCALCLUSTER)
     else:
         assert false
     self.layer = layer
     self.id = id
     self.energy=0
Ejemplo n.º 4
0
 def __init__(self, uid,pdgid):
     ''' uid is unique integer from 601-699
         pdgid is particle uid eg 22 for photon
     '''
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.PARTICLE, 'r')
     self.pdgid = pdgid
     self.uid = uid
Ejemplo n.º 5
0
 def __init__(self, id):
     ''' id is unique integer from 1-99
     '''
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK)
     self.id = id
     self.layer = 'tracker'
     self.energy=0
Ejemplo n.º 6
0
    def __init__(self, element_ids, edges, pfevent):
        '''
            element_ids:  list of the uniqueids of the elements to go in this block [id1,id2,...]
            edges: is a dictionary of edges, it must contain at least all needed edges.
                   It is not a problem if it contains
                   additional edges as only the ones needed will be extracted
            pfevent: allows access to the underlying elements given a uniqueid
                     must provide a get_object function
        '''
        #make a uniqueid for this block
        self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.BLOCK)
        self.is_active = True  # if a block is subsequently split it will be deactivated

        #allow access to the underlying objects
        self.pfevent = pfevent

        #comment out energy sorting  for now as not available C++
        sortby = lambda x: Identifier.type_short_code(x)
        self.element_uniqueids = sorted(element_ids, key=sortby)
        #sequential numbering of blocks, not essential but helpful for debugging
        self.block_count = PFBlock.temp_block_count
        PFBlock.temp_block_count += 1

        #extract the relevant parts of the complete set of edges and store this within the block
        self.edges = dict()
        for id1, id2 in itertools.combinations(self.element_uniqueids, 2):
            key = Edge.make_key(id1, id2)
            self.edges[key] = edges[key]
Ejemplo n.º 7
0
    def __init__(self, element_ids, edges, subtype):
        ''' 
            element_ids:  list of the uniqueids of the elements to go in this block [id1,id2,...]
            edges: is a dictionary of edges, it must contain at least all needed edges.
                   It is not a problem if it contains
                   additional edges as only the ones needed will be extracted
            subtype: used when making unique identifier, will normally be 'r' for reconstructed blocks and 's' for split blocks
           
        '''
        #make a uniqueid for this block
        self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.BLOCK,
                                           subtype)
        self.element_uniqueids = sorted(
            element_ids, key=lambda x: Identifier.type_letter(x))

        #comment out energy sorting  for now as not available C++
        sortby = lambda x: Identifier.type_letter(x)
        self.element_uniqueids = sorted(element_ids, key=sortby)
        #sequential numbering of blocks, not essential but helpful for debugging
        self.block_count = PFBlock.temp_block_count
        PFBlock.temp_block_count += 1

        #extract the relevant parts of the complete set of edges and store this within the block
        self.edges = dict()
        for id1, id2 in itertools.combinations(self.element_uniqueids, 2):
            key = Edge.make_key(id1, id2)
            self.edges[key] = edges[key]
Ejemplo n.º 8
0
 def __init__(self, id, pdgid):
     ''' id is unique integer from 601-699
         pdgid is particle id eg 22 for photon
     '''
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.RECPARTICLE)
     self.pdgid = pdgid
     self.id = id
 def __init__(self, uid,pdgid):
     ''' uid is unique integer from 601-699
         pdgid is particle uid eg 22 for photon
     '''
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.PARTICLE,  uid,'r')
     self.pdgid = pdgid
     self.uid = uid
Ejemplo n.º 10
0
 def __init__(self, id):
     ''' id is unique integer from 1-99
     '''
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK)
     self.id = id
     self.layer = 'tracker'
     self.energy = 0
Ejemplo n.º 11
0
 def __init__(self, element_ids, edges, pfevent): 
     ''' 
         element_ids:  list of the uniqueids of the elements to go in this block [id1,id2,...]
         edges: is a dictionary of edges, it must contain at least all needed edges. It is not a problem if it contains
                additional edges as only the ones needed will be extracted
         pfevent: allows access to the underlying elements given a uniqueid 
                  must provide a get_object function
     '''
     #make a uniqueid for this block
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.BLOCK) 
     self.is_active = True # if a block is subsequently split it will be deactivated
     
     #allow access to the underlying objects
     self.pfevent=pfevent        
     
     #order the elements by element type (ecal, hcal, track) and then by energy
     #this is a bit yucky but needed to make sure the order returned is consistent
     #maybe should live outside of this class        
     self.element_uniqueids = sorted(element_ids, key = lambda  x: (Identifier.type_short_code(x),-self.pfevent.get_object(x).energy) )
     
     #sequential numbering of blocks, not essential but helpful for debugging
     self.block_count = PFBlock.temp_block_count
     PFBlock.temp_block_count += 1
     
     #extract the relevant parts of the complete set of edges and store this within the block
     self.edges = dict()
     for id1, id2 in itertools.combinations(self.element_uniqueids,2):
         key = Edge.make_key(id1,id2)
         self.edges[key] = edges[key]
Ejemplo n.º 12
0
 def __init__(self, id,pdgid):
     ''' id is unique integer from 601-699
         pdgid is particle id eg 22 for photon
     '''
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.RECPARTICLE)
     self.pdgid = pdgid
     self.id = id
Ejemplo n.º 13
0
    def __init__(self, pfobjecttype=Identifier.PFOBJECTTYPE.NONE):
   #def __init__(self):
        super(PFObject, self).__init__()

        self.linked = []
        self.locked = False
        self.block_label = None
        self.uniqueid = Identifier.make_id(pfobjecttype)
Ejemplo n.º 14
0
    def __init__(self, pfobjecttype=Identifier.PFOBJECTTYPE.NONE):
        #def __init__(self):
        super(PFObject, self).__init__()

        self.linked = []
        self.locked = False
        self.block_label = None
        self.uniqueid = Identifier.make_id(pfobjecttype)
Ejemplo n.º 15
0
 def __init__(self, id, pdgid):
     ''' id is unique integer from 301-399
         pdgid is particle id eg 22 for photon
     '''
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.PARTICLE)
     #print "particle: ",self.uniqueid," ",id
     self.pdgid = pdgid
     self.id = id
Ejemplo n.º 16
0
 def __init__(self, id, pdgid):
     ''' id is unique integer from 301-399
         pdgid is particle id eg 22 for photon
     '''
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.PARTICLE)
     #print "particle: ",self.uniqueid," ",id
     self.pdgid = pdgid
     self.id = id
Ejemplo n.º 17
0
 def __init__(self, pfobjecttype, index, subtype='u', identifiervalue = 0.0):
     '''@param pfobjecttype: type of the object to be created (used in Identifier class) eg Identifier.PFOBJECTTYPE.ECALCLUSTER
        @param subtype: Identifier subtype, eg 'm' for merged
        @param identifiervalue: The value to be encoded into the Identifier eg energy or pt
 '''
     super(PFObject, self).__init__()
     self.linked = []
     self.locked = False
     self.block_label = None
     self.uniqueid=Identifier.make_id(pfobjecttype, index, subtype, identifiervalue)
Ejemplo n.º 18
0
 def __init__(self, pfobjecttype, index, subtype='u', identifiervalue = 0.0):
     '''@param pfobjecttype: type of the object to be created (used in Identifier class) eg Identifier.PFOBJECTTYPE.ECALCLUSTER
        @param subtype: Identifier subtype, eg 'm' for merged
        @param identifiervalue: The value to be encoded into the Identifier eg energy or pt
 '''
     super(PFObject, self).__init__()
     self.linked = []
     self.locked = False
     self.block_label = None
     self.uniqueid=Identifier.make_id(pfobjecttype, index, subtype, identifiervalue)
Ejemplo n.º 19
0
 def __init__(self, tlv, vertex, charge, pdgid=None, subtype='s'):
     self.subtype = subtype
     super(Particle, self).__init__(pdgid, charge, tlv)
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.PARTICLE,
                                        subtype)
     self.vertex = vertex
     self.path = None
     self.clusters = dict()
     self.track = None  # to match cpp
     self.clusters_smeared = dict()
     self.track_smeared = None
Ejemplo n.º 20
0
 def __init__(self, tlv, vertex, charge,
              pdgid=None,
              ParticleType=Identifier.PFOBJECTTYPE.PARTICLE):
     super(Particle, self).__init__(pdgid, charge, tlv)
     self.uniqueid = Identifier.make_id(ParticleType)
     self.vertex = vertex
     self.path = None
     self.clusters = dict()
     self.track = None # Alice Experiment to match cpp debug Track(self.p3(), self.q(), self.path)
     self.clusters_smeared = dict()
     self.track_smeared = None
Ejemplo n.º 21
0
    def test_papasevent(self):
        papasevent = PapasEvent(0)
        ecals = dict()
        tracks = dict()
        mixed = dict()

        for i in range(0, 2):
            uid = Identifier.make_id(Identifier.PFOBJECTTYPE.ECALCLUSTER, i,
                                     't', 4.5)
            ecals[uid] = uid
        for i in range(0, 2):
            uid = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK, i, 's',
                                     4.5)
            tracks[uid] = uid

        lastid = Identifier.make_id(Identifier.PFOBJECTTYPE.ECALCLUSTER, 3,
                                    't', 3)
        ecals[lastid] = lastid

        papasevent.add_collection(ecals)
        papasevent.add_collection(tracks)

        #check that adding the same collection twice fails
        self.assertRaises(ValueError, papasevent.add_collection, ecals)

        #check that adding a mixed collection fails
        mixed = ecals.copy()
        mixed.update(tracks)
        self.assertRaises(ValueError, papasevent.add_collection, mixed)

        #get we can get back collections OK
        self.assertTrue(len(
            papasevent.get_collection('zz')) == 0)  # this one does not exist
        self.assertTrue(len(papasevent.get_collection('et')) == 3)

        #check get_object
        self.assertTrue(
            Identifier.pretty(papasevent.get_object(lastid)) == 'et3')
        self.assertTrue(papasevent.get_object(499) is None)
Ejemplo n.º 22
0
 def __init__(self,
              tlv,
              vertex,
              charge,
              pdgid=None,
              ParticleType=Identifier.PFOBJECTTYPE.PARTICLE):
     super(Particle, self).__init__(pdgid, charge, tlv)
     self.uniqueid = Identifier.make_id(ParticleType)
     self.vertex = vertex
     self.path = None
     self.clusters = dict()
     self.track = None  # Alice Experiment to match cpp debug Track(self.p3(), self.q(), self.path)
     self.clusters_smeared = dict()
     self.track_smeared = None
Ejemplo n.º 23
0
 def __init__(self, fccobj):
     super(Particle, self).__init__(fccobj)
     self.uniqueid=Identifier.make_id(Identifier.PFOBJECTTYPE.PARTICLE)
     self._charge = fccobj.core().charge
     self._pid = fccobj.core().pdgId
     self._status = fccobj.core().status
     if hasattr(fccobj, 'startVertex'):
         start = fccobj.startVertex()
         self._start_vertex = Vertex(start) if start.isAvailable() \
                              else None 
         end = fccobj.endVertex()
         self._end_vertex = Vertex(end) if end.isAvailable() \
                            else None 
     self._tlv = TLorentzVector()
     p4 = fccobj.core().p4
     self._tlv.SetXYZM(p4.px, p4.py, p4.pz, p4.mass)
Ejemplo n.º 24
0
 def __init__(self, tlv, vertex, charge, index=0, pdgid=None, subtype='s'):
     self.subtype = subtype
     super(Particle, self).__init__(pdgid, charge, tlv)
     
 #allow the value used in the particle unique id to depend on the collider type
     idvalue = 0.
     if Collider.BEAMS == 'ee':
         idvalue=self.e()
     else:
         idvalue=self.pt()
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.PARTICLE, index, subtype, idvalue)
     self.vertex = vertex
     self.path = None
     self.clusters = dict()
     self.track = None # to match cpp 
     self.clusters_smeared = dict()
     self.track_smeared = None
Ejemplo n.º 25
0
 def __init__(self, tlv, vertex, charge, index=0, pdgid=None, subtype='s'):
     self.subtype = subtype
     super(Particle, self).__init__(pdgid, charge, tlv)
     
 #allow the value used in the particle unique id to depend on the collider type
     idvalue = 0.
     if Collider.BEAMS == 'ee':
         idvalue=self.e()
     else:
         idvalue=self.pt()
     self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.PARTICLE, index, subtype, idvalue)
     self.vertex = vertex
     self.path = None
     self.clusters = dict()
     self.track = None # to match cpp 
     self.clusters_smeared = dict()
     self.track_smeared = None
Ejemplo n.º 26
0
    def __init__(self, element_ids, edges, index, subtype):
        ''' 
            @param element_ids:  list of the uniqueids of the elements to go in this block [id1,id2,...]
            @param edges: is a dictionary of edges, it must contain at least all needed edges.
                   It is not a problem if it contains
                   additional edges as only the ones needed will be extracted
            @param index: index into the collection of blocks into which new block will be added
            @param subtype: used when making unique identifier, will normally be 'r' for reconstructed blocks and 's' for split blocks
           
        '''
        #make a uniqueid for this block
        self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.BLOCK,
                                           index, subtype, len(element_ids))
        #this will sort by type eg ecal, hcal, track and then by energy (biggest first)
        self.element_uniqueids = sorted(element_ids, reverse=True)
        #sequential numbering of blocks, not essential but helpful for debugging
        self.block_count = PFBlock.temp_block_count
        PFBlock.temp_block_count += 1

        #extract the relevant parts of the complete set of edges and store this within the block
        self.edges = dict()
        for id1, id2 in itertools.combinations(self.element_uniqueids, 2):
            key = Edge.make_key(id1, id2)
            self.edges[key] = edges[key]
Ejemplo n.º 27
0
    def __init__(self, element_ids, edges, index, subtype): 
        ''' 
            @param element_ids:  list of the uniqueids of the elements to go in this block [id1,id2,...]
            @param edges: is a dictionary of edges, it must contain at least all needed edges.
                   It is not a problem if it contains
                   additional edges as only the ones needed will be extracted
            @param index: index into the collection of blocks into which new block will be added
            @param subtype: used when making unique identifier, will normally be 'r' for reconstructed blocks and 's' for split blocks
           
        '''
        #make a uniqueid for this block
        self.uniqueid = Identifier.make_id(Identifier.PFOBJECTTYPE.BLOCK, index, subtype, len(element_ids))
        #this will sort by type eg ecal, hcal, track and then by energy (biggest first)
        sortby = lambda x: (Identifier.type_letter(x), -Identifier.get_value(x))
        self.element_uniqueids = sorted(element_ids, key=sortby)
        #sequential numbering of blocks, not essential but helpful for debugging
        self.block_count = PFBlock.temp_block_count
        PFBlock.temp_block_count += 1

        #extract the relevant parts of the complete set of edges and store this within the block
        self.edges = dict()
        for id1, id2 in itertools.combinations(self.element_uniqueids, 2):
            key = Edge.make_key(id1, id2)
            self.edges[key] = edges[key]