Beispiel #1
0
 def pushJobs(self):
     servers = filter(lambda x: x != None, self.NS.servers)
     if not self.quiet:
         pbar = progressbar("Pushing to &count& nodes:", len(servers))
         pbar.start()
         i=0
     for node in servers:
         node.job = self.job
         node.pushCurrentJob()
         if not self.quiet:
             i += 1
             pbar.update(i)
     if not self.quiet:
         pbar.finish()
def simulate(N, duration, tstep=1, renderEveryNthFrame=1, path="Simulation", viewradius=1,\
             xyzrange=[[-1,1],[-1,1],[-1,1]], projections=False, transparency=True, delete=False):
    # Keyboard interrupt handling
    def signal_handler(signal, frame):
        import sys
        print '\n(!) Rendering aborted: KeyboardInterrupt.'
        sys.exit(0)
    signal.signal(signal.SIGINT, signal_handler)

    xyzrange = np.multiply(viewradius, xyzrange)

    # Set up and clear path
    if os.path.exists(path):                                                                        #|Remove previous crap if anything is there
        shutil.rmtree(path)
        os.makedirs(path+"/frames")
    else:
        os.makedirs(path+"/frames")

    # Set some stuff up
    t = 0
    #pos = randomParticles(N)
    sideLength = np.floor(N**(1.0/3))
    pos = uniformParticles(sideLength, 0.002)
    vel = zeroVelocity(sideLength**3)

    numSteps = (duration-t)/float(tstep)
    step = 0
    count = 1
    pbar = progressbar("Computing &count& steps:", numSteps+1)
    pbar.start()
    # Simulation loop
    while t <= duration:
        if  step%renderEveryNthFrame == 0:
            renderFrame(pos, t, count, path, xyzrange, projections, transparency)
            count += 1
        pos, vel = update(pos, vel, tstep)
        t += tstep
        step += 1
        pbar.update(step)
    pbar.finish()

    print "Combining frames; may take a minute..."
    args = (['convert', '-delay', '.1', '-loop', '0', path+"/frames/*.gif", path+"/animation.gif"]) #|This part requires ImageMagick to function. Change the arguments as you wish.
    subprocess.check_call(args)

    if delete:
        shutil.rmtree(path+"/frames")
        print "Successfully deleted frames." 
Beispiel #3
0
def stackMass(rTree, histmass):

    # gets number of entries (collision bunches)
    nentries = rTree.GetEntries()

    # creates a progress bar
    pbar = progressbar("Stacking", nentries).start()

    for i in range(0, nentries):
        rTree.GetEntry(i)
        for rec in range(0, rTree.STr2_NPi0_rec):
            if rTree.STr2_Pi0recIsEB[rec]:
                histmass.Fill(rTree.STr2_mPi0_rec[rec])
        pbar.update(i + 1)
    pbar.finish()
    return histmass
Beispiel #4
0
 def shutdownNodes(self):
     servers = filter(lambda x: x != None, self.NS.servers)
     if len(servers) == 0:
         print "No slave nodes to shut down."
         return 0
     print ""
     pbar = progressbar("Shutting down &count& nodes:", len(servers))
     pbar.start()
     i = 0
     for node in servers:
         node.client.close()
         i += 1
         pbar.update(i)
     pbar.finish()
     print ""
     return 0
Beispiel #5
0
def stackTimeEta(rTree, entries, histlist, histlist2, translist, translist2):

    if entries != -1:
        nentries = entries
    else:
        # gets number of entries (collision bunches)
        nentries = rTree.GetEntries()

    # creates a progress bar
    pbar = progressbar("Stacking", nentries).start()

    if histlist2 != 0:
        pass
    else:  # merged 1 plot
        for i in range(0, nentries):
            rTree.GetEntry(i)
            for rec in range(0, rTree.STr2_NPi0_rec):
                if rTree.STr2_Pi0recIsEB[rec] != True:
                    continue
                if rTree.STr2_iEta_1[rec] + 85 < 0:
                    pass
                else:
                    if fc.applyCutsEta(rTree, rec, rTree.STr2_Eta_1[rec], True) is False:  # photon 1 merged
                        continue
                    if rTree.STr2_iEta_1[rec] >= 0:  # accounting for crystal 0 being 1
                        histlist[rTree.STr2_iEta_1[rec] + 86].Fill(rTree.STr2_Time_1[rec])
                        translist[rTree.STr2_iEta_1[rec] + 86].Fill(float(1) / rTree.STr2_Laser_rec_1[rec])
                    else:
                        histlist[rTree.STr2_iEta_1[rec] + 85].Fill(rTree.STr2_Time_1[rec])
                        translist[rTree.STr2_iEta_1[rec] + 85].Fill(float(1) / rTree.STr2_Laser_rec_1[rec])
                if rTree.STr2_iEta_2[rec] + 85 < 0:
                    pass
                else:
                    if fc.applyCutsEta(rTree, rec, rTree.STr2_Eta_2[rec], False) is False:  # photon 2 merged
                        continue
                    if rTree.STr2_iEta_2[rec] >= 0:  # accounting for crystal 0 being 1
                        histlist[rTree.STr2_iEta_2[rec] + 86].Fill(rTree.STr2_Time_2[rec])
                        translist[rTree.STr2_iEta_2[rec] + 86].Fill(float(1) / rTree.STr2_Laser_rec_2[rec])
                    else:
                        histlist[rTree.STr2_iEta_2[rec] + 85].Fill(rTree.STr2_Time_2[rec])
                        translist[rTree.STr2_iEta_2[rec] + 85].Fill(float(1) / rTree.STr2_Laser_rec_2[rec])
            pbar.update(i + 1)
        pbar.finish()
        return histlist, translist

    for i in range(0, nentries):  # 2 separate plots for p1 and p2
        rTree.GetEntry(i)
        for rec in range(0, rTree.STr2_NPi0_rec):
            if rTree.STr2_Pi0recIsEB[rec] != 1:
                continue
            if rTree.STr2_iEta_1[rec] + 85 < 0:
                pass
            else:
                if fc.applyCutsEta(rTree, rec, rTree.STr2_Eta_1[rec], True) is False:  # photon 1 separate
                    continue
                if rTree.STr2_iEta_1[rec] >= 0:  # accounting for crystal 0 being 1
                    histlist[rTree.STr2_iEta_1[rec] + 86].Fill(rTree.STr2_Time_1[rec])
                    translist[rTree.STr2_iEta_1[rec] + 86].Fill(float(1) / rTree.STr2_Laser_rec_1[rec])
                else:
                    histlist[rTree.STr2_iEta_1[rec] + 85].Fill(rTree.STr2_Time_1[rec])
                    translist[rTree.STr2_iEta_1[rec] + 85].Fill(float(1) / rTree.STr2_Laser_rec_1[rec])

            if rTree.STr2_iEta_2[rec] + 85 < 0:
                pass
            else:
                if fc.applyCutsEta(rTree, rec, rTree.STr2_Eta_2[rec], False) is False:  # photon 2 separate
                    continue
                if rTree.STr2_iEta_2[rec] >= 0:  # accounting for crystal 0 being 1
                    histlist2[rTree.STr2_iEta_2[rec] + 86].Fill(rTree.STr2_Time_2[rec])
                    translist2[rTree.STr2_iEta_2[rec] + 86].Fill(float(1) / rTree.STr2_Laser_rec_2[rec])
                else:
                    histlist2[rTree.STr2_iEta_2[rec] + 85].Fill(rTree.STr2_Time_2[rec])
                    translist2[rTree.STr2_iEta_2[rec] + 85].Fill(float(1) / rTree.STr2_Laser_rec_2[rec])
        pbar.update(i + 1)
    pbar.finish()
    return histlist, histlist2, translist, translist2
Beispiel #6
0
def stackTime(rTree, entries, histlist, histlist2, histlist3, histlist4, translist, translist2, translist3, translist4):

    if entries != -1:
        nentries = entries
    else:
        # gets number of entries (collision bunches)
        nentries = rTree.GetEntries()

    # creates a progress bar
    pbar = progressbar("Stacking", nentries).start()

    # check if want to make 2 separate plots for p1 and p2 or conjoined
    if histlist3 != 0:  # (p1,p2,m1,m2)
        pass

    # makes 1 plot for both photon 1 and 2, double stacking all the way
    else:  # (p,m,0,0)
        if len(histlist) != 101:  # not endcap
            for i in range(0, nentries):
                rTree.GetEntry(i)
                for rec in range(0, rTree.STr2_NPi0_rec):
                    if rTree.STr2_Pi0recIsEB[rec] != True:
                        continue
                    if rTree.STr2_iEta_1[rec] + 85 < 0 or rTree.STr2_iPhi_1[rec] < 0:
                        pass
                    else:
                        if fc.applyCuts(rTree, rec, rTree.STr2_Eta_1[rec], True) is False:  # photon 1
                            continue
                        if rTree.STr2_iEta_1[rec] >= 0:  # accounting for crystal 0 being 1
                            histlist[rTree.STr2_iEta_1[rec] + 86][rTree.STr2_iPhi_1[rec]].Fill(rTree.STr2_Time_1[rec])
                            translist[rTree.STr2_iEta_1[rec] + 86][rTree.STr2_iPhi_1[rec]].Fill(
                                float(1) / rTree.STr2_Laser_rec_1[rec]
                            )
                        else:
                            histlist[rTree.STr2_iEta_1[rec] + 85][rTree.STr2_iPhi_1[rec]].Fill(rTree.STr2_Time_1[rec])
                            translist[rTree.STr2_iEta_1[rec] + 85][rTree.STr2_iPhi_1[rec]].Fill(
                                float(1) / rTree.STr2_Laser_rec_1[rec]
                            )
                    if rTree.STr2_iEta_2[rec] + 85 < 0 or rTree.STr2_iPhi_2[rec] < 0:
                        pass
                    else:
                        if fc.applyCuts(rTree, rec, rTree.STr2_Eta_2[rec], False) is False:  # photon 2
                            continue
                        if rTree.STr2_iEta_2[rec] >= 0:  # accounting for crystal 0 being 1
                            histlist[rTree.STr2_iEta_2[rec] + 86][rTree.STr2_iPhi_2[rec]].Fill(rTree.STr2_Time_2[rec])
                            translist[rTree.STr2_iEta_2[rec] + 86][rTree.STr2_iPhi_2[rec]].Fill(
                                float(1) / rTree.STr2_Laser_rec_2[rec]
                            )
                        else:
                            histlist[rTree.STr2_iEta_2[rec] + 85][rTree.STr2_iPhi_2[rec]].Fill(rTree.STr2_Time_2[rec])
                            translist[rTree.STr2_iEta_2[rec] + 85][rTree.STr2_iPhi_2[rec]].Fill(
                                float(1) / rTree.STr2_Laser_rec_2[rec]
                            )
                pbar.update(i + 1)
            pbar.finish()
            return histlist, translist

        else:  # is endcap
            for i in range(0, nentries):
                rTree.GetEntry(i)
                for rec in range(0, rTree.STr2_NPi0_rec):
                    if rTree.STr2_Pi0recIsEB[rec] == True:
                        continue
                    if rTree.STr2_Eta_1[rec] > 1.479:
                        if rTree.STr2_iX_1[rec] < 0 or rTree.STr2_iY_1[rec] < 0:
                            pass
                        else:
                            if fc.applyCuts(rTree, rec, rTree.STr2_Eta_1[rec], True) is False:  # photon 1 in EE+
                                continue
                            histlist[rTree.STr2_iX_1[rec]][rTree.STr2_iY_1[rec]].Fill(rTree.STr2_Time_1[rec])
                            translist[rTree.STr2_iX_1[rec]][rTree.STr2_iY_1[rec]].Fill(
                                float(1) / rTree.STr2_Laser_rec_1[rec]
                            )
                    elif rTree.STr2_Eta_1[rec] < -1.479:
                        if rTree.STr2_iX_1[rec] < 0 or rTree.STr2_iY_1[rec] < 0:
                            pass
                        else:
                            if fc.applyCuts(rTree, rec, rTree.STr2_Eta_1[rec], True) is False:  # photon 1 in EE-
                                continue
                            histlist2[rTree.STr2_iX_1[rec]][rTree.STr2_iY_1[rec]].Fill(rTree.STr2_Time_1[rec])
                            translist2[rTree.STr2_iX_1[rec]][rTree.STr2_iY_1[rec]].Fill(
                                float(1) / rTree.STr2_Laser_rec_1[rec]
                            )
                    if rTree.STr2_Eta_2[rec] > 1.479:
                        if rTree.STr2_iX_2[rec] < 0 or rTree.STr2_iY_2[rec] < 0:
                            pass
                        else:
                            if fc.applyCuts(rTree, rec, rTree.STr2_Eta_2[rec], False) is False:  # photon 2 in EE+
                                continue
                            histlist[rTree.STr2_iX_2[rec]][rTree.STr2_iY_2[rec]].Fill(rTree.STr2_Time_2[rec])
                            translist[rTree.STr2_iX_2[rec]][rTree.STr2_iY_2[rec]].Fill(
                                float(1) / rTree.STr2_Laser_rec_2[rec]
                            )
                    elif rTree.STr2_Eta_2[rec] < -1.479:
                        if rTree.STr2_iX_2[rec] < 0 or rTree.STr2_iY_2[rec] < 0:
                            pass
                        else:
                            if fc.applyCuts(rTree, rec, rTree.STr2_Eta_2[rec], False) is False:  # photon 2 in EE-
                                continue
                            histlist2[rTree.STr2_iX_2[rec]][rTree.STr2_iY_2[rec]].Fill(rTree.STr2_Time_2[rec])
                            translist2[rTree.STr2_iX_2[rec]][rTree.STr2_iY_2[rec]].Fill(
                                float(1) / rTree.STr2_Laser_rec_2[rec]
                            )
                #                    print "photon 1: " + str(rTree.STr2_iX_1[rec]) + ", " + str(rTree.STr2_iY_1[rec])
                #                    print "photon 2: " + str(rTree.STr2_iX_2[rec]) + ", " + str(rTree.STr2_iY_2[rec])
                pbar.update(i + 1)
            pbar.finish()
            return histlist, histlist2, translist, translist2

    # stack 2 separate plots for 2 photons of interest
    if len(histlist) != 101:  # not endcap
        for i in range(0, nentries):
            rTree.GetEntry(i)
            for rec in range(0, rTree.STr2_NPi0_rec):
                if rTree.STr2_Pi0recIsEB[rec] != True:
                    continue
                if rTree.STr2_iEta_1[rec] + 85 < 0 or rTree.STr2_iPhi_1[rec] < 0:
                    pass
                else:
                    if fc.applyCuts(rTree, rec, rTree.STr2_Eta_1[rec], True) is False:  # photon 1
                        continue
                    if rTree.STr2_iEta_1[rec] >= 0:  # accounting for crystal 0 being 1
                        histlist[rTree.STr2_iEta_1[rec] + 86][rTree.STr2_iPhi_1[rec]].Fill(rTree.STr2_Time_1[rec])
                        translist[rTree.STr2_iEta_1[rec] + 86][rTree.STr2_iPhi_1[rec]].Fill(
                            float(1) / rTree.STr2_Laser_rec_1[rec]
                        )
                    else:
                        histlist[rTree.STr2_iEta_1[rec] + 85][rTree.STr2_iPhi_1[rec]].Fill(rTree.STr2_Time_1[rec])
                        translist[rTree.STr2_iEta_1[rec] + 85][rTree.STr2_iPhi_1[rec]].Fill(
                            float(1) / rTree.STr2_Laser_rec_1[rec]
                        )
                if rTree.STr2_iEta_2[rec] + 85 < 0 or rTree.STr2_iPhi_2[rec] < 0:
                    pass
                else:
                    if fc.applyCuts(rTree, rec, rTree.STr2_Eta_2[rec], False) is False:  # photon 2
                        continue
                    if rTree.STr2_iEta_2[rec] >= 0:  # accounting for crystal 0 being 1
                        histlist2[rTree.STr2_iEta_2[rec] + 86][rTree.STr2_iPhi_2[rec]].Fill(rTree.STr2_Time_2[rec])
                        translist2[rTree.STr2_iEta_2[rec] + 86][rTree.STr2_iPhi_2[rec]].Fill(
                            float(1) / rTree.STr2_Laser_rec_2[rec]
                        )
                    else:
                        histlist2[rTree.STr2_iEta_2[rec] + 85][rTree.STr2_iPhi_2[rec]].Fill(rTree.STr2_Time_2[rec])
                        translist2[rTree.STr2_iEta_2[rec] + 85][rTree.STr2_iPhi_2[rec]].Fill(
                            float(1) / rTree.STr2_Laser_rec_2[rec]
                        )
            pbar.update(i + 1)
        pbar.finish()
        return histlist, histlist2, translist, translist2
    else:  # is endcap
        for i in range(0, nentries):
            rTree.GetEntry(i)
            for rec in range(0, rTree.STr2_NPi0_rec):
                if rTree.STr2_Pi0recIsEB[rec] == True:
                    continue
                if rTree.STr2_Eta_1[rec] > 1.479:
                    if rTree.STr2_iX_1[rec] < 0 or rTree.STr2_iY_1[rec] < 0:
                        pass
                    else:
                        if fc.applyCuts(rTree, rec, rTree.STr2_Eta_1[rec], True) is False:  # photon 1 in EE+
                            continue
                        histlist[rTree.STr2_iX_1[rec]][rTree.STr2_iY_1[rec]].Fill(rTree.STr2_Time_1[rec])
                        translist[rTree.STr2_iX_1[rec]][rTree.STr2_iY_1[rec]].Fill(
                            float(1) / rTree.STr2_Laser_rec_1[rec]
                        )
                elif rTree.STr2_Eta_1[rec] < 1.479:
                    if rTree.STr2_iX_1[rec] < 0 or rTree.STr2_iY_1[rec] < 0:
                        pass
                    else:
                        if fc.applyCuts(rTree, rec, rTree.STr2_Eta_1[rec], True) is False:  # photon 1 in EE-
                            continue
                        histlist2[rTree.STr2_iX_1[rec]][rTree.STr2_iY_1[rec]].Fill(rTree.STr2_Time_1[rec])
                        translist2[rTree.STr2_iX_1[rec]][rTree.STr2_iY_1[rec]].Fill(
                            float(1) / rTree.STr2_Laser_rec_1[rec]
                        )
                if rTree.STr2_Eta_2[rec] > 1.479:
                    if rTree.STr2_iX_2[rec] < 0 or rTree.STr2_iY_2[rec] < 0:
                        pass
                    else:
                        if fc.applyCuts(rTree, rec, rTree.STr2_Eta_2[rec], False) is False:  # photon 2 in EE+
                            continue
                        histlist3[rTree.STr2_iX_2[rec]][rTree.STr2_iY_2[rec]].Fill(rTree.STr2_Time_2[rec])
                        translist3[rTree.STr2_iX_2[rec]][rTree.STr2_iY_2[rec]].Fill(
                            float(1) / rTree.STr2_Laser_rec_2[rec]
                        )
                elif rTree.STr2_Eta_2[rec] < 1.479:
                    if rTree.STr2_iX_2[rec] < 0 or rTree.STr2_iY_2[rec] < 0:
                        pass
                    else:
                        if fc.applyCuts(rTree, rec, rTree.STr2_Eta_2[rec], False) is False:  # photon 2 in EE-
                            continue
                        histlist4[rTree.STr2_iX_2[rec]][rTree.STr2_iY_2[rec]].Fill(rTree.STr2_Time_2[rec])
                        translist4[rTree.STr2_iX_2[rec]][rTree.STr2_iY_2[rec]].Fill(
                            float(1) / rTree.STr2_Laser_rec_2[rec]
                        )
            pbar.update(i + 1)
        pbar.finish()
        return histlist, histlist2, histlist3, histlist4, translist, translist2, translist3, translist4
