def check_volume_cut(input_path, number_entries_input, radius_cut): """ :param input_path: file name with path to input root files from tut_detsim.py: user_atmoNC_{}.root :param number_entries_input: number of entries, that the input files should have (integer), normally = 100 :param radius_cut: radius, which defines the fiducial volume, in mm :return: """ # load the ROOT file: rfile = ROOT.TFile(input_path) # get the "geninfo"-TTree from the TFile: rtree_geninfo = rfile.Get("geninfo") # get the "prmtrkdep"-TTree from TFile: rtree_prmtrkdep = rfile.Get("prmtrkdep") # get the number of events in the geninfo Tree: number_events = rtree_geninfo.GetEntries() # check if number_events_geninfo is equal to number_entries_input (if not, the detector simulation was incorrect!!): if number_events != number_entries_input: sys.exit( "ERROR: number of events are not equal to {0:d} -> Detector Simulation not correct!" .format(number_entries_input)) # number of events with reconstructed position inside fiducial volume (r_reco < Radius_cut): n_reco_inside = 0 # number of leak-out events (r_init < Radius_cut, but r_reco >= Radius_cut): n_leak_out = 0 # number of leak-in events (r_init >= Radius_cut, but r_reco < Radius_cut): n_leak_in = 0 # loop over every event, i.e. every entry, in the TTree: for event in range(number_events): """ read prmtrkdep tree: """ rtree_prmtrkdep.GetEntry(event) # get nInitParticles from prmtrkdep tree: n_par_prmtrkdep = int( rtree_prmtrkdep.GetBranch('nInitParticles').GetLeaf( 'nInitParticles').GetValue()) # preallocate sum of Qedep of initial particles: qedep_sum = 0 # to get total quenched deposited energy, sum over initial particles: for index1 in range(n_par_prmtrkdep): # get deposit energy of initial neutron in MeV: qedep = float( rtree_prmtrkdep.GetBranch('Qedep').GetLeaf('Qedep').GetValue( index1)) # add qedep to qedep_sum: qedep_sum += qedep """ read 'geninfo' tree: """ # get the current event in the Tree: rtree_geninfo.GetEntry(event) # get event ID: evt_id = int( rtree_geninfo.GetBranch('evtID').GetLeaf('evtID').GetValue()) if evt_id != event: sys.exit( "ERROR: event ID's are not equal in file {0}".format(rfile)) # get number of particles in the event: n_par_geninfo = int( rtree_geninfo.GetBranch('nInitParticles').GetLeaf( 'nInitParticles').GetValue()) # check if there are initial particles: if n_par_geninfo == 0: # no initial particle -> go to next event continue # preallocate array for initial position: initx = np.array([]) inity = np.array([]) initz = np.array([]) # loop over number of particles in the event: for index1 in range(n_par_geninfo): # get initial position of the particle in mm : initx = np.append( initx, float( rtree_geninfo.GetBranch('InitX').GetLeaf('InitX').GetValue( index1))) inity = np.append( inity, float( rtree_geninfo.GetBranch('InitY').GetLeaf('InitY').GetValue( index1))) initz = np.append( initz, float( rtree_geninfo.GetBranch('InitZ').GetLeaf('InitZ').GetValue( index1))) # set 0th entry of array as initial position in mm: x_init = initx[0] y_init = inity[0] z_init = initz[0] # check if all initial position are equal: for index1 in range(n_par_geninfo): if x_init != initx[index1] or y_init != inity[ index1] or z_init != initz[index1]: sys.exit( "ERROR: initial positions are not equal for all initial particles (event {0:d}, file {1})" .format(event, rfile)) # smear the initial position with vertex reconstruction: x_reco = NC_background_functions.position_smearing(x_init, qedep_sum) y_reco = NC_background_functions.position_smearing(y_init, qedep_sum) z_reco = NC_background_functions.position_smearing(z_init, qedep_sum) # calculate r_init in mm: r_init = np.sqrt(x_init**2 + y_init**2 + z_init**2) # calculate r_reco in mm: r_reco = np.sqrt(x_reco**2 + y_reco**2 + z_reco**2) if r_reco < radius_cut: # reco. position inside fiducial volume: n_reco_inside += 1 if r_init < radius_cut and r_reco >= radius_cut: n_leak_out += 1 if r_init >= radius_cut and r_reco < radius_cut: n_leak_in += 1 return number_events, n_reco_inside, n_leak_out, n_leak_in
# check if there is just one initial positron: sys.exit( "ERROR: more than 1 initial particles in event {0:d}".format( event)) # get initial x, y, z position: x_init = float( rtree_geninfo.GetBranch('InitX').GetLeaf('InitX').GetValue()) y_init = float( rtree_geninfo.GetBranch('InitY').GetLeaf('InitY').GetValue()) z_init = float( rtree_geninfo.GetBranch('InitZ').GetLeaf('InitZ').GetValue()) # do vertex reconstruction with function position_smearing(): # Smear x,y and z position of the initial position (returns reconstructed position in mm): x_reconstructed = NC_background_functions.position_smearing( x_init, qedep_prmtrkdep) y_reconstructed = NC_background_functions.position_smearing( y_init, qedep_prmtrkdep) z_reconstructed = NC_background_functions.position_smearing( z_init, qedep_prmtrkdep) # calculate distance to detector center in mm: r_reconstructed = np.sqrt(x_reconstructed**2 + y_reconstructed**2 + z_reconstructed**2) # check if event passes the volume cut: if r_reconstructed >= radius_cut: # event is rejected by volume cut. print("file {0:d}, event = {1:d}: r_init = {2:0.2f} mm".format( index, event, r_reconstructed)) # go to next event
Qedep_capture = float(rtree_prmtrkdep.GetBranch('Qedep').GetLeaf('Qedep').GetValue()) # get current event: rtree_geninfo.GetEntry(event) # get initial x,y,z position in mm: x_init = float(rtree_geninfo.GetBranch('InitX').GetLeaf('InitX').GetValue()) y_init = float(rtree_geninfo.GetBranch('InitY').GetLeaf('InitY').GetValue()) z_init = float(rtree_geninfo.GetBranch('InitZ').GetLeaf('InitZ').GetValue()) # do vertex reconstruction with function position_smearing() for distance cut: # Smear x,y and z position of the initial position (returns reconstructed position in mm) # (for Qedep use random number from uniform distribution between 10 MeV and 100 MeV. This represents the prompt # energy of a positron like in a real IBD event, since in user_neutron_multiplicity.root only the neutron is # simulated): Qedep_init = np.random.uniform(10, 100) x_reco_init = NC_background_functions.position_smearing(x_init, Qedep_init) y_reco_init = NC_background_functions.position_smearing(y_init, Qedep_init) z_reco_init = NC_background_functions.position_smearing(z_init, Qedep_init) # get nCapture tree: rtree_ncapture.GetEntry(event) # get number of neutron captures: NeutronN = int(rtree_ncapture.GetBranch('NeutronN').GetLeaf('NeutronN').GetValue()) # set variables to zeros: nCaptureT = 0.0 x_reco_ncapture = -17000 y_reco_ncapture = 0 z_reco_ncapture = 0 # check NeutronN: