argbs = int(sys.argv[1]) #box setup to use argoutput = sys.argv[2] #name of outputfile arginputlist = sys.argv[3] #name of input list file def ScaleAndWriteHist(h): if h.Integral() > 0: h.Scale(1 / h.Integral()) h.Write() else: print h.GetName(), " has 0 entries. Skipping..." qbins = 50 xbins = 50 geo = geom() bs = boxsetup3d(argbs, False) for b in bs: geo.drawbox(b) ttree = TChain("MCSMuons/MCSMuons") files = 0 for line in file(arginputlist): ttree.Add(line[:-1]) files += 1 print "Found", ttree.GetEntries(), "entries in", files, "files" tf = TFile(argoutput, "recreate") #diagnostic histograms to make sure things are behaving correctly
def DoEventsList(tl): #do events list loop for track label tl ftreelist=["evt_number/I", "evt_time/I", "MuCS_Start[3]/F", "MuCS_theta_xy/F", "MuCS_theta_xy_rms/F", "MuCS_theta_yz/F", "MuCS_theta_yz_rms/F", "MuCS_Start_TPC[3]/F", "MuCS_NHitsX/I","MuCS_NHitsZ/I", "MuCS_TPC_len/F", "Tagged_Start[3]/F", "Tagged_End[3]/F", "Tagged_theta_xy/F", "Tagged_theta_yz/F", "Tagged_len/F", "MinD_Start[3]/F","MinD_End[3]/F", "MinD_theta_xy/F" , "MinD_theta_yz/F" , "MinD_dist/F", "MinD_len/F", "MCTagged_Start[3]/F", "MCTagged_End[3]/F", "MCTagged_theta_xy/F", "MCTagged_theta_yz/F", "MCTagged_len/F", "flash_time/F", "flash_pe/F", "flash_ycenter/F","flash_ywidth/F","flash_zcenter/F","flash_zwidth/F", "nflashes/I","totpe/F","MCflash_time/F","MCflash_pe/F", "MCflash_ycenter/F","MCflash_ywidth/F","MCflash_zcenter/F","MCflash_zwidth/F","MCnflashes/I","MCtotpe/F"] etree=flatttree("events_%s"%(tl),ftreelist) for i in range(argNStart,argN): eventnumber=GetEntries(i) print "Entry: %d, Event:%d"%(i,eventnumber) #for some reason, this gets the MuCS::MuCSRecoData object #the try/excepts are to handle different era's of variable names automagically try: #md=events.__getattr__("MuCS::MuCSRecoDatas_mucsreco__MuCSExtrapolate.obj.ftheta_xy") #mdhits=events.__getattr__("MuCS::MuCSDatas_merger__MuCSMerger.obj.ft0") md=events.__getattr__("MuCS::MuCSRecoDatas_MuCSReco__MuCSMerge.obj.ftheta_xy") mdhits=events.__getattr__("MuCS::MuCSDatas_MuCSMerger__MuCSMerge.obj.ft0") except: try: md=events.__getattr__("MuCS::MuCSRecoDatas_MuCSReco__MuCSMETAL.obj.ftheta_xy") mdhits=events.__getattr__("MuCS::MuCSDatas_MuCSMerger__MuCSMETAL.obj.ft0") except: raise mind=1e6 geo=geom("%s_%d"%(tl,eventnumber)) Tagged_Start=(0.,0.,0.) Tagged_End=(0.,0.,0.) Tagged_theta_xy=Tagged_theta_yz=0. MuCS_Start=MuCS_Start_TPC=(0.,0.,0.) MuCS_theta_xy=MuCS_theta_yz=MuCS_theta_xy_rms=MuCS_theta_yz_rms=0. MinD_Start=(0.,0.,0.) MinD_End=(0.,0.,0.) MinD_dist=0. MinD_theta_xy=MinD_theta_yz=0. MuCS_NHitsX=MuCS_NHitsZ=0 MuCS_TPC_len=Tagged_len=MinD_len=0. MCTagged_Start=(0.,0.,0.) MCTagged_End=(0.,0.,0.) MCTagged_theta_xy=MCTagged_theta_yz=MCTagged_len=0. for b in bs: geo.drawbox(b) if md.z()!=0.: mucstrks=drawBoxHits(mdhits,geo) #draw MuCS hits and projected track v1 mucstrks,MuCS_Start,MuCS_theta_xy,MuCS_theta_yz,MuCS_Start_TPC, MuCS_TPC_len,MuCS_theta_xy_rms,MuCS_theta_yz_rms=getLinesTuple(md,geo) geo.drawpoint(mucstrks,len(mucstrks),4,"f",4) #draw projected track from MuCSExtrapolate if not argpmtonly: print "ntracks=",avt("ntracks",tl) for trk in xrange(avt("ntracks",tl)): p1=(avt("trkstartx",tl)[trk]+xrecooffset,avt("trkstarty",tl)[trk],avt("trkstartz",tl)[trk]) p2=(avt("trkendx",tl)[trk]+xrecooffset,avt("trkendy",tl)[trk],avt("trkendz",tl)[trk]) print p1,p2 if checkMuCSTag(trk,tl) and avt("trklen",tl)[trk]>Tagged_len: geo.drawpoint((p1,p2), 2, 2,"",4) Tagged_Start, Tagged_End, Tagged_theta_xy,Tagged_theta_yz,Tagged_len=GetTaggedInfo(trk,tl) else: geo.drawpoint((p1,p2), 2, 11,"",2) #find closest track to MuCS TPC projection if md.z()!=0: pTop,pBot,t1,t2,tlen=GetTaggedInfo(trk,tl) d=dist(pTop,MuCS_Start_TPC) if d<mind: mind=d MinD_dist=d MinD_Start, MinD_End,MinD_theta_xy,MinD_theta_yz,MinD_len=GetTaggedInfo(trk,tl) #get number of hits that went into the MuCS track if md.z()!=0: MuCS_NHitsZ=len(mdhits.Hits7())+len(mdhits.Hits2()) MuCS_NHitsX=len(mdhits.Hits3())+len(mdhits.Hits1()) print "Hits Z,X:", MuCS_NHitsZ,",", MuCS_NHitsX #get mc track info if mcanatree is not None: for trk in xrange(mcavt("ntracks",tl)): p1=(mcavt("trkstartx",tl)[trk]+xrecooffset,mcavt("trkstarty",tl)[trk],mcavt("trkstartz",tl)[trk]) p2=(mcavt("trkendx",tl)[trk]+xrecooffset,mcavt("trkendy",tl)[trk],mcavt("trkendz",tl)[trk]) if checkMuCSTagMC(trk,tl) and mcavt("trklen",tl)[trk]>MCTagged_len: geo.drawpoint((p1,p2), 2, 9,"",4) MCTagged_Start, MCTagged_End, MCTagged_theta_xy,MCTagged_theta_yz,MCTagged_len=GetTaggedInfoMC(trk,tl) else: geo.drawpoint((p1,p2), 2, 46,"",2) #draw and get flash info nflashes,flash_time,flash_pe,flash_ycenter,flash_ywidth,flash_zcenter,flash_zwidth,ntotflashes,totpe=drawFlashes(geo, anatree, False) MCnflashes,MCflash_time,MCflash_pe,MCflash_ycenter,MCflash_ywidth,MCflash_zcenter,MCflash_zwidth,MCntotflashes,MCtotpe=drawFlashes(geo, mcanatree, True) print "Drew %d data flashes and %d mc flashes" %(nflashes,MCnflashes) #fill tree etree.fill((eventnumber,int(anatree.evttime), MuCS_Start, MuCS_theta_xy, MuCS_theta_xy_rms, MuCS_theta_yz, MuCS_theta_yz_rms, MuCS_Start_TPC, MuCS_NHitsX, MuCS_NHitsZ,MuCS_TPC_len, Tagged_Start, Tagged_End, Tagged_theta_xy, Tagged_theta_yz, Tagged_len, MinD_Start, MinD_End, MinD_theta_xy, MinD_theta_yz, MinD_dist, MinD_len, MCTagged_Start, MCTagged_End, MCTagged_theta_xy, MCTagged_theta_yz, MCTagged_len, flash_time, flash_pe,flash_ycenter,flash_ywidth,flash_zcenter,flash_zwidth, ntotflashes, totpe, MCflash_time, MCflash_pe,MCflash_ycenter,MCflash_ywidth,MCflash_zcenter,MCflash_zwidth,MCntotflashes,MCtotpe)) geo.close(tfout) del geo print "finished event", eventnumber #if i>10: exit(0) etree.close(tfout)