## Getting back to program file
##
    # Check current working directory.
    retdir = os.getcwd()
    print "Current working directory %s" % retdir
    
    # Now change the directory
    os.chdir( startdir + '/result/')
    
    # Check current working directory.
    retdir = os.getcwd()
    print "Directory changed successfully %s" % retdir

    #Progress bar for the saves
#    pbar = progressbar("saving data", 171).start()
    pbar = progressbar("saving data", 342).start()

    #saving all 1D histograms in tree
#    f = rt.TFile("timeEB"+str(int(time.time()))+".root","new")
#    for eta in range(0,len(histList)):
#        for phi in range(0, len(histList[0])):
#            histList[eta][phi].Write()
#            #Saving value of data in tuple list
#            dataList = np.vstack((dataList, [eta-85, phi, htime.GetBinContent(eta+1, phi)]))
#        pbar.update(eta+1)
#    np.delete(dataList,0)
#    htime.Write()

    f = rt.TFile("timeEB1_"+str(int(time.time()))+".root","new")
    for eta in range(0,len(histList1)):
        for phi in range(0, len(histList1[0])):
Beispiel #8
0
    fileList = os.listdir(p.rootFileLocationLocal)
    fileList.sort()
    filename = p.runNumber + "EcalNtp_"

    ##Get data ready to search
    rTree = rt.TChain("Tree_Optim")
    for k in range(len(fileList)):
        if filename in fileList[k]:
            rTree.Add(fileList[k])
            print "successfully cut branch from " + fileList[k]

    ##Find eta and fill
    nentries = rTree.GetEntries()

    #creates a progress bar
    pbar = progressbar("Stacking", nentries).start()
    
    for i in range(0, nentries):
        rTree.GetEntry(i)
        for rec in range(0, rTree.STr2_NPi0_rec):
