Exemple #1
0
    def readEvent(self):
        
        runNumber = self._lcioReader.getNumberOfRuns()

        try:
              self._event = self._lcioReader.next()
        except:
              return None

        evtNum = self._event.getEventNumber()

        pfoTargetCandidates = []

        hits = self._event.getCollection('SDHcalCollection')
        nHits = hits.getNumberOfElements()
        cellIdEncoding = hits.getParameters().getStringVal( EVENT.LCIO.CellIDEncoding )
        idDecoder = UTIL.BitField64( cellIdEncoding )

        print 'Event : ', evtNum, ', # of SDHCAL hits: ', nHits

        hitsLayer = []

        for iHit in range(0, nHits):
            hit = hits.getElementAt( iHit )
            cellID = long( hit.getCellID0() & 0xffffffff ) | ( long( hit.getCellID1() ) << 32 )
            idDecoder.setValue( cellID )
            layer = int( idDecoder['K'].value() )
            hitsLayer.append( layer )

            #print 'hit layer: %d' % (layer)

        return self._event, hitsLayer
Exemple #2
0
def readEvent():
    for event in reader:
        allHitPos = []

        hcalHits = event.getCollection('HCALOther')
        evtNum = event.getEventNumber()

        nHit = hcalHits.getNumberOfElements()
        cellIdEncoding = hcalHits.getParameters().getStringVal(
            EVENT.LCIO.CellIDEncoding)
        idDecoder = UTIL.BitField64(cellIdEncoding)

        for iHit in range(0, nHit):
            caloHit = hcalHits.getElementAt(iHit)
            pos = caloHit.getPositionVec()
            cellID = long(caloHit.getCellID0()
                          & 0xffffffff) | (long(caloHit.getCellID1()) << 32)
            idDecoder.setValue(cellID)
            layer = idDecoder['layer'].value()

            allHitPos.append([pos[0], pos[1], pos[2]])

        evt = drawPoint(allHitPos, evtNum)
        text = raw_input('press any key to exit: ')

        if text == '':
            evt.DisableListElements()
        else:
            print 'exit'
            break
Exemple #3
0
def get_pos(event):  # start position of each particle

    # get a hit collection
    BCAL = event.getCollection("BeamCalHits")

    # get the cell ID encoding string from the collection parameters
    cellIdEncoding = BCAL.getParameters().getStringVal(
        EVENT.LCIO.CellIDEncoding)

    # define a cell ID decoder for the collection
    idDecoder = UTIL.BitField64(cellIdEncoding)
    for calhit in BCAL:

        # combine the two 32 bit cell IDs of the hit into one 64 bit integer
        cellID = long(calhit.getCellID0()
                      & 0xffffffff) | (long(calhit.getCellID1()) << 32)

        # set up the ID decoder for this cell ID
    idDecoder.setValue(cellID)

    # access the field information using a valid field from the cell ID encoding string
    print 'x:', idDecoder['x'].value()
    print 'y:', idDecoder['y'].value()
    # can put 'barrel' , 'layer' instead of 'x' and 'y' to get those values

    a = TNtuple("a", "cell", "layer")
Exemple #4
0
def layerNos(nmbEvents,inFile):
    layerNosH=[0]*nmbEvents
    layerNos=[0]*nmbEvents
    for i in range(nmbEvents):
        layerNos[i]=[]
        layerNosH[i]=[]

    #create a reader
    readerL = LcioReader(inFile )
    eventNo=-1
    # loop over the events
    for event in readerL:
        eventNo+=1
        if eventNo%100==0:
            print "recording layers of event "+str(eventNo)
        # get a hit collection
        hcalHits = event.getCollection( 'HCalBarrelHits' )
        ecalHits = event.getCollection( 'ECalBarrelHits' )
        # get the cell ID encoding string from the collection parameters
        cellIdEncoding = ecalHits.getParameters().getStringVal( EVENT.LCIO.CellIDEncoding )
        cellIdEncodingH = hcalHits.getParameters().getStringVal( EVENT.LCIO.CellIDEncoding )
        # define a cell ID decoder for the collection
        idDecoder = UTIL.BitField64( cellIdEncoding )
        idDecoderH = UTIL.BitField64( cellIdEncodingH )
        # loop over all hits in the collection
        for caloHit in ecalHits:
            # combine the two 32 bit cell IDs of the hit into one 64 bit integer
            cellID = long( caloHit.getCellID0() & 0xffffffff ) | ( long( caloHit.getCellID1() ) << 32 )
            # set up the ID decoder for this cell ID
            idDecoder.setValue( cellID )
            # access the field information using a valid field from the cell ID encoding string
            layerNos[eventNo].append(idDecoder['layer'].value())
        for caloHitH in hcalHits:
            cellIDH=long(caloHitH.getCellID0() & 0xffffffff)|(long(caloHitH.getCellID1())<<32)
            idDecoderH.setValue(cellIDH)
            layerNosH[eventNo].append(idDecoderH['layer'].value())

    return layerNosH, layerNos
