def m_Kpipipi_fill(t, h, type): window_low = 1.86965 - window(ecms)/2. window_up = 1.86965 + window(ecms)/2. for ientry in xrange(t.GetEntries()): t.GetEntry(ientry) if not (t.m_rm_Dpipi > window_low and t.m_rm_Dpipi < window_up): continue if not (t.m_n_p == 0 and t.m_n_pbar == 0): continue discarded = False for iTrk in range(3): if abs(t.m_Vxy_Dtrks[iTrk]) > 0.55: discarded = True if abs(t.m_Vz_Dtrks[iTrk]) > 3.0: discarded = True if abs(t.m_cos_theta_Dtrks[iTrk]) > 0.93: discarded = True if abs(t.m_Vxy_pip) > 0.55: discarded = True if abs(t.m_Vxy_pim) > 0.55: discarded = True if abs(t.m_Vz_pip) > 3.: discarded = True if abs(t.m_Vz_pim) > 3.: discarded = True if abs(t.m_cos_theta_pip) > 0.93: discarded = True if abs(t.m_cos_theta_pim) > 0.93: discarded = True if (t.m_m_pipi > 0.491036 and t.m_m_pipi < 0.503471) and abs(t.m_L_svf/t.m_Lerr_svf) > 2.: discarded = True if discarded: continue if type == 'Kpipipi1': h.Fill(t.m_m_Kpipipi1) if type == 'Kpipipi2': h.Fill(t.m_m_Kpipipi2)
def m_Kpipipi1_fill(t, h): window_low = 1.86965 - window(ecms)/2. window_up = 1.86965 + window(ecms)/2. for ientry in xrange(t.GetEntries()): t.GetEntry(ientry) if not (t.m_rm_Dpipi > window_low and t.m_rm_Dpipi < window_up): continue h.Fill(t.m_m_Kpipipi1)
def exoMassMapping(exomass=None): # Make exo_planet regression # Map min(exo) ==> 8.7E-5 (Mass of mercury) # Map av(ex) ====> 0.176 (Av mass of solar system) # Map max(exo) ==> 1.1*max(exo) x1,x2,x3 = min(exo_mass_data), sum(exo_mass_data)/len(exo_mass_data), max(exo_mass_data) X = numpy.matrix([[x1**2,x1,1], [x2**2,x2,1], [x3**2,x3,1]]) Y = numpy.matrix([[8.7E-5],[0.176],[1.1*x3]]) Z = numpy.linalg.solve(X,Y) if exomass is None: return lambda x: window(float(Z[0])*x*x+float(Z[1])*x+float(Z[2]),x1*0.95) else: return window(float(Z[0])*exomass*exomass+float(Z[1])*exomass+float(Z[2]),x1*0.95)
def plot_vortex(a, vortices): outfile = open('../results/vortices.dat', 'w') outfile.write('radius gamma x_index y_index u_c v_c dist corr\n') for i, line in enumerate(vortices): #print(line) outfile.write("{0} {1} {2} {3} {4} {5} {6} {7} \n".format( line[0], line[1], line[2], line[3], line[4], line[5], line[6], line[7])) print('r:', line[0], 'gamma:', line[1], 'x:', line[2], 'y', line[3], 'dist', line[6], 'corr', line[7]) dx = a.dx[5] - a.dx[4] dy = a.dy[5] - a.dy[4] x_index, y_index, u_data, v_data = tools.window( a, round(line[2] / dx, 0), round(line[3] / dy, 0), line[6]) u_model, v_model = fitting.velocity_model(line[0], line[1], line[2], line[3], line[4], line[5], x_index, y_index) corr = fitting.correlation_coef(u_data, v_data, u_model, v_model) plot_fit(x_index, y_index, u_data, v_data, u_model, v_model, line[2], line[3], line[0], line[1], line[4], line[5], corr, i, 1) corr = fitting.correlation_coef(u_data - line[4], v_data - line[5], u_model - line[4], v_model - line[5]) plot_fit(x_index, y_index, u_data - line[4], v_data - line[5], u_model - line[4], v_model - line[5], line[2], line[3], line[0], line[1], line[4], line[5], corr, i, 2)
def get_vortices(a, peaks, vorticity): """General routine to check if the detected vortex is a real vortex :param a: data from the input file :param peaks: list of vortices :param vorticity: calculated field :type a: int, float, ... :type peaks: list :type vorticity: array :returns: vortices :rtype: list """ b = list() vortices = list() j = 0 dx = a.dx[5]-a.dx[4] #ugly dy = a.dy[5]-a.dy[4] for i in range(len(peaks[0])): x_center_index = peaks[1][i] y_center_index = peaks[0][i] print(i, " Processing detected swirling at (x, y)", x_center_index, y_center_index) coreR = 2*(a.dx[5]-a.dx[4]) #ugly change someday gamma = vorticity[y_center_index, x_center_index]*np.pi*coreR**2 b = full_fit(coreR, gamma, a, x_center_index, y_center_index) if b[6] < 2: corr = 0 else: x_index, y_index, u_data, v_data = tools.window(a, round(b[2]/dx, 0), round(b[3]/dy, 0), b[6]) u_model, v_model = velocity_model(b[0], b[1], b[2], b[3], b[4], b[5], x_index, y_index) corr = correlation_coef(u_data-b[4], v_data-b[5], u_model-b[4], v_model-b[5]) if corr > 0.75: print("Accepted! corr = %s (vortex %s)" %(corr, j)) vortices.append([b[0], b[1], b[2], b[3], b[4], b[5], b[6], corr]) j += 1 return vortices
def full_fit(coreR, gamma, a, x_center_index, y_center_index): """Full fitting procedure :param coreR: core radius of the vortex :param gamma: circulation contained in the vortex :param a: data from the input file :param x_center_index: x index of the vortex center :param y_center_index: y index of the vortex center :type coreR: float :type gamma: float :type a: class :type x_center_index: int :type y_center_index: int :returns: fitted[i], dist :rtype: list """ fitted = [[], [], [], [], [], []] fitted[0] = coreR fitted[1] = gamma fitted[2] = a.dx[x_center_index] fitted[3] = a.dy[y_center_index] dx = a.dx[5] - a.dx[4] #ugly dy = a.dy[5] - a.dy[4] corr = 0.0 for i in range(5): x_center_index = int(round(fitted[2] / dx)) y_center_index = int(round(fitted[3] / dy)) if x_center_index >= a.u.shape[1]: x_center_index = a.u.shape[1] - 1 if x_center_index <= 2: x_center_index = 3 if y_center_index >= a.v.shape[0]: y_center_index = a.v.shape[0] - 1 r1 = fitted[0] x1 = fitted[2] y1 = fitted[3] dist = int(round(fitted[0] / dx, 0)) + 1 if fitted[0] < 2 * dx: break fitted[4] = a.u[y_center_index, x_center_index] #u_conv fitted[5] = a.v[y_center_index, x_center_index] #v_conv x_index, y_index, u_data, v_data = tools.window( a, x_center_index, y_center_index, dist) fitted = fit(fitted[0], fitted[1], x_index, y_index, fitted[2], fitted[3], u_data, v_data, fitted[4], fitted[5], i) if i > 0: # break if radius variation is less than 10% and accepts if abs(fitted[0] / r1 - 1) < 0.1: if (abs((fitted[2] / x1 - 1)) < 0.1) or (abs( (fitted[3] / y1 - 1)) < 0.1): break # break if x or y position is out of the window and discards if (abs((fitted[2] - x1)) > dist * dx) or (abs( (fitted[3] - y1)) > dist * dy): dist = 0 break return fitted[0], fitted[1], fitted[2], fitted[3], fitted[4], fitted[ 5], dist
def normalisePlanetaryOrbits(self, minSep=0.2*AU): print("running orbital normalisation") if self.radius + minSep >= Planets[0].semi_major_axis: print("Planet IN star") self.shiftOrbit(0, self.radius+minSep) for i,(p1, p2) in enumerate(window(self.Planets)): if p1.semi_major_axis + minSep >= p2.semi_major_axis: self.shiftOrbit(i+1, p1.semi_major_axis+minSep)
def full_fit(coreR, gamma, a, xCenter, yCenter): model = [[],[],[],[],[],[]] model[0] = coreR model[1] = gamma model[2] = a.dx[xCenter] model[3] = a.dy[yCenter] dx = a.dx[5]-a.dx[4] #ugly dy = a.dy[5]-a.dy[4] dist = int(round(model[0]/dx,0)) + 2 u_conv = a.u[xCenter, yCenter] v_conv = a.v[xCenter, yCenter] X, Y, Uw, Vw = tools.window(a,xCenter,yCenter,dist) model = fit(model[0], model[1], X, Y, model[2], model[3], Uw, Vw, u_conv, v_conv) uMod, vMod = velocity_model(model[0], model[1], model[2], model[3], u_conv, v_conv,X,Y) corr = correlation_coef(Uw,Vw,uMod,vMod) print('dist:',dist,'Radius',round(model[0],3),'Gamma', round(model[1],3),'corr',round(corr,3),'x',model[2], 'y',model[3],'u_conv',u_conv,'v_conv',v_conv, 'xC',xCenter,'yC',yCenter) plot.plot_debug(X, Y, Uw, Vw, uMod, vMod, model[0], corr) if (corr > 0.75): plot.plot_debug(X, Y, Uw, Vw, uMod, vMod, model[0], corr) xCenter = int(round(model[2]/dx,0)) yCenter = int(round(model[3]/dy,0)) dist = int(round(2*model[0]/dx,0)) u_conv = a.u[xCenter, yCenter] v_conv = a.v[xCenter, yCenter] X, Y, Uw, Vw = tools.window(a,xCenter,yCenter,dist) model = fit(model[0], model[1], X, Y, model[2], model[3], Uw, Vw, u_conv, v_conv) uMod, vMod = velocity_model(model[0], model[1], model[2], model[3], u_conv, v_conv,X,Y) corr = correlation_coef(Uw,Vw,uMod,vMod) #print('dist:',dist,'Radius',round(model[0],3),'Gamma', # round(model[1],3),'corr',round(corr,3),'x',model[2], # 'y',model[3],'u_conv',u_conv,'v_conv',v_conv, # 'xC',xCenter,'yC',yCenter) return xCenter, yCenter, model[1], model[0], corr, dist, model[2], model[3], u_conv, v_conv
def parseText(self, molecules, sep=None): """Parse text and store in Markov dictionary. @param molecules is a list of `sentences`. @param sep separates complex molecules Note that sentences does not mean grammatical sentences, and instead form the "units" of the generator. For example, to generate individual words, the molecules would be words and the atoms would be letters. sep would be None. To generate phrases or prose, the molecules would be sentences and the atoms would be words. sep would be " ". """ yieldEnd = ([i] for i in [endMarker]) if sep is None: get_atom = lambda molecule: (i for i in molecule) #chain((i for i in molecule),yieldEnd) else: get_atom = lambda molecule: (i for i in molecule.split(sep)) #chain((i for i in molecule.split(sep)),yieldEnd)#+[endMarker]) #chain(yieldStart, (i for i in molecule.split(sep)),yieldEnd) if isinstance(molecules, str): molecules = [molecules] for molecule in molecules: if self.noteStarts: s = tuple(islice(get_atom(molecule),self.keySize)) if len(s)==self.keySize: self.starting.append(s) if self.noteEnds: loop_over = chain(get_atom(molecule),yieldEnd) else: loop_over = get_atom(molecule) for atoms in window(loop_over,self.keySize+1): self.addKey(atoms[:-1],atoms[-1])
def parseText(self, molecules, sep=None): """Parse text and store in Markov dictionary. @param molecules is a list of `sentences`. @param sep separates complex molecules Note that sentences does not mean grammatical sentences, and instead form the "units" of the generator. For example, to generate individual words, the molecules would be words and the atoms would be letters. sep would be None. To generate phrases or prose, the molecules would be sentences and the atoms would be words. sep would be " ". """ yieldEnd = ([i] for i in [endMarker]) if sep is None: get_atom = lambda molecule: (i for i in molecule) #chain((i for i in molecule),yieldEnd) else: get_atom = lambda molecule: (i for i in molecule.split(sep)) #chain((i for i in molecule.split(sep)),yieldEnd)#+[endMarker]) #chain(yieldStart, (i for i in molecule.split(sep)),yieldEnd) if isinstance(molecules, str): molecules = [molecules] for molecule in molecules: if self.noteStarts: s = tuple(islice(get_atom(molecule), self.keySize)) if len(s) == self.keySize: self.starting.append(s) if self.noteEnds: loop_over = chain(get_atom(molecule), yieldEnd) else: loop_over = get_atom(molecule) for atoms in window(loop_over, self.keySize + 1): self.addKey(atoms[:-1], atoms[-1])
peaks = tools.find_peaks(swirling, args.threshold, args.boxsize) print("Vortices found:", len(peaks[0])) #---- PEAKS DIRECTION OF ROTATION ----# dirL, dirR = tools.direction_rotation(vorticity, peaks) #---- MODEL FITTING ----# vortices = list() if (args.plot_x == 'fit') and (args.xy == [0, 0]): vortices = fitting.get_vortices(a, peaks, vorticity, args.rmax) print('---- Accepted vortices ----') print(len(vortices)) else: print("No fitting") #---- PLOTTING OPTIONS ----# if args.xy != [0, 0]: x = int(args.xy[0]) y = int(args.xy[1]) swirlingw = swirling[y - 10:y + 10, x - 10:x + 10] x_index, y_index, u_data, v_data = tools.window(a, x, y, 10) plot.plot_quiver(x_index, y_index, u_data, v_data, swirlingw) if args.plot_x == 'detect': plot.plot_detect(dirL, dirR, swirling, args.flip) if args.plot_x == 'fields': plot.plot_fields(a, vorticity) if args.plot_x == 'fit': plot.plot_accepted(a, vortices, swirling, args.output_dir, time_step) plot.plot_vortex(a, vortices, args.output_dir, time_step)
def main(): args = sys.argv[1:] if len(args) < 8: return usage() dst_path = args[0] sample = args[1] decay = args[2] mode = args[3] type = args[4] ecms = args[5] cms = args[6] dst_num = args[7] sys.stdout.write('Scanning %s...\n' % dst_path) dst_list = [] print '***************************************start to search***************************************' dst_list = search(dst_list, dst_path, '.dst') print '***************************************searching ending**************************************' dst_list_groups = group_files_by_num(dst_list, dst_num) i = 0 for dst_list_fill in dst_list_groups: file_name = sample + '_' + decay + '_' + mode + '_' + ecms + '_' + str( i) + '.txt' f = open(file_name, 'w') f.write('#include "$ROOTIOROOT/share/jobOptions_ReadRec.txt"\n') f.write('#include "$MAGNETICFIELDROOT/share/MagneticField.txt"\n') f.write('#include "$DTAGALGROOT/share/jobOptions_dTag.txt"\n') f.write('#include "$DDECAYALGROOT/share/jobOptions_DDecay.txt"\n') f.write('#include "$MEASUREDECMSSVCROOT/share/anaOptions.txt"\n') f.write('DDecay.IsMonteCarlo = true;\n') f.write('DDecay.Ecms = ' + str(float(cms) / 1000.) + ';\n') f.write('DDecay.W_m_Kpipi = ' + str(width(ecms[0:4])) + ';\n') f.write('DDecay.W_rm_Dpipi = ' + str(window(ecms[0:4])) + ';\n') f.write('\n') f.write('DTag.NeutralDReconstruction = true;\n') f.write('DTag.ChargedDReconstruction = true;\n') f.write('DTag.DsReconstruction = true;\n') f.write('\n') f.write('NeutralDSelector.UseMbcCuts = false;\n') f.write('eutralDSelector.UseDeltaECuts = false;\n') f.write('NeutralDSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('ChargedDSelector.UseMbcCuts = false;\n') f.write('ChargedDSelector.UseDeltaECuts = false;\n') f.write('ChargedDSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('DsSelector.UseMbcCuts = false;\n') f.write('DsSelector.UseDeltaECuts = false;\n') f.write('DsSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('// Input REC or DST file name\n') f.write('EventCnvSvc.digiRootInputFile = {\n') for dst in dst_list_fill: if dst != dst_list_fill[-1]: temp = '"' + dst + '",\n' f.write(temp) if dst == dst_list_fill[-1]: temp = '"' + dst + '"\n' f.write(temp) f.write('};\n') f.write('\n') f.write( '// Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL )\n' ) f.write('MessageSvc.OutputLevel =6;\n') f.write('\n') f.write('// Number of events to be processed (default is 10)\n') f.write('ApplicationMgr.EvtMax = -1;\n') f.write('\n') f.write('ApplicationMgr.HistogramPersistency = "ROOT";\n') f.write( 'NTupleSvc.Output = {\"FILE1 DATAFILE=\'/scratchfs/bes/$USER/bes/DDPIPI/v0.2/' + sample + '/' + type + '/' + ecms + '/sys_err/psipp_shape/rootfile/' + sample + '_' + decay + '_' + mode + '_' + ecms + '_' + str(i) + '.root' + '\' OPT=\'NEW\' TYP=\'ROOT\'\"};\n') f.close() i = i + 1 print 'All done!'
else: print("saving file", args.outfilename) #---- PLOTTING OPTIONS ----# if args.plot_x == 'detect': plot.plot_detection(dirL, dirR, swirling, args.flip) elif args.plot_x == 'fields': plot.plot_fields(a, vorticity) elif args.plot_x == 'fields2': plot.plot_fields2(a, vorticity, args.flip) elif args.plot_x == 'quiverRuim': dist = 10 for i in range(len(peaks[0])): xCenter = peaks[0][i] yCenter = peaks[1][i] X, Y, Uw, Vw = tools.window(a, xCenter, yCenter, dist) swirlingw = swirling[xCenter - dist:xCenter + dist, yCenter - dist:yCenter + dist] #reuse window function? if (xCenter > dist) and (yCenter > dist): print('x1:', xCenter, 'x2:', yCenter, 'swirl:', peaks[2][i]) plot.plot_quiver(X, Y, Uw, Vw, swirlingw) elif args.plot_x == 'quiver': for i in range(len(vortices)): swirlingw = swirling[vortices[i][0] - vortices[i][5]:vortices[i][0] + vortices[i][5], vortices[i][1] - vortices[i][5]:vortices[i][1] + vortices[i][5]] X, Y, Uw, Vw = tools.window(a, vortices[i][0], vortices[i][1], vortices[i][5]) uMod, vMod = fitting.velocity_model(vortices[i][3], vortices[i][2],
def plot(path, leg_title, ecms, xmin, xmax, ymin, ymax, bins): try: f_data = TFile(path[0]) t_data = f_data.Get('save') entries_data = t_data.GetEntries() logging.info('data entries :'+str(entries_data)) except: logging.error(path[0] + ' is invalid!') sys.exit() set_pub_style() set_prelim_style() from ROOT import gStyle colors = array('i', 7*[0]) for i in range(7): colors[i] = 18 - i gStyle.SetPalette(7, colors) mbc = TCanvas('mbc', 'mbc', 800, 600) xtitle = 'M(K^{-}#pi^{+}#pi^{+}) (GeV)/c^{2}' ytitle = 'RM(D^{+}#pi_{d}^{+}#pi_{d}^{-}) (GeV)/c^{2}' h_data = TH2F('scatter_data', 'scatter plot of M(Kpipi) and Rm(Dpipi)', bins, xmin, xmax, bins, ymin, ymax) format_data_hist(h_data) name_axis(h_data, xtitle, ytitle) fill(t_data, h_data) h_data.SetMarkerSize(0.2) # h_data.Draw('box') h_data.Draw('COLZ') x_move = width(ecms) y_move = window(ecms) x_offset = width(ecms) y_offset = window(ecms) x0 = 1.86965 - 5/2. * x_move y0 = 1.86965 + 5/2. * y_move mats = make_matrix(3, 3, (x0, y0), x_move, x_offset, y_move, y_offset) VarsManager = locals() for i, mat in enumerate(mats): x_list = [] y_list = [] for point in mat: x, y = point x_list.append(x) y_list.append(y) x, y = array('d', x_list), array('d', y_list) VarsManager['box_' + str(i)] = TPolyLine(5, x, y) if i == 4: color = ROOT.kRed else: color = ROOT.kBlue VarsManager['box_' + str(i)].SetLineColor(color) VarsManager['box_' + str(i)].SetLineWidth(4) if i == 1 or i == 3 or i == 5 or i == 7: VarsManager['box_' + str(i)].SetLineStyle(9) if i == 0 or i == 2 or i == 6 or i == 8: VarsManager['box_' + str(i)].SetLineStyle(2) VarsManager['box_' + str(i)].Draw('same') # if i == 0: left, right, bottom, top = position_convert(min(x), xmin, xmax) + 0.0045, position_convert(max(x), xmin, xmax) + 0.025, position_convert(min(y), ymin, ymax) + 0.0045, position_convert(max(y), ymin, ymax) + 0.025 # elif i == 1 or i == 2: left, right, bottom, top = position_convert(min(x), xmin, xmax), position_convert(max(x), xmin, xmax) + 0.025, position_convert(min(y), ymin, ymax), position_convert(max(y), ymin, ymax) + 0.025 # elif i == 3: left, right, bottom, top = position_convert(min(x), xmin, xmax) + 0.0045, position_convert(max(x), xmin, xmax), position_convert(min(y), ymin, ymax) + 0.0045, position_convert(max(y), ymin, ymax) # elif i == 6: left, right, bottom, top = position_convert(min(x), xmin, xmax) + 0.0045, position_convert(max(x), xmin, xmax) - 0.025, position_convert(min(y), ymin, ymax) + 0.0045, position_convert(max(y), ymin, ymax) - 0.025 # elif i == 6 or i == 7 or i == 8: left, right, bottom, top = position_convert(min(x), xmin, xmax), position_convert(max(x), xmin, xmax) - 0.025, position_convert(min(y), ymin, ymax), position_convert(max(y), ymin, ymax) - 0.025 # else: left, right, bottom, top = position_convert(min(x), xmin, xmax), position_convert(max(x), xmin, xmax), position_convert(min(y), ymin, ymax), position_convert(max(y), ymin, ymax) # VarsManager['pt_' + str(i)] = TPaveText(left, bottom, right, top, "BRNDC") # set_pavetext(VarsManager['pt_' + str(i)]) # VarsManager['pt_' + str(i)].SetTextSize(0.06) # VarsManager['pt_' + str(i)].Draw() # if i == 0: VarsManager['pt_' + str(i)].AddText('(-1, 1)') # if i == 1: VarsManager['pt_' + str(i)].AddText(' (0, 1) ') # if i == 2: VarsManager['pt_' + str(i)].AddText(' (1, 1) ') # if i == 3: VarsManager['pt_' + str(i)].AddText('(-1, 0)') # if i == 4: VarsManager['pt_' + str(i)].AddText(' (0, 0) ') # if i == 5: VarsManager['pt_' + str(i)].AddText(' (1, 0) ') # if i == 6: VarsManager['pt_' + str(i)].AddText('(-1, -1)') # if i == 7: VarsManager['pt_' + str(i)].AddText(' (0, -1)') # if i == 8: VarsManager['pt_' + str(i)].AddText(' (1, -1)') # VarsManager['pt_' + str(i)].SetTextColor(color) pt = TPaveText(0.75, 0.77, 0.85, 0.87, "BRNDC") set_pavetext(pt) pt.Draw() pt.AddText(leg_title) if not os.path.exists('./figs/'): os.makedirs('./figs/') mbc.SaveAs('./figs/scatter_m_Kpipi_rm_Dpipi_'+str(ecms)+'.pdf') raw_input('Press <Enter> to end...')
def write_file(ecms, cms, runNo, dst_list, file_num=-1): if file_num == -1: file_name = 'data' + str(runNo) + '.txt' else: file_name = 'data' + str(runNo) + '-' + str(file_num) + '.txt' f = open(file_name, 'w') f.write('#include "$ROOTIOROOT/share/jobOptions_ReadRec.txt"\n') f.write('#include "$MAGNETICFIELDROOT/share/MagneticField.txt"\n') f.write('#include "$DTAGALGROOT/share/jobOptions_dTag.txt"\n') f.write('#include "$DDECAYALGROOT/share/jobOptions_DDecay.txt"\n') f.write('#include "$MEASUREDECMSSVCROOT/share/anaOptions.txt"\n') f.write('DDecay.IsMonteCarlo = false;\n') f.write('DDecay.Ecms = ' + str(float(cms) / 1000.) + ';\n') f.write('DDecay.W_m_Kpipi = ' + str(width(ecms[0:4])) + ';\n') f.write('DDecay.W_rm_Dpipi = ' + str(window(ecms[0:4])) + ';\n') f.write('\n') f.write('DTag.NeutralDReconstruction = true;\n') f.write('DTag.ChargedDReconstruction = true;\n') f.write('DTag.DsReconstruction = true;\n') f.write('\n') f.write('NeutralDSelector.UseMbcCuts = false;\n') f.write('eutralDSelector.UseDeltaECuts = false;\n') f.write('NeutralDSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('ChargedDSelector.UseMbcCuts = false;\n') f.write('ChargedDSelector.UseDeltaECuts = false;\n') f.write('ChargedDSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('DsSelector.UseMbcCuts = false;\n') f.write('DsSelector.UseDeltaECuts = false;\n') f.write('DsSelector.UseDeltaMassCuts = true;\n') f.write('\n') f.write('// Input REC or DST file name\n') f.write('EventCnvSvc.digiRootInputFile = {\n') print 'processing runNo: ' + str(runNo) + ' with ' + str( len(dst_list)) + ' dst files(' + str(file_num) + ')...' for dst in dst_list: if dst != dst_list[-1]: temp = '"' + dst + '",\n' f.write(temp) if dst == dst_list[-1]: temp = '"' + dst + '"\n' f.write(temp) f.write('};\n') f.write('\n') f.write( '// Set output level threshold (2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL )\n' ) f.write('MessageSvc.OutputLevel =6;\n') f.write('\n') f.write('// Number of events to be processed (default is 10)\n') f.write('ApplicationMgr.EvtMax = -1;\n') f.write('\n') f.write('ApplicationMgr.HistogramPersistency = "ROOT";\n') if file_num == -1: f.write( 'NTupleSvc.Output = {\"FILE1 DATAFILE=\'/scratchfs/bes/$USER/bes/DDPIPI/v0.2/data/' + ecms + '/' + 'data' + str(runNo) + '.root\' OPT=\'NEW\' TYP=\'ROOT\'\"};\n') else: f.write( 'NTupleSvc.Output = {\"FILE1 DATAFILE=\'/scratchfs/bes/$USER/bes/DDPIPI/v0.2/data/' + ecms + '/' + 'data' + str(runNo) + '_' + str(file_num) + '.root\' OPT=\'NEW\' TYP=\'ROOT\'\"};\n') f.close()
def plot(data_path, pt_title, ecms, xmin, xmax, xbins, mode): try: f_data = TFile(data_path) t_data = f_data.Get('save') entries_data = t_data.GetEntries() logging.info('data entries :' + str(entries_data)) except: logging.error('File paths are invalid!') sys.exit() set_pub_style() set_prelim_style() window_low = 1.86965 - window(ecms) / 2. window_up = 1.86965 + window(ecms) / 2. window_side_low_up = window_low - (window_up - window_low) window_side_low_low = window_side_low_up - (window_up - window_low) window_side_up_low = window_up + (window_up - window_low) window_side_up_up = window_side_up_low + (window_up - window_low) mbc = TCanvas('mbc', 'mbc', 800, 600) content = (xmax - xmin) / xbins * 1000 ytitle = 'Events/%.1f MeV/c^{2}' % content xtitle = 'RM(D^{+}#pi_{d}^{+}#pi_{d}^{-}) (GeV/c^{2})' h_data = TH1F('data', 'data', xbins, xmin, float(xmax)) format_data_hist(h_data) if ecms == 4420 or ecms == 4680: h_data.GetYaxis().SetTitleOffset(1.15) h_data.GetXaxis().SetTitleOffset(0.99) name_axis(h_data, xtitle, ytitle) rm_Dpipi_fill(t_data, h_data, window_low, window_up) if not os.path.exists('./figs/'): os.makedirs('./figs/') if mode == 'after' and ecms == 4230: h_data.GetYaxis().SetRangeUser(0, 1.2 * h_data.GetMaximum()) h_data.Draw('E1') if ecms == 4420 and mode == 'before': low = 380 elif ecms == 4420 and mode == 'after': low = 240 elif ecms == 4230 and mode == 'before': low = 14 elif ecms == 4230 and mode == 'after': low = 0 elif ecms == 4680 and mode == 'before': low = 950 elif ecms == 4680 and mode == 'after': low = 620 else: low = 0 top = h_data.GetMaximum() if ecms == 4680: top = top / 0.88 arrow1 = TArrow(window_low, low, window_low, 0.8 * top, 0.02, '<-') set_arrow(arrow1, ROOT.kRed) arrow1.SetLineStyle(2) arrow1.Draw() arrow2 = TArrow(window_up, low, window_up, 0.8 * top, 0.02, '<-') set_arrow(arrow2, ROOT.kRed) arrow2.SetLineStyle(2) arrow2.Draw() arrow3 = TArrow(window_side_low_low, low, window_side_low_low, 0.8 * top, 0.02, '<-') set_arrow(arrow3, ROOT.kBlue) arrow3.Draw() arrow4 = TArrow(window_side_low_up, low, window_side_low_up, 0.8 * top, 0.02, '<-') set_arrow(arrow4, ROOT.kBlue) arrow4.Draw() arrow5 = TArrow(window_side_up_low, low, window_side_up_low, 0.8 * top, 0.02, '<-') set_arrow(arrow5, ROOT.kBlue) arrow5.Draw() arrow6 = TArrow(window_side_up_up, low, window_side_up_up, 0.8 * top, 0.02, '<-') set_arrow(arrow6, ROOT.kBlue) arrow6.Draw() leg = TLegend(position_convert(0.8 * (xmax - xmin) + xmin, xmin, xmax), position_convert(0.8 * (top - low) + low, low, top), position_convert(0.95 * (xmax - xmin) + xmin, xmin, xmax), position_convert((top - low) + low, low, top), 'BRNDC') set_legend(leg, h_data, 'Data', pt_title) leg.Draw() h_data.Draw('sameE1') mbc.SaveAs('./figs/rm_Dpipi_' + str(ecms) + '_' + mode + '.pdf') raw_input('Enter anything to end...')