#            print "Phi: " + str(rTree.STr2_iPhi_1[rec]) + ", iEta: " + str(rTree.STr2_iEta_1[rec]) + ", iY: " + str(rTree.STr2_iY_1[rec]) + ", iX: " + str(rTree.STr2_iX_1[rec]) + ", Eta: " + str(rTree.STr2_Eta_1[rec]) + ", is in EB: " + str(rTree.STr2_Pi0recIsEB[rec])
            if rTree.STr2_Pi0recIsEB[rec] == True: #If not endcap, kick out
                continue
            if rTree.STr2_iX_1[rec] < 0 or rTree.STr2_iY_1[rec] < 0: #has to contain positive x,y values
                pass
            else:
#                print "Phi: " + str(rTree.STr2_iPhi_1[rec]) + ", iEta: " + str(rTree.STr2_iEta_1[rec]) + ", iY: " + str(rTree.STr2_iY_1[rec]) + ", iX: " + str(rTree.STr2_iX_1[rec]) + ", Eta: " + str(rTree.STr2_Eta_1[rec]) + ", is in EB: " + str(rTree.STr2_Pi0recIsEB[rec])
                if rTree.STr2_Eta_1[rec] > 1.479: #Is it EE+?
                    endcapetaplus[rTree.STr2_iX_1[rec]+1][rTree.STr2_iY_1[rec]][2] += 1
                    endcapetaplus[rTree.STr2_iX_1[rec]+1][rTree.STr2_iY_1[rec]][3] += rTree.STr2_Eta_1[rec]
                elif rTree.STr2_Eta_1[rec] < -1.479: #Is it EE-?
##
    # Check current working directory.
    retdir = os.getcwd()
    print "Current working directory %s" % retdir
    
    # Now change the directory
    os.chdir( startdir + '/result/')
    
    # Check current working directory.
    retdir = os.getcwd()
    print "Directory changed successfully %s" % retdir


    #Progress bar for the saves
    #    pbar = progressbar("saving data", 101).start()
    pbar = progressbar("saving data", 101).start()

    #saving all 1D histograms in tree
    f = rt.TFile("timeEB_"+str(int(time.time()))+".root","new")
    for x in range(0,len(histListp)):
        for y in range(0, len(histListp[0])):
            histListp[x][y].Write()
            histListm[x][y].Write()
            #Saving value of data in tuple list
            dataListp = np.vstack((dataListp, ["p", x, y, htimep.GetBinContent(x+1, y)]))
            dataListm = np.vstack((dataListp, ["m", x, y, htimem.GetBinContent(x+1, y)]))
        pbar.update(x+1)
    htimep.Write()
    htimem.Write()