Exemplo n.º 1
0
def main():
    global beamEnergy
    # Parse all command line arguments using the argparse module.
    parser = argparse.ArgumentParser(
        description='PyRoot analysis demostrating the us of a DST.')
    parser.add_argument("dst_file", help="ROOT DST file to process")
    parser.add_argument("-o", "--output", help="Name of output pdf file")
    parser.add_argument("-m", "--mc", help="is MonteCarlo")
    parser.add_argument("-p", "--pulser", help="is Pulser")
    parser.add_argument("-e", "--energy", help="beam energy")
    args = parser.parse_args()

    # If an output file name was not specified, set a default name and warn
    # the user
    if args.output:
        output_file = args.output
    else:
        output_file = "analysis_output.root"
        print "[ HPS ANALYSIS ]: An output file name was not specified. Setting the name to "
        print output_file

    print "[ HPS ANALYSIS ]:  Output file is " + output_file
    isMC = False
    if args.mc:
        print "[ HPS ANALYSIS ]: Setting to run as MC"
        isMC = True

    isPulser = False
    if args.pulser:
        print "[ HPS ANALYSIS ]: Setting to run from a pulser file"
        isPulser = True

    if args.energy:
        print 'Setting beam energy to ' + args.energy
        beamEnergy = float(args.energy)
        myhist.setEnergyScales(beamEnergy)

#################################
#       Event Selection
################################
#clean up event first
#### nominal selection
    nTrkMax = 3
    nTrkMin = 3
    nPosMax = 1
    ######  two tracks (e+/e-) exactly
    #    nTrkMax=2
    #    nTrkMin=2
    #    nPosMax=1
    ###### more than 1 electron
    #    nTrkMax=10
    #    nTrkMin=3
    #    nPosMax=1
    ###################
    maxSharedHits = 2
    #v0 cuts
    #    v0Chi2=10
    v0Chi2 = 99999999.0
    #ESum -- full region
    v0PzMax = 1.2 * beamEnergy
    v0PzMin = 0.1 * beamEnergy
    #ESum -- Radiative region
    #    v0PzMax=1.2
    #    v0PzMin=0.80

    v0PyMax = 0.2  #absolute value
    v0PxMax = 0.2  #absolute value
    v0VzMax = 25.0  # mm from target
    #    v0VyMax=1.0# mm from target
    v0VyMax = 6666.0  # mm from target
    v0VxMax = 2.0  # mm from target
    #  track quality cuts
    trkChi2 = 10
    beamCut = 0.8 * beamEnergy
    minPCut = 0.05
    trkPyMax = 0.2
    trkPxMax = 0.2
    #    slopeCut=0.03
    slopeCut = 0.0
    trkDeltaT = 4  #ns
    cluDeltaT = 2  #ns
    cluTrkDeltaT = 4  #ns
    ##############
    #  ESum slices; upper limits
    nSlicesESum = 5
    esumMin = 0.55
    esumMax = 1.2
    sliceSizeESum = 0.1  #100MeV starting at esumMin
    ##############
    trackKiller = False
    tkThreshold = 0.5  #GeV, below this start killing tracks
    tkThreshEff = 1.0
    tkLowPoint = 0.20
    tkLowPointEff = 0.40
    #    tkSlope=2.6
    #    tkIntercept=-0.04
    #calculate tkSlope and Intercept
    tkSlope = (tkThreshEff - tkLowPointEff) / (tkThreshold - tkLowPoint)
    tkIntercept = tkThreshEff - tkSlope * tkThreshold

    ##############
    requireECalMatch = True
    requireECalFiducial = True
    requireECalSuperFiducial = False
    useGBL = True

    # Open the ROOT file
    #    root_file = ROOT.TFile(str(args.dst_file))
    # Get the TTree "HPS_EVENT" containing the HpsEvent branch and all
    # other colletions
    #    tree = root_file.Get("HPS_Event")
    #use a TChain
    print "[ HPS ANALYSIS ]: Reading in root chain from " + args.dst_file
    tree = ROOT.TChain("HPS_Event")
    tree.Add(str(args.dst_file) + "*")
    # Create an HpsEvent object in order to read the TClonesArray
    # collections
    hps_event = HpsEvent()

    b_hps_event = tree.SetBranchAddress("Event", ROOT.AddressOf(hps_event))

    #--- Analysis ---#
    #----------------#

    #counters
    nEvents = 0
    nPassBasicCuts = 0
    nPassV0Cuts = 0
    nPassTrkCuts = 0
    nPassNCand = 0
    nPassECalMatch = 0
    nFakeTri = 0
    nTwoCand = 0
    seedCnt = 0
    # Loop over all events in the file
    for entry in xrange(0, tree.GetEntries()):

        # Print the event number every 500 events
        if (entry + 1) % 10000 == 0: print "Event " + str(entry + 1)
        tree.GetEntry(entry)
        if not hps_event.isPair1Trigger() and not isMC and not isPulser:
            continue
        nEvents += 1
        addFakeEle = False

        # Loop over all tracks in the event
        npositrons = 0
        n_tracks = 0
        for track_n in xrange(0, hps_event.getNumberOfTracks()):
            track = hps_event.getGblTrack(track_n)
            if track is None:
                continue
