def AnaUnit(): my_anaunit = fmwk.ExampleERSelection() # Set Producers # First Argument: True = MC, False = Reco my_anaunit.SetShowerProducer(True, "mcreco") my_anaunit.SetTrackProducer(True, "mcreco") #my_anaunit.SetShowerProducer(False,"showerreco"); #my_anaunit.SetTrackProducer(False,""); my_anaunit._mode = True # True = Select. False = Fill mode my_anaunit._mgr._mc_for_ana = True return my_anaunit
my_proc.set_io_mode(fmwk.storage_manager.kREAD) # Specify output root file name my_proc.set_ana_output_file("ertool_hist.root") # Create ERTool algorithm (empty base class for this example) my_algo = ertool.AlgoBase() # Create ERTool filter (empty base class for this example) my_filter = ertool.FilterBase() # Create ERTool analysis (empty base class for this example) my_ana = ertool.AnaBase() # Create larlite interfce analysis unit for ERTool my_anaunit = fmwk.ExampleERSelection() # Set Producers # First Argument: True = MC, False = Reco # Second Argument: producer module label my_anaunit.SetShowerProducer(True, "mcreco") my_anaunit.SetTrackProducer(True, "mcreco") my_anaunit.SetVtxProducer(True, "generator") # Implement manager my_anaunit._mgr.SetAlgo(my_algo) my_anaunit._mgr.SetFilter(my_filter) my_anaunit._mgr.SetAna(my_ana) my_ana._mode = True # True = Select. False = Fill mode my_proc.add_process(my_anaunit)
# 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(fmwk.storage_manager.kREAD) # Specify output root file name my_proc.set_ana_output_file("EMselectionPDF.root") my_algo = ertool.AlgoEMPart() my_algo.LoadParams() my_algo.Reset() my_algo.SetMode(False) # True = Gamma. False = Electron. my_algo.setVerbose(True) my_ana = fmwk.ExampleERSelection() # Set Producers # First Argument: True = MC, False = Reco #my_ana.SetShowerProducer(True,"mcreco"); #my_ana.SetTrackProducer(True,"mcreco"); #my_ana.SetVtxProducer(True,"generator"); my_ana.SetShowerProducer(False,"showerreco"); my_ana.SetTrackProducer(False,""); my_ana.SetVtxProducer(False,""); my_ana._mgr.SetAlgo(my_algo) my_ana._mode =True # True = Select. False = Fill mode my_proc.add_process(my_ana) my_proc.run()
def main(): if len(sys.argv) < 2: msg = '\n' msg += "Usage: %s $INPUT_ROOT_FILE\n" % sys.argv[0] msg += "$INPUT_ROOT_FILE containing 'gamma' ('electron') is used for training AlgoEMPart gamma (electron) mode.\n" msg += '\n' sys.stderr.write(msg) sys.exit(1) # Create ana_processor instance my_proc = fmwk.ana_processor() # Create algorithm my_algo = ertool.AlgoEMPart() # ******* Set Fit ranges ********** # Fit ranges for Reconstructed Info my_algo.SetFitRange_dEdx(0.5, 8, False) # False = e- / True = gamma my_algo.SetFitRange_dEdx(0.5, 9, True) my_algo.SetFitRange_RadLen(1., 4., False) my_algo.SetFitRange_RadLen(5., 35., True) # Fit ranges for MC Info: #my_algo.SetFitRange_dEdx(0.5,8,False); # False = e- / True = gamma #my_algo.SetFitRange_dEdx(0.5,9,True); #my_algo.SetFitRange_RadLen(5.,25.,True); #my_algo.SetFitRange_RadLen(0.,5.,False); # ******* End Set Fit Ranges ******* #my_algo.setVerbose(False) my_algo.setPlot(True) # Create analysis unit my_ana = fmwk.ExampleERSelection() my_ana.SetMinEDep(10) my_ana.SetCheater(True) # Set Producers # First Argument: True = MC, False = Reco #my_ana.SetShowerProducer(True,"mcreco"); #my_ana.SetTrackProducer(True,"mcreco"); #my_ana.SetShowerProducer(False,"pandoraNuShower"); my_ana.SetShowerProducer(False, "showerreco") my_ana.SetTrackProducer(False, "") #my_ana._mgr.SetAlgo(my_algo) my_ana._mgr.AddAlgo(my_algo) my_ana._mgr._training_mode = True # Check if gamma/electron files are provided: gamma_files = [] electron_files = [] for x in xrange(len(sys.argv) - 1): fname = sys.argv[x + 1] if fname.find('gamma') >= 0: gamma_files.append(fname) else: electron_files.append(fname) print print ' Running AlgoEMPart training script...' print print ' Identified %2d input files for gamma' % len(gamma_files) print ' Identified %2d input files for electron' % len(electron_files) if not ask_binary(' Proceed? [y/n]:'): return False print if ask_binary(' Load previously extracted fit parameters? [y/n]:'): my_algo.setLoadParams(True) else: my_algo.setLoadParams(False) # # Training for gamma mode # gamma_trained = False if len(gamma_files) and ask_binary(' Run training for gamma? [y/n]:'): my_proc.set_io_mode(fmwk.storage_manager.kREAD) my_proc.add_process(my_ana) for f in gamma_files: my_proc.add_input_file(f) my_algo.SetMode(True) my_ana._mgr.Reset() my_proc.set_ana_output_file("gamma_training.root") print ' Start running gamma training...' my_proc.run() print print ' Finished running gamma training...' print # Re-set my_proc.reset() gamma_trained = True # # Training for electron mode # electron_trained = False if len(electron_files) and ask_binary( ' Run training for electron? [y/n]:'): my_proc.set_io_mode(fmwk.storage_manager.kREAD) my_proc.add_process(my_ana) for f in electron_files: my_proc.add_input_file(f) my_algo.SetMode(False) my_ana._mgr.Reset() my_proc.set_ana_output_file("electron_training.root") print ' Start running electron training...' my_proc.run() print print ' Finished running electron training...' print # Re-set my_proc.reset() electron_trained = True # # Store trained parameters # if (gamma_trained or electron_trained ) and ask_binary(' Store train result parameters? [y/n]:'): my_ana._mgr.StorePSet("new_empart.txt") #my_algo.StoreParams() print ' Parameter stored...' print return True
def main(): if len(sys.argv) < 2: msg = '\n' msg += "Usage: %s $INPUT_ROOT_FILE\n" % sys.argv[0] msg += '\n' sys.stderr.write(msg) sys.exit(1) ertool.Manager() #viewer plt.ion() display_reco = ERViewer() display_mc = ERViewer() display_reco.show() display_mc.show() # Create ana_processor instance my_proc = fmwk.ana_processor() # Create algorithm my_algo = ertool.AlgoPi0() my_algo.setVerbose(True) my_algo.setMinShrEnergy(10) my_algo.setMaxShrEnergy(1000) my_algo.setIPMax(10) my_algo.setMinFitMass(50) my_algo.setMaxFitMass(200) my_algo.setAngleMax(3.14) # Create analysis unit my_ana = fmwk.ExampleERSelection() # ************Set Producers************** # First Argument: True = MC, False = Reco my_ana.SetShowerProducer(True, "mcreco") my_ana.SetTrackProducer(True, "mcreco") my_ana.SetVtxProducer(False, "") my_ana.SetShowerProducer(False, "showerreco") my_ana.SetTrackProducer(False, "") my_ana.SetVtxProducer(False, "") #my_ana.SetShowerProducer(True,"mcreco"); #my_ana.SetTrackProducer(True,"mcreco"); #my_ana.SetVtxProducer(False,""); # ************Set Producers************** #help(my_ana._mgr) my_ana._mgr.SetAlgo(my_algo) my_ana._mgr._training_mode = True # Obtain input root files files = [] for x in xrange(len(sys.argv) - 1): fname = sys.argv[x + 1] if fname.endswith('.root'): files.append(fname) print print ' Running AlgoPi0 training script...' print print ' Identified %2d input files' % len(files) if not ask_binary(' Proceed? [y/n]:'): return False print if ask_binary(' Load previously extracted fit parameters? [y/n]:'): my_algo.LoadParams() my_proc.set_io_mode(fmwk.storage_manager.kREAD) my_proc.add_process(my_ana) for f in files: my_proc.add_input_file(f) my_ana._mgr.Reset() my_proc.set_ana_output_file("pi0_viewing.root") print ' Start running pi0 training...' # Start event-by-event loop counter = 0 while (counter < 1000): try: counter = input( 'Hit Enter to continue to next evt, or type in an event number to jump to that event:' ) except SyntaxError: counter = counter + 1 my_proc.process_event(counter) # get objets and display display_reco.clear() display_mc.clear() data_reco = my_ana.GetData() part_reco = my_ana.GetParticles() data_mc = my_ana.GetData(True) part_mc = my_ana.GetParticles(True) #display_reco.add(part_reco, data_reco, False) display_mc.add(part_mc, data_mc, False) display_reco.add(part_reco, data_reco, False) for x in xrange(part_mc.size()): print part_mc[x].Diagram() #for x in xrange(part_reco.size()): # print part_reco[x].Diagram() #Last argument decides if un-taggeg showers/tracks should have random color (True) or grey (False) display_reco.show() display_mc.show() #my_proc.run() print print ' Finished running pi0 training...' print # # Store trained parameters # if ask_binary(' Store train result parameters? [y/n]:'): my_algo.StoreParams() print ' Parameter stored...' print return True