def processFile(input_file, output_file): # if len(sys.argv) < 2: # msg = '\n' # msg += "Usage 1: %s $INPUT_ROOT_FILE(s)\n" % sys.argv[0] # msg += '\n' # sys.stderr.write(msg) # sys.exit(1) # Create ana_processor instance my_proc = larlite.ana_processor() my_proc.add_input_file(input_file) # # Set input root file # for x in xrange(len(sys.argv)-1): # my_proc.add_input_file(sys.argv[x+1]) # Specify IO mode my_proc.set_io_mode(larlite.storage_manager.kREAD) larutil.LArUtilManager.Reconfigure(larlite.geo.kArgoNeuT) # Specify output root file name my_proc.set_ana_output_file(output_file) # Attach an analysis unit ... here we use a base class which does nothing. # Replace with your analysis unit if you wish. my_proc.add_process(argoana.dEdxPfPartAna()) # Let's run it. my_proc.run(0)
def run(self, n_events=-1, n_skip=-1): larutil.LArUtilManager.Reconfigure(larlite.geo.kArgoNeuT) # Create ana_processor instance my_proc = larlite.ana_processor() # Set input root file my_proc.add_input_file(self._file) # Specify IO mode my_proc.set_io_mode(larlite.storage_manager.kREAD) # Specify output root file name # my_proc.set_ana_output_file() # Attach an analysis unit ... here we use a base class which do my_proc.add_process(self._process) # Let's run it. if n_events == -1: my_proc.run(0) else: if n_skip == -1: my_proc.run(0, n_events) else: my_proc.run(n_skip, n_events)
def runCaloMuons(amp_q_constants, area_q_constants, amp_e_constants, area_e_constants, f): larutil.LArUtilManager.Reconfigure(larlite.geo.kArgoNeuT) # Create ana_processor instance my_proc = larlite.ana_processor() # Set input root file my_proc.add_input_file(f) # Specify IO mode my_proc.set_io_mode(larlite.storage_manager.kREAD) # my_proc.set_output_file("out.root") # Specify output root file name my_proc.set_ana_output_file("from_test_ana_you_can_remove_me.root") # Attach an analysis unit ... here we use a base class which does nothing. # Replace with your analysis unit if you wish. caloAlg = larlite.ArgoCaloXingMuons() caloAlg.setAreaQConstant(area_q_constants[0], 0) caloAlg.setAreaQConstant(area_q_constants[1], 1) caloAlg.setAmpQConstant(amp_q_constants[0], 0) caloAlg.setAmpQConstant(amp_q_constants[1], 1) caloAlg.setAreaEConstant(area_e_constants[0], 0) caloAlg.setAreaEConstant(area_e_constants[1], 1) caloAlg.setAmpEConstant(amp_e_constants[0], 0) caloAlg.setAmpEConstant(amp_e_constants[1], 1) # Need to set the lifetime corrections here lifetimes = caloAlg.getLifetimes() # This is for data: # pf = open('/data_linux/argoneut/calibration_files/lifetimes_data.pkl', 'rb') # lifetime_calibrations = pickle.load(pf) # for run in lifetime_calibrations: # lifetimes[run] = lifetime_calibrations[run] # This is for mc: lifetimes[1] = 500 caloAlg.setLifetimes(lifetimes) my_proc.add_process(caloAlg) # Let's run it. my_proc.run(0) return caloAlg
def main(): larutil.LArUtilManager.Reconfigure(larlite.geo.kMicroBooNE) drawWire = evd.DrawWire() #print 'initize image processing' drawWire.initialize() ana_processor = larlite.ana_processor() ana_processor.set_io_mode(larlite.storage_manager.kREAD) ana_processor.add_process(drawWire) ana_processor.add_input_file( sys.argv[1] ) manager = larlite.storage_manager() manager.reset() manager.add_in_filename( sys.argv[2] ) manager.set_io_mode(larlite.storage_manager.kREAD) manager.open() folder = "/uboone/data/users/davidc1/numuCCFilterOutput/selection2/handscanned/images/" froot = ROOT.TFile(sys.argv[1]) tree = froot.Get("larlite_id_tree") nentries = tree.GetEntries() froot.Close() i = 0 for entry in xrange(nentries): #print 'processing event %i'%entry ana_processor.process_event( entry ) manager.go_to( entry ) # grab the vertex: vertex_v = manager.get_data(larlite.data.kVertex,"numuCC_vertex") if (len(vertex_v) != 1): print 'Number of vertices != 1 : continue...' continue vtx = vertex_v[0] wire_range, time_range = getWireRange(vtx) run = manager.run_id() event = manager.event_id() image = drawWire.getArrayByPlane(2) drawEvent(wire_range, time_range, image, folder, run, event)
def runCaloMuons(wire_calibrations, f): larutil.LArUtilManager.Reconfigure(larlite.geo.kArgoNeuT) # Create ana_processor instance my_proc = larlite.ana_processor() # Set input root file my_proc.add_input_file(f) # Specify IO mode my_proc.set_io_mode(larlite.storage_manager.kREAD) # my_proc.set_output_file("out.root") # Specify output root file name my_proc.set_ana_output_file("from_test_ana_you_can_remove_me.root") # Attach an analysis unit ... here we use a base class which does nothing. # Replace with your analysis unit if you wish. caloAlg = larlite.ArgoXingMuons2D() # Convert the corrections to a vector<vector<double> > in order to pass # them: _vector_corrections = caloAlg.getWireCorrections() _vector_corrections.resize(2) _vector_corrections[0].resize(240) _vector_corrections[1].resize(240) for plane in wire_calibrations: for wire in wire_calibrations[plane]: # print "({},{}): {:.2f}".format(plane,wire, # wire_calibrations[plane][wire]) _vector_corrections[plane][ wire] = 1.025 * wire_calibrations[plane][wire] caloAlg.setWireCorrections(_vector_corrections) my_proc.add_process(caloAlg) # Let's run it. my_proc.run(0) return caloAlg
def runCaloMuonsWires(f, wireCorrections=None): larutil.LArUtilManager.Reconfigure(larlite.geo.kArgoNeuT) # Create ana_processor instance my_proc = larlite.ana_processor() # Set input root file my_proc.add_input_file(f) # Specify IO mode my_proc.set_io_mode(larlite.storage_manager.kREAD) # my_proc.set_output_file("out.root") # Specify output root file name my_proc.set_ana_output_file("from_test_ana_you_can_remove_me.root") # Attach an analysis unit ... here we use a base class which does nothing. # Replace with your analysis unit if you wish. caloAlg = larlite.ArgoCaloXingMuons() if wireCorrections is not None: caloAlg.setWireCorrections(wireCorrections) caloAlg.setAreaQConstant(area_q_constants[0], 0) caloAlg.setAreaQConstant(area_q_constants[1], 1) caloAlg.setAmpQConstant(amp_q_constants[0], 0) caloAlg.setAmpQConstant(amp_q_constants[1], 1) caloAlg.setAreaEConstant(area_e_constants[0], 0) caloAlg.setAreaEConstant(area_e_constants[1], 1) caloAlg.setAmpEConstant(amp_e_constants[0], 0) caloAlg.setAmpEConstant(amp_e_constants[1], 1) my_proc.add_process(caloAlg) # Let's run it. my_proc.run(0) # get the wire corrections and return them: return caloAlg.getWireCorrections()
def main(): gc.enable() gc.set_debug(gc.DEBUG_STATS) larutil.LArUtilManager.Reconfigure(larlite.geo.kMicroBooNE) drawWire = evd.DrawWire() print 'initize image processing' drawWire.initialize() ana_processor = larlite.ana_processor() ana_processor.set_io_mode(larlite.storage_manager.kREAD) ana_processor.add_process(drawWire) ana_processor.add_input_file( sys.argv[1] ) folder = "/home/david/uboone/images/" _file_wire = sys.argv[1] _file_nu = sys.argv[2] froot = ROOT.TFile(_file_nu) tree = froot.Get("larlite_id_tree") nentries = tree.GetEntries() froot.Close() i = 0 for entry in xrange(5): print 'processing event %i'%entry ana_processor.process_event( entry ) run = manager.run_id() event = manager.event_id() image = drawWire.getArrayByPlane(2) drawEvent(image, folder, run, event)
def runCaloMuons(amp_q_constants, area_q_constants, amp_e_constants, area_e_constants, f): larutil.LArUtilManager.Reconfigure(larlite.geo.kArgoNeuT) # Create ana_processor instance my_proc = larlite.ana_processor() # Set input root file my_proc.add_input_file(f) # Specify IO mode my_proc.set_io_mode(larlite.storage_manager.kREAD) # my_proc.set_output_file("out.root") # Specify output root file name my_proc.set_ana_output_file("from_test_ana_you_can_remove_me.root") # Attach an analysis unit ... here we use a base class which does nothing. # Replace with your analysis unit if you wish. caloAlg = larlite.ArgoCaloXingMuons() caloAlg.setAreaQConstant(area_q_constants[0], 0) caloAlg.setAreaQConstant(area_q_constants[1], 1) caloAlg.setAmpQConstant(amp_q_constants[0], 0) caloAlg.setAmpQConstant(amp_q_constants[1], 1) caloAlg.setAreaEConstant(area_e_constants[0], 0) caloAlg.setAreaEConstant(area_e_constants[1], 1) caloAlg.setAmpEConstant(amp_e_constants[0], 0) caloAlg.setAmpEConstant(amp_e_constants[1], 1) my_proc.add_process(caloAlg) # Let's run it. my_proc.run(0) # Target for dE/dx is fix at 2.3 MeV/cm # print the results: print "Induction Q area mean: {m}\ttarget: {t}".format( m=caloAlg.induction_q_area_mean(), t=caloAlg.induction_q_target_mean()) print "Induction Q amp mean: {m}\ttarget: {t}".format( m=caloAlg.induction_q_amp_mean(), t=caloAlg.induction_q_target_mean()) print "Collection Q area mean: {m}\ttarget: {t}".format( m=caloAlg.collection_q_area_mean(), t=caloAlg.collection_q_target_mean()) print "Collection Q amp mean: {m}\ttarget: {t}".format( m=caloAlg.collection_q_amp_mean(), t=caloAlg.collection_q_target_mean()) print "Induction E area mean: {m}\ttarget: {t}".format( m=caloAlg.induction_e_area_mean(), #t=caloAlg.induction_e_target_mean()) t=2.3) print "Induction E amp mean: {m}\ttarget: {t}".format( m=caloAlg.induction_e_amp_mean(), #t=caloAlg.induction_e_target_mean()) t=2.3) print "Collection E area mean: {m}\ttarget: {t}".format( m=caloAlg.collection_e_area_mean(), #t=caloAlg.collection_e_target_mean()) t=2.3) print "Collection E amp mean: {m}\ttarget: {t}".format( m=caloAlg.collection_e_amp_mean(), #t=caloAlg.collection_e_target_mean()) t=2.3) # return the correction factors: area_q_corrections = [ caloAlg.induction_q_area_mean() / caloAlg.induction_q_target_mean(), caloAlg.collection_q_area_mean() / caloAlg.collection_q_target_mean() ] amp_q_corrections = [ caloAlg.induction_q_amp_mean() / caloAlg.induction_q_target_mean(), caloAlg.collection_q_amp_mean() / caloAlg.collection_q_target_mean() ] # area_e_corrections = [caloAlg.induction_e_area_mean()/caloAlg.induction_e_target_mean(), # caloAlg.collection_e_area_mean()/caloAlg.collection_e_target_mean()] # amp_e_corrections = [caloAlg.induction_e_amp_mean()/caloAlg.induction_e_target_mean(), # caloAlg.collection_e_amp_mean()/caloAlg.collection_e_target_mean()] area_e_corrections = [ caloAlg.induction_e_area_mean() / 2.3, caloAlg.collection_e_area_mean() / 2.3 ] amp_e_corrections = [ caloAlg.induction_e_amp_mean() / 2.3, caloAlg.collection_e_amp_mean() / 2.3 ] return area_q_corrections, amp_q_corrections, area_e_corrections, amp_e_corrections
def main(**args): my_proc = larlite.ana_processor() # my_proc.enable_event_alignment(False) if args['verbose']: print "Verbose mode turned on." if args['source'] != None: print "\tSource file is " + args['source'] if args['data_output'] != None: print "\tData output file is " + args['data_output'] if args['ana_output'] != None: print "\tAna output file is " + args['ana_output'] # my_proc.set_verbosity(larlite.msg.kDEBUG) # else: my_proc.set_verbosity(larlite.msg.kERROR) if args['source'] == None: print "Error: please specificy an input file with -s or --source." quit() if args['data_output'] == None: args['data_output'] = args['source'][0].replace(".root", "") + "_mergeall.root" if args['verbose']: print "No event output file selected. If necessary, output will go to:" print "\t" + args['data_output'] if args['ana_output'] == None: args['ana_output'] = "default_ana_output.root" if args['verbose']: print "No ana output file selected. If necessary, output will go to:" print "\t" + args['ana_output'] if args['num_events'] != None: nevents = int(args['num_events']) larutil.LArUtilManager.Reconfigure(larlite.geo.kArgoNeuT) my_proc.set_io_mode(larlite.storage_manager.kBOTH) for x in args['source']: my_proc.add_input_file(x) my_proc.set_output_file(args['data_output']) htc = larlite.HitToCluster() htc.SetInputProducer("cccluster") name = "ccclusterWithSingles" htc.SetOutputProducer(name) my_proc.add_process(htc) # Merge all: merger = larlite.ClusterMerger() merger.SetInputProducer("ccclusterWithSingles") merger.SetOutputProducer("mergeall") ######################################## # MERGE ALGORITHMS ######################################## # algo_array = cmtool.CBAlgoArray() mergeAll = cmtool.CBAlgoMergeAll() mergeAll.SetHits(0) # algo_array.AddAlgo(mergeAll, True) merger.GetManager().SetMinNHits(0) merger.GetManager().AddMergeAlgo(mergeAll) merger.SaveOutputCluster() my_proc.add_process(merger) if args['num_events'] != None: start = time.clock() my_proc.run(0, nevents) end = time.clock() print "Processed ", nevents, " events in ", end - start, "seconds." print "Average per event: ", (end - start) / nevents, "seconds." else: my_proc.run()
def main(**args): my_proc = larlite.ana_processor() my_proc.enable_filter(True) my_proc.enable_event_alignment(False) if args['verbose']: print "Verbose mode turned on." if args['source'] != None: print "\tSource file is " + args['source'] if args['data_output'] != None: print "\tData output file is " + args['data_output'] if args['ana_output'] != None: print "\tAna output file is " + args['ana_output'] # my_proc.set_verbosity(larlite.msg.kDEBUG) # else: my_proc.set_verbosity(larlite.msg.kERROR) if args['source'] == None: print "Error: please specificy an input file with -s or --source." quit() if args['data_output'] == None: args['data_output'] = "default_filter_output.root" if args['verbose']: print "No event output file selected. If necessary, output will go to: " print "\t"+args['data_output'] if args['ana_output'] == None: args['ana_output'] = "default_ana_output.root" if args['verbose']: print "No ana output file selected. If necessary, output will go to:" print "\t"+args['ana_output'] if args['num_events'] != None: nevents = int(args['num_events']) my_proc.set_io_mode(larlite.storage_manager.kBOTH) for x in args['source']: my_proc.add_input_file(x) my_proc.set_output_file(args['data_output']) larutil.LArUtilManager.Reconfigure(larlite.geo.kArgoNeuT) # showerfilter=argofilter.ShowerFilter() # showerfilter.SetInputProducer("ccMergedFinal") # showerfilter.SetOutputProducer("ccShowers") # showerfilter=argofilter.BasicFilter() showerfilter.SetInputProducer("cccluster") my_proc.add_process(showerfilter) if args['num_events'] != None: start=time.clock() my_proc.run(0, nevents) end=time.clock() print "Processed ", nevents, " events in ", end-start, "seconds." print "Average per event: ", (end-start)/nevents, "seconds." else: my_proc.run()
msg = '\n' msg += "Usage 1: %s $INPUT_ROOT_FILE(s)\n" % sys.argv[0] msg += '\n' sys.stderr.write(msg) sys.exit(1) print sys.argv f = sys.argv[1:] # Run minos matching on the file, reject events that are matched to minos: larutil.LArUtilManager.Reconfigure(larlite.geo.kArgoNeuT) # Create ana_processor instance my_proc = larlite.ana_processor() # Set input root file for _f in f: my_proc.add_input_file(_f) # Specify IO mode my_proc.set_io_mode(larlite.storage_manager.kBOTH) # Specify output root file name my_proc.set_ana_output_file("ana.root") my_proc.set_output_file("out.root") filterModule = argofilter.TrackFilter() filterModule.setTrackProducer("pmtrack") filterModule.setClusterProducer("trajcluster")
def drawEvent(_file, shower, output_folder): print ROOT.gROOT.GetListOfFiles().RemoveAll() if shower.dEdx_best_median() < 0.1: return print bcolors.OKBLUE, "Initializing data ...", bcolors.ENDC ana_processor = larlite.ana_processor() # ana_processor.enable_event_alignment(False) ana_processor.set_io_mode(larlite.storage_manager.kREAD) image_process = evd.DrawWire() # Set up the noise filter and initialize image_process.initialize() ana_processor.add_process(image_process) ana_processor.add_input_file(_file) ana_processor.process_event(shower.fileIndex() - 1) # # Fetch the data from the reader and transpose it to get the axes correct _orig_coll_array = image_process.getArrayByPlane(1) _orig_ind_array = image_process.getArrayByPlane(0) _orig_coll_array = numpy.flipud(numpy.transpose(_orig_coll_array)) _orig_ind_array = numpy.flipud(numpy.transpose(_orig_ind_array)) _scaled_coll_array = numpy.repeat(_orig_coll_array, 13, axis=1) _scaled_ind_array = numpy.repeat(_orig_ind_array, 13, axis=1) # This function maps the data onto the color scheme and makes and RGB array coll_array = collectionMapper.to_rgba(_scaled_coll_array) coll_array = numpy.uint8(coll_array * 255) ind_array = inductionMapper.to_rgba(_scaled_ind_array) ind_array = numpy.uint8(ind_array * 255) run = shower.run() event = shower.event() x_extent = 240 * 13 y_extent = 2048 # logo_top = run_info = "Run {}, Event {}".format(run, event) calo_info = "Best Plane: {}\ndE/dx: {:.3}".format( shower.best_plane(), shower.dEdx_best_median()) collfileName = "R{}_E{}_collection.png".format(run, event) indfileName = "R{}_E{}_induction.png".format(run, event) coll_image = Image.fromarray(coll_array) draw = ImageDraw.Draw(coll_image) fontsize = 60 font = ImageFont.truetype("arialbd.ttf", fontsize) draw.text((100, y_extent - fontsize - 100), run_info, (255, 255, 255), font) # draw.text((100, y_extent - fontsize*3 - 100),calo_info,(255,255,255),font) coll_image.paste(argoneut_logo, (1, 1)) coll_image.save(output_folder + collfileName) ind_image = Image.fromarray(ind_array) draw = ImageDraw.Draw(ind_image) draw.text((100, y_extent - fontsize - 100), run_info, (255, 255, 255), font) # draw.text((100, y_extent - fontsize*3 - 100),calo_info,(255,255,255),font) ind_image.paste(argoneut_logo, (1, 1)) ind_image.save(output_folder + indfileName) print bcolors.OKBLUE, "Finished " + run_info, bcolors.ENDC