#            print track.getParticle().getType()
            if trkMatchAndFiducial(
                    track.getParticle(),
                    requireECalSuperFiducial) and trkMomentum(
                        track, minPCut, beamCut
                    ):  # count only matched tracks in defined fiducial region
                n_tracks += 1
                if track.getCharge() > 0:
                    npositrons += 1
                    myhist.rawposMom.Fill(pMag(track.getMomentum()))
                else:
                    myhist.raweleMom.Fill(pMag(track.getMomentum()))
#                    findWABPair(track.getParticle(),hps_event)

#        print "nTracks = "+str(n_tracks)+"; nPositrons = "+str(npositrons)
#        if n_tracks/2.0>nTrkMax : continue   #do this very dumb thing (divide by 2 to un-double count GBL tracks)
#        if n_tracks/2.0<2:  continue
        myhist.nTrk.Fill(n_tracks)
        myhist.nPos.Fill(npositrons)
        myhist.nEle.Fill(n_tracks - npositrons)
        myhist.nClust.Fill(hps_event.getNumberOfEcalClusters())

        if n_tracks > nTrkMax: continue
        if n_tracks < nTrkMin: continue
        if npositrons < 1 or npositrons > nPosMax: continue
        nPassBasicCuts += 1
        #        print "passed basic cuts"
        candidateList = []
        bestCandidate = -99
        nCandidate = 0
        # loop over all v0 candidates...
        for uc_index in xrange(
                0,
                hps_event.getNumberOfParticles(HpsParticle.UC_V0_CANDIDATE)):
            particle = hps_event.getParticle(HpsParticle.UC_V0_CANDIDATE,
                                             uc_index)
            #            print "Particle Type = "+ str(particle.getType())
            if useGBL and particle.getType() < 32: continue
            if not useGBL and particle.getType() > 31: continue
            #            print "found one..."
            vchi2 = particle.getVertexFitChi2()
            vposition = particle.getVertexPosition()
            vmomentum = particle.getMomentum()
            if vchi2 > v0Chi2: continue
            # use the measured sum of momentum
            #            if vmomentum[2]>v0PzMax : continue
            #            if vmomentum[2]<v0PzMin : continue
            #recon'ed vertex position cuts
            if abs(vposition[0]) > v0VxMax: continue
            if abs(vposition[1]) > v0VyMax: continue

            #            if abs(vposition[2])>v0VzMax :continue
            # Only look at particles that have two daugther particles...
            daughter_particles = particle.getParticles()
            if daughter_particles.GetSize() != 2: continue
            # Only look at particles that are composed of e+e- pairs
            if daughter_particles.At(0).getCharge() * daughter_particles.At(
                    1).getCharge() > 0:
                continue
            #            print "Passed daughter number cuts"

            electron = daughter_particles.At(0)
            positron = daughter_particles.At(1)

            if daughter_particles.At(0).getCharge() > 0:
                electron = daughter_particles.At(1)
                positron = daughter_particles.At(0)

            pEle = electron.getMomentum()
            pPos = positron.getMomentum()

            v0Sum = pMag(pSum(pEle, pPos))
            #total momentum sum cuts
            if v0Sum > v0PzMax: continue
            if v0Sum < v0PzMin: continue
            nPassV0Cuts += 1
            #            print "Passed v0 cuts"
            #############   tracking cuts
            #momentum cuts...get rid of very soft or very hard tracks
            if pMag(pEle) > beamCut or pMag(pPos) > beamCut: continue
            if pMag(pEle) < minPCut or pMag(pPos) < minPCut: continue
            #top+bottom requirement
            if pEle[1] * pPos[1] > 0: continue

            #            print 'looking at tracks now'
            #            print len(electron.getTracks())

            if len(electron.getTracks()) == 0 or len(
                    positron.getTracks()) == 0:
                continue
            eleTrk = electron.getTracks().At(0)
            posTrk = positron.getTracks().At(0)
            if eleTrk is None or posTrk is None: continue
            #            eleTrk.Print("v")
            #track timing
            if eleTrk.getTrackTime() - posTrk.getTrackTime() > trkDeltaT:
                continue
            #track slope (if any cut)
            if abs(eleTrk.getTanLambda()) < slopeCut or abs(
                    posTrk.getTanLambda()) < slopeCut:
                continue