Exemple #5
0
eventNo = -1
# loop over the events
for event in readerL:
    eventNo += 1
    if eventNo % 100 == 0:
        print "recording layers of event " + str(eventNo)
#    print eventNo
# get a hit collection
    ecalHits = event.getCollection('ECalBarrelHits')
    # get the cell ID encoding string from the collection parameters
    cellIdEncoding = ecalHits.getParameters().getStringVal(
        EVENT.LCIO.CellIDEncoding)
    #    print cellIdEncoding
    # define a cell ID decoder for the collection
    idDecoder = UTIL.BitField64(cellIdEncoding)
    # loop over all hits in the collection
    for caloHit in ecalHits:
        # combine the two 32 bit cell IDs of the hit into one 64 bit integer
        cellID = long(caloHit.getCellID0()
                      & 0xffffffff) | (long(caloHit.getCellID1()) << 32)
        # set up the ID decoder for this cell ID
        idDecoder.setValue(cellID)
        # access the field information using a valid field from the cell ID encoding string
        #        print 'layer:', idDecoder['layer'].value()
        layerNos[eventNo].append(idDecoder['layer'].value())

###############################################################################

# create a reader and open an LCIO file
reader = IOIMPL.LCFactory.getInstance().createLCReader()
Exemple #6
0
def getEnergies(path_to_file, outfile, openingAngleCut):

    idDecoder = UTIL.BitField64(
        "system:5,side:2,module:8,stave:4,layer:9,submodule:4,x:32:-16,y:-16")
    idDecoderHCAL = UTIL.BitField64(
        "system:5,side:2,module:8,stave:4,layer:9,submodule:4,x:32:-16,y:-16")

    fil = ROOT.TFile.Open(str(path_to_file), "read")
    iEvt = 0

    # We make an empty list of events
    event_list = []

    for event in fil.EVENT:

        openingAngle = -1  # default if there is no pi0 -> /gamma/gamma

        if (len(event.MCParticles) >= 3 and event.MCParticles[0].pdgID == 111
                and event.MCParticles[1].pdgID == 22
                and event.MCParticles[2].pdgID == 22):

            gamma1px = event.MCParticles[1].psx
            gamma1py = event.MCParticles[1].psy
            gamma1pz = event.MCParticles[1].psz
            gamma2px = event.MCParticles[2].psx
            gamma2py = event.MCParticles[2].psy
            gamma2pz = event.MCParticles[2].psz

            cos_theta = (gamma1px * gamma2px + gamma1py * gamma2py +
                         gamma1pz * gamma2pz) / math.sqrt(
                             (gamma1px * gamma1px + gamma1py * gamma1py +
                              gamma1pz * gamma1pz) *
                             (gamma2px * gamma2px + gamma2py * gamma2py +
                              gamma2pz * gamma2pz))
            openingAngle = math.acos(cos_theta)

        if (~openingAngleCut or (openingAngle < 0.01 and openingAngle != -1)
            ):  # either require opening angle cut of 0.01 or allow everything

            # We make an empty list of hits (within this event)
            hit_list = []
            hit_listHCAL = []

            iEvt = iEvt + 1

            # Read HCAL
            for i in range(len(event.HCalBarrelCollection)):
                idDecoderHCAL.setValue(event.HCalBarrelCollection[i].cellID)

                z = idDecoderHCAL['layer'].value()
                x = idDecoderHCAL['x'].value()
                y = idDecoderHCAL['y'].value()
                E = event.HCalBarrelCollection[i].energyDeposit
                pos = event.HCalBarrelCollection[i].position
                hit_listHCAL.append(
                    (int(x), int(y), int(z), E, pos.X(), pos.Y(), pos.Z()))

            # Read ECAL
            for i in range(len(event.ECalBarrelCollection)):

                #print event.ECalBarrelCollection.getParameters()
                idDecoder.setValue(event.ECalBarrelCollection[i].cellID)

                z = idDecoder['layer'].value()
                x = idDecoder['x'].value()
                y = idDecoder['y'].value()
                E = event.ECalBarrelCollection[i].energyDeposit
                pos = event.ECalBarrelCollection[i].position
                if (z < 25):
                    hit_list.append(
                        (int(x), int(y), int(z), E, pos.X(), pos.Y(), pos.Z()))

            # Read energy
            gunpx = event.MCParticles[0].psx
            gunpy = event.MCParticles[0].psy
            gunpz = event.MCParticles[0].psz
            m = event.MCParticles[0].mass
            gunE = ROOT.TMath.Sqrt(m * m + gunpx * gunpx + gunpy * gunpy +
                                   gunpz * gunpz)
            pdgID = event.MCParticles[0].pdgID

            photon_conversion_num = 0
            for i in range(len(event.MCParticles)):
                if (event.MCParticles[i].pdgID == -11):
                    positron_px = event.MCParticles[i].psx
                    positron_py = event.MCParticles[i].psy
                    positron_pz = event.MCParticles[i].psz
                    positron_m = event.MCParticles[i].mass
                    positron_E = ROOT.TMath.Sqrt(positron_m * positron_m +
                                                 positron_px * positron_px +
                                                 positron_py * positron_py +
                                                 positron_pz * positron_pz)
                    for j in range(len(event.MCParticles)):
                        if (event.MCParticles[j].pdgID == 11
                                and event.MCParticles[j].vsx
                                == event.MCParticles[i].vsx
                                and event.MCParticles[j].vsy
                                == event.MCParticles[i].vsy
                                and event.MCParticles[j].vsz
                                == event.MCParticles[i].vsz):

                            electron_px = event.MCParticles[j].psx
                            electron_py = event.MCParticles[j].psy
                            electron_pz = event.MCParticles[j].psz
                            electron_m = event.MCParticles[j].mass
                            electron_E = ROOT.TMath.Sqrt(
                                electron_m * electron_m +
                                electron_px * electron_px +
                                electron_py * electron_py +
                                electron_pz * electron_pz)

                            #if((positron_E + electron_E) > (ROOT.TMath.Sqrt(electron_m*electron_m+10)+ROOT.TMath.Sqrt(positron_m*positron_m +10))):
                            if ((positron_E + electron_E) > 1000):
                                photon_conversion_num += 1

            event_list.append({
                'pdgID': pdgID,
                'E': gunE,
                'px': gunpx,
                'py': gunpy,
                'pz': gunpz,
                'conversion': photon_conversion_num,
                'ECAL': hit_list,
                'HCAL': hit_listHCAL,
                'openingAngle': openingAngle
            })

            print(len(hit_list), len(hit_listHCAL))

    # Append this event to the event list
    text_file = open(outfile, "w")
    for evt in event_list:
        text_file.write(str(evt) + "\n")
    text_file.close()
def readEvent():
    for event in reader:
        allHitPos = []

        hcalHits = event.getCollection('HCALOther')
        evtNum   = event.getEventNumber()

        nHit = hcalHits.getNumberOfElements()
        cellIdEncoding = hcalHits.getParameters().getStringVal( EVENT.LCIO.CellIDEncoding ) 
        idDecoder = UTIL.BitField64( cellIdEncoding )

        for iHit in range(0, nHit):
            caloHit = hcalHits.getElementAt( iHit )
            pos = caloHit.getPositionVec()
            cellID = long( caloHit.getCellID0() & 0xffffffff ) | ( long( caloHit.getCellID1() ) << 32 )
            idDecoder.setValue( cellID )
            layer = idDecoder['layer'].value()

            allHitPos.append( [pos[0], pos[1], pos[2]] )

        quantile = 0.025

        Xdata = StandardScaler().fit_transform(allHitPos)
        bandwidth = cluster.estimate_bandwidth(Xdata, quantile=quantile)
        ms = cluster.MeanShift(bandwidth=bandwidth, bin_seeding=True)
        ms.fit(Xdata)
        y_pred = ms.labels_.astype(np.int)
        hitClusters = list(y_pred)
        
        clustersSelected = []
        
        iClu = 0
        minClusterSize = 0
        maxClusterSize = 10000
        
        while True:
            hitsNum = hitClusters.count(iClu)
        
            if hitsNum == 0:
                break
        
            allHits = len(hitClusters)
        
            idx = [i for i in range(allHits) if hitClusters[i] == iClu]
        	
            printOut = False

            if printOut:
                print '----> Cluster ', iClu, ': hits number: ', hitsNum, ' =================== '
                print idx, '\n'
        
        	###########################################
        	# select clusters to show by hit number
        	###########################################
            if hitsNum > minClusterSize and hitsNum < maxClusterSize:
                hitCluster = [allHitPos[i] for i in idx]
                clustersSelected.append( hitCluster )
        
            iClu = iClu + 1
    
    ###########################################

        evt = drawClusters(clustersSelected, evtNum)
        #evt = drawPoints(allHitPos, evtNum)
        text = raw_input('press any key to exit: ')

        if text == '':
            evt.DisableListElements()
            #print 'next event'
        else:
            print 'exit'
            break