#            print 'satisfied timing cuts...'

##############
            nPassTrkCuts += 1

            ##############
            #   ECAL matching and timing cuts...also fiducial region cuts...
            if requireECalMatch:
                if positron.getClusters().GetEntries() == 0:
                    continue
                if electron.getClusters().GetEntries() == 0:
                    continue
                posCluster = positron.getClusters().First()
                eleCluster = electron.getClusters().First()

                if eleCluster.getClusterTime() - posCluster.getClusterTime(
                ) > cluDeltaT:
                    continue

                if eleTrk.getTrackTime() - eleCluster.getClusterTime(
                ) + 43.5 > cluTrkDeltaT:
                    continue

                if posTrk.getTrackTime() - posCluster.getClusterTime(
                ) + 43.5 > cluTrkDeltaT:
                    continue

                if requireECalFiducial:
                    #ANTI-fiducial cut
                    #                    if  myhist.inFiducialRegion(posCluster.getPosition()[0],posCluster.getPosition()[1]) :
                    #                        continue
                    #                    if  myhist.inFiducialRegion(eleCluster.getPosition()[0],eleCluster.getPosition()[1]) :
                    #                        continue
                    #Fiducial cut
                    if not myhist.inFiducialRegion(
                            posCluster.getPosition()[0],
                            posCluster.getPosition()[1]):
                        continue
                    if not myhist.inFiducialRegion(
                            eleCluster.getPosition()[0],
                            eleCluster.getPosition()[1]):
                        continue
                if requireECalSuperFiducial:
                    if not myhist.inSuperFiducialRegion(
                            posCluster.getPosition()[0],
                            posCluster.getPosition()[1]):
                        continue
                    if not myhist.inSuperFiducialRegion(
                            eleCluster.getPosition()[0],
                            eleCluster.getPosition()[1]):
                        continue
            nPassECalMatch += 1
            ##############
            #Passed the cuts..append the candidate index
            candidateList.append(particle)

        numCands = len(candidateList)

        myhist.nCand.Fill(numCands)
        if numCands != 2:
            continue  #require 2 candidates...probably have to rethink this.

        print 'found 2 candidates'

        cand0 = candidateList[0]  # take this as base candidate
        candpos = cand0.getParticles().At(0)
        candele = cand0.getParticles().At(1)
        if candpos.getCharge() < 0:
            candpos = cand0.getParticles().At(1)
            candele = cand0.getParticles().At(0)
#            print "swapping cand"
        cand1 = candidateList[1]  # get the recoil electron from this
        recoil = cand1.getParticles().At(0)
        recpos = cand1.getParticles().At(1)
        if recoil.getCharge() > 0:
            #            print "swapping recoil"
            recoil = cand1.getParticles().At(1)
            recpos = cand1.getParticles().At(0)
#        print 'Positron p' +str(pMag(candpos.getMomentum()))
#        print 'Electron p' +str(pMag(candele.getMomentum()))
#        print 'Recoil   p' +str(pMag(recoil.getMomentum()))
#        print 'Recoil Positron   p' +str(pMag(recpos.getMomentum()))

#        if candpos == recpos :
#            print "positrons are same"

        numSharedHits = myhist.getSharedHits(recoil.getTracks()[0],
                                             candele.getTracks()[0])
        print "Number of overlapping hits for electrons is : " + str(
            numSharedHits)

        if numSharedHits <= maxSharedHits:
            nTwoCand += 1
            myhist.fillCandidateHistograms(cand0, recoil)
            myhist.fillThreeTrackPlots(cand0, cand1)

#    if(nPassTrkCuts>0):
    myhist.saveHistograms(output_file)

    print "******************************************************************************************"
    print "Number of Events:\t\t", nEvents, "\t\t\t", float(
        nEvents) / nEvents, "\t\t\t", float(nEvents) / nEvents
    print "N(particle) Cuts:\t\t", nPassBasicCuts, "\t\t\t", float(
        nPassBasicCuts) / nEvents, "\t\t\t", float(nPassBasicCuts) / nEvents
    print "V0 Vertex   Cuts:\t\t", nPassV0Cuts, "\t\t\t", float(
        nPassV0Cuts) / nPassBasicCuts, "\t\t\t", float(nPassV0Cuts) / nEvents
    print "Tracking    Cuts:\t\t", nPassTrkCuts, "\t\t\t", float(
        nPassTrkCuts) / nPassV0Cuts, "\t\t\t", float(nPassTrkCuts) / nEvents
    print "ECal Match  Cuts:\t\t", nPassECalMatch, "\t\t\t", float(
        nPassECalMatch) / nPassTrkCuts, "\t\t\t", float(
            nPassECalMatch) / nEvents

    print "Number of Fake Events Added:  \t\t", nFakeTri, "\t\t\t", float(
        nFakeTri) / nPassECalMatch

    print "Number of events with 2 candidates (unshared) = ", nTwoCand
Exemplo n.º 2
0
def main():
    global beamEnergy
    # Parse all command line arguments using the argparse module.
    parser = argparse.ArgumentParser(description='PyRoot analysis demostrating the us of a DST.')
    parser.add_argument("dst_file",  help="ROOT DST file to process")
    parser.add_argument("-o", "--output",  help="Name of output pdf file")
    parser.add_argument("-m", "--mc",  help="is MonteCarlo")
    parser.add_argument("-p", "--pulser",  help="is Pulser")
    parser.add_argument("-e","--energy",help="beam energy")
    args = parser.parse_args()

    # If an output file name was not specified, set a default name and warn
    # the user 
    if args.output:
        output_file = args.output
    else: 
        output_file = "analysis_output.root"
        print "[ HPS ANALYSIS ]: An output file name was not specified. Setting the name to " 
        print output_file


    print "[ HPS ANALYSIS ]:  Output file is "+output_file
    isMC=False
    if args.mc:
        print  "[ HPS ANALYSIS ]: Setting to run as MC"
        isMC=True


    isPulser=False
    if args.pulser:
        print  "[ HPS ANALYSIS ]: Setting to run from a pulser file"
        isPulser=True

    if args.energy : 
        print 'Setting beam energy to '+args.energy
        beamEnergy=float(args.energy)
        myhist.setEnergyScales(beamEnergy)


#################################
#       Event Selection
################################
#clean up event first
#### nominal selection
    nTrkMax=3
    nTrkMin=3
    nPosMax=1
######  two tracks (e+/e-) exactly
#    nTrkMax=2
#    nTrkMin=2
#    nPosMax=1
###### more than 1 electron
#    nTrkMax=10
#    nTrkMin=3
#    nPosMax=1
###################
    maxSharedHits=2
    #v0 cuts   
#    v0Chi2=10
    v0Chi2=99999999.0
    #ESum -- full region
    v0PzMax=1.2*beamEnergy
    v0PzMin=0.1*beamEnergy
    #ESum -- Radiative region
#    v0PzMax=1.2
#    v0PzMin=0.80

    v0PyMax=0.2 #absolute value
    v0PxMax=0.2 #absolute value
    v0VzMax=25.0# mm from target
#    v0VyMax=1.0# mm from target    
    v0VyMax=6666.0# mm from target
    v0VxMax=2.0# mm from target
 #  track quality cuts
    trkChi2=10
    beamCut=0.8*beamEnergy
    minPCut=0.05
    trkPyMax=0.2
    trkPxMax=0.2
#    slopeCut=0.03
    slopeCut=0.0
    trkDeltaT=4#ns
    cluDeltaT=2#ns
    cluTrkDeltaT=4#ns
##############
#  ESum slices; upper limits    
    nSlicesESum=5 
    esumMin=0.55
    esumMax=1.2
    sliceSizeESum=0.1 #100MeV starting at esumMin
##############
    trackKiller=False
    tkThreshold=0.5 #GeV, below this start killing tracks
    tkThreshEff=1.0
    tkLowPoint=0.20
    tkLowPointEff=0.40
#    tkSlope=2.6 
#    tkIntercept=-0.04
    #calculate tkSlope and Intercept   
    tkSlope=(tkThreshEff-tkLowPointEff)/(tkThreshold-tkLowPoint)
    tkIntercept=tkThreshEff-tkSlope*tkThreshold

##############
    requireECalMatch = True
    requireECalFiducial = True
    requireECalSuperFiducial = False
    useGBL=True


     # Open the ROOT file
    #    root_file = ROOT.TFile(str(args.dst_file))
    # Get the TTree "HPS_EVENT" containing the HpsEvent branch and all
    # other colletions
    #    tree = root_file.Get("HPS_Event")
    #use a TChain
    print "[ HPS ANALYSIS ]: Reading in root chain from "+args.dst_file
    tree=ROOT.TChain("HPS_Event")
    tree.Add(str(args.dst_file)+"*")    
    # Create an HpsEvent object in order to read the TClonesArray 
    # collections
    hps_event = HpsEvent()

    b_hps_event = tree.SetBranchAddress("Event", ROOT.AddressOf(hps_event))

    #--- Analysis ---#
    #----------------#

    #counters
    nEvents=0;
    nPassBasicCuts=0;
    nPassV0Cuts=0;
    nPassTrkCuts=0;
    nPassNCand=0
    nPassECalMatch=0;
    nFakeTri=0
    nTwoCand=0
    seedCnt=0
    # Loop over all events in the file
    for entry in xrange(0, tree.GetEntries()) : 
                 
        # Print the event number every 500 events
        if (entry+1)%10000 == 0 : print "Event " + str(entry+1)
        tree.GetEntry(entry)
        if not hps_event.isPair1Trigger() and not isMC and not isPulser: continue
        nEvents+=1
        addFakeEle=False
                                         

        # Loop over all tracks in the event
        npositrons=0
        n_tracks=0
        for track_n in xrange(0, hps_event.getNumberOfTracks()) :             
            track = hps_event.getGblTrack(track_n)
            if track is None : 
                continue
#            print track.getParticle().getType()
            if trkMatchAndFiducial(track.getParticle(),requireECalSuperFiducial) and trkMomentum(track,minPCut,beamCut): # count only matched tracks in defined fiducial region
                n_tracks+=1
                if track.getCharge()>0 :
                    npositrons+=1
                    myhist.rawposMom.Fill(pMag(track.getMomentum()))
                else :
                    myhist.raweleMom.Fill(pMag(track.getMomentum()))
#                    findWABPair(track.getParticle(),hps_event)

#        print "nTracks = "+str(n_tracks)+"; nPositrons = "+str(npositrons)
#        if n_tracks/2.0>nTrkMax : continue   #do this very dumb thing (divide by 2 to un-double count GBL tracks)
#        if n_tracks/2.0<2:  continue        
        myhist.nTrk.Fill(n_tracks);
        myhist.nPos.Fill(npositrons);
        myhist.nEle.Fill(n_tracks-npositrons);
        myhist.nClust.Fill(hps_event.getNumberOfEcalClusters())

        if n_tracks>nTrkMax : continue  
        if n_tracks<nTrkMin:  continue        
        if npositrons<1 or npositrons>nPosMax : continue
        nPassBasicCuts+=1
#        print "passed basic cuts"
        candidateList=[]
        bestCandidate=-99
        nCandidate=0
        # loop over all v0 candidates...
        for uc_index in xrange(0, hps_event.getNumberOfParticles(HpsParticle.UC_V0_CANDIDATE)):
            particle = hps_event.getParticle(HpsParticle.UC_V0_CANDIDATE, uc_index)
#            print "Particle Type = "+ str(particle.getType())
            if useGBL and  particle.getType()<32  : continue
            if not useGBL and  particle.getType()>31  : continue
#            print "found one..."
            vchi2=particle.getVertexFitChi2();
            vposition=particle.getVertexPosition();
            vmomentum=particle.getMomentum();
            if vchi2>v0Chi2 :  continue
            # use the measured sum of momentum 
#            if vmomentum[2]>v0PzMax : continue
#            if vmomentum[2]<v0PzMin : continue
             #recon'ed vertex position cuts
            if abs(vposition[0])>v0VxMax : continue
            if abs(vposition[1])>v0VyMax :continue

#            if abs(vposition[2])>v0VzMax :continue
            # Only look at particles that have two daugther particles...
            daughter_particles = particle.getParticles()
            if daughter_particles.GetSize() != 2 : continue
            # Only look at particles that are composed of e+e- pairs
            if daughter_particles.At(0).getCharge()*daughter_particles.At(1).getCharge() > 0 : continue
#            print "Passed daughter number cuts"

            electron =  daughter_particles.At(0)
            positron =  daughter_particles.At(1)
            
            if daughter_particles.At(0).getCharge()>0:
                electron =  daughter_particles.At(1)
                positron =  daughter_particles.At(0)

            pEle=electron.getMomentum()
            pPos=positron.getMomentum()

            v0Sum=pMag(pSum(pEle,pPos))
            #total momentum sum cuts
            if v0Sum>v0PzMax : continue
            if v0Sum<v0PzMin : continue
            nPassV0Cuts+=1
#            print "Passed v0 cuts"
#############   tracking cuts
            #momentum cuts...get rid of very soft or very hard tracks
            if pMag(pEle)>beamCut or pMag(pPos)>beamCut : continue
            if pMag(pEle)<minPCut or pMag(pPos)<minPCut : continue   
            #top+bottom requirement
            if pEle[1]*pPos[1]>0 : continue

#            print 'looking at tracks now' 
#            print len(electron.getTracks())
            
            if  len(electron.getTracks()) == 0 or  len(positron.getTracks()) == 0: continue
            eleTrk=electron.getTracks().At(0)
            posTrk=positron.getTracks().At(0)
            if eleTrk is None or posTrk is None : continue
#            eleTrk.Print("v")
            #track timing
            if eleTrk.getTrackTime() - posTrk.getTrackTime()> trkDeltaT :
                continue
            #track slope (if any cut)
            if abs(eleTrk.getTanLambda())<slopeCut or abs(posTrk.getTanLambda())<slopeCut :
                continue
#            print 'satisfied timing cuts...'

            ##############
            nPassTrkCuts+=1

            ##############
            #   ECAL matching and timing cuts...also fiducial region cuts...
            if requireECalMatch: 
                if positron.getClusters().GetEntries() == 0 :
                    continue
                if electron.getClusters().GetEntries() == 0 :
                    continue
                posCluster=positron.getClusters().First()
                eleCluster=electron.getClusters().First()
                
                if eleCluster.getClusterTime()- posCluster.getClusterTime() > cluDeltaT:
                    continue
                
                if eleTrk.getTrackTime() - eleCluster.getClusterTime()+43.5 > cluTrkDeltaT : 
                    continue

                if posTrk.getTrackTime() - posCluster.getClusterTime()+43.5 > cluTrkDeltaT : 
                    continue
                
                if requireECalFiducial:
                    #ANTI-fiducial cut
                    #                    if  myhist.inFiducialRegion(posCluster.getPosition()[0],posCluster.getPosition()[1]) :
                    #                        continue
                    #                    if  myhist.inFiducialRegion(eleCluster.getPosition()[0],eleCluster.getPosition()[1]) :
                    #                        continue
                    #Fiducial cut
                    if not myhist.inFiducialRegion(posCluster.getPosition()[0],posCluster.getPosition()[1]) :
                        continue
                    if not myhist.inFiducialRegion(eleCluster.getPosition()[0],eleCluster.getPosition()[1]) :
                        continue
                if requireECalSuperFiducial :
                    if not myhist.inSuperFiducialRegion(posCluster.getPosition()[0],posCluster.getPosition()[1]) :
                        continue
                    if not myhist.inSuperFiducialRegion(eleCluster.getPosition()[0],eleCluster.getPosition()[1]) :
                        continue
            nPassECalMatch+=1
            ##############
            #Passed the cuts..append the candidate index
            candidateList.append(particle)
      

        numCands=len(candidateList)
                    
        myhist.nCand.Fill(numCands)
        if numCands != 2 : continue  #require 2 candidates...probably have to rethink this.  
        
        print 'found 2 candidates' 
        
        cand0=candidateList[0]  # take this as base candidate
        candpos=cand0.getParticles().At(0)
        candele=cand0.getParticles().At(1)
        if candpos.getCharge()<0 : 
            candpos=cand0.getParticles().At(1)
            candele=cand0.getParticles().At(0)    
#            print "swapping cand"
        cand1=candidateList[1]  # get the recoil electron from this
        recoil= cand1.getParticles().At(0)
        recpos= cand1.getParticles().At(1)
        if recoil.getCharge()> 0 :
#            print "swapping recoil"
            recoil= cand1.getParticles().At(1)
            recpos= cand1.getParticles().At(0)
#        print 'Positron p' +str(pMag(candpos.getMomentum()))
#        print 'Electron p' +str(pMag(candele.getMomentum()))
#        print 'Recoil   p' +str(pMag(recoil.getMomentum()))
#        print 'Recoil Positron   p' +str(pMag(recpos.getMomentum()))

#        if candpos == recpos : 
#            print "positrons are same" 

        numSharedHits=myhist.getSharedHits(recoil.getTracks()[0],candele.getTracks()[0])
        print "Number of overlapping hits for electrons is : "+str(numSharedHits)

        
        if numSharedHits <= maxSharedHits : 
            nTwoCand+=1
            myhist.fillCandidateHistograms(cand0,recoil)
            myhist.fillThreeTrackPlots(cand0,cand1)
            

#    if(nPassTrkCuts>0): 
    myhist.saveHistograms(output_file)   

    print "******************************************************************************************"
    print "Number of Events:\t\t",nEvents,"\t\t\t",float(nEvents)/nEvents,"\t\t\t",float(nEvents)/nEvents
    print "N(particle) Cuts:\t\t",nPassBasicCuts,"\t\t\t",float(nPassBasicCuts)/nEvents,"\t\t\t",float(nPassBasicCuts)/nEvents
    print "V0 Vertex   Cuts:\t\t",nPassV0Cuts,"\t\t\t",float(nPassV0Cuts)/nPassBasicCuts,"\t\t\t",float(nPassV0Cuts)/nEvents
    print "Tracking    Cuts:\t\t",nPassTrkCuts,"\t\t\t",float(nPassTrkCuts)/nPassV0Cuts,"\t\t\t",float(nPassTrkCuts)/nEvents
    print "ECal Match  Cuts:\t\t",nPassECalMatch,"\t\t\t",float(nPassECalMatch)/nPassTrkCuts,"\t\t\t",float(nPassECalMatch)/nEvents

    print "Number of Fake Events Added:  \t\t",nFakeTri,"\t\t\t",float(nFakeTri)/nPassECalMatch
                      
    print "Number of events with 2 candidates (unshared) = ",nTwoCand
Exemplo n.º 3
0
        # Get an Ecal scoring plane hit from the event
        ecal_sp_hit = hps_event.getEcalScoringPlaneHit(ecal_sp_hit_n)

        # Get the associated particle
        particle = ecal_sp_hit.getParticle()

        # Get the track associated with the particle
        track = particle.getTracks().At(0)

        # Find the GBL track that corresponds to the Ecal scoring
        # plane hit
        for gbl_track_n in xrange(0, hps_event.getNumberOfGblTracks()):

            # Get a GBL track from the event
            gbl_track = hps_event.getGblTrack(gbl_track_n)

            # If the GBL seed track and the track associated with
            # the Ecal scoring plane hit do not match, continue
            # onto the next track
            if (gbl_track.getSeedD0() != track.getD0()): continue

            h_track_d0.Fill(gbl_track.getSeedD0())
            h_gbl_track_d0.Fill(gbl_track.getD0())

            gbl_track_parameters[0] = gbl_track.getD0()
            gbl_track_parameters[1] = gbl_track.getPhi()
            gbl_track_parameters[2] = gbl_track.getKappa()
            gbl_track_parameters[3] = gbl_track.getZ0()
            gbl_track_parameters[4] = math.tan(math.pi / 2 -
                                               gbl_track.getTheta())
		# Get an Ecal scoring plane hit from the event
		ecal_sp_hit = hps_event.getEcalScoringPlaneHit(ecal_sp_hit_n)

		# Get the associated particle
		particle = ecal_sp_hit.getParticle()

		# Get the track associated with the particle
		track = particle.getTracks().At(0)

		# Find the GBL track that corresponds to the Ecal scoring 
		# plane hit
		for gbl_track_n in xrange(0, hps_event.getNumberOfGblTracks()):

			# Get a GBL track from the event
			gbl_track = hps_event.getGblTrack(gbl_track_n)

			# If the GBL seed track and the track associated with
			# the Ecal scoring plane hit do not match, continue
			# onto the next track
			if(gbl_track.getSeedD0() != track.getD0()): continue

			h_track_d0.Fill(gbl_track.getSeedD0())
			h_gbl_track_d0.Fill(gbl_track.getD0())

			gbl_track_parameters[0] = gbl_track.getD0()	
			gbl_track_parameters[1] = gbl_track.getPhi()
			gbl_track_parameters[2] = gbl_track.getKappa()
			gbl_track_parameters[3] = gbl_track.getZ0()
			gbl_track_parameters[4] = math.tan(math.pi/2 - gbl_track.getTheta())