def showAvailableFits(): import FitManager availablefits = FitManager.get_plugins(FitManager.FitProvider) print '-->> Available fit plugins : ' for entry in availablefits: print entry print '<<--' print ' '
def doRunVdmFitter(Fill, FitName, InputGraphsFile, OutputDir, FitConfigInfo): showAvailableFits() availableFits = FitManager.get_plugins(FitManager.FitProvider) key = FitName + '_Fit' if key not in availableFits: print "Fit " + FitName + " requested via json file does not exist, nothing to fit with, exit." sys.exit(1) fitter = availableFits[FitName+'_Fit']() FitLogFile = OutputDir + FitName +'.log' fitlogfile = open(FitLogFile,'w') sysstdout = sys.stdout sys.stdout = fitlogfile sysstderr = sys.stderr sys.stderr = fitlogfile # temporarily: move graphs files over from forTmpStorage directory #list = os.listdir('./forTmpStorage/') #import shutil #for element in list: # shutil.copy('./forTmpStorage/'+element, InputDataDir) # for 2D fits if '_2D' in FitName: # test that when 2D fit function is requested, the graph file used is also a 2D one if not '2D' in InputGraphsFile: print "--?? You selected a 2D fitting function, but chose as input a graphs file without the \"2D\" in its name" print "??--" print " " sys.exit(1) if not os.path.isfile(InputGraphsFile): print "--?? Input data file ", InputGraphsFile ," does not exist" print "??--" print " " sys.exit(1) print " " print "Now open input graphs file: ", InputGraphsFile graphsAll = {} infile = open(InputGraphsFile, 'rb') graphsAll = pickle.load(infile) infile.close() # if input file is 2D graphs file, also open the corresponding 1D graph file if '_2D' in FitName: fileName1D = InputGraphsFile.replace("graphs2D", "graphs") infile1D = open(fileName1D, 'rb') graphs1D = pickle.load(infile1D) resultsAll = {} # first loop over scan numbers orderedKeyList=[] for keyAll in sorted(graphsAll.keys()): graphs = {} results = {} graphs = graphsAll[keyAll] if '_2D' in FitName: keyX = "Scan_" + keyAll.split("_")[1] keyY = "Scan_" + keyAll.split("_")[2] graphsX = graphs1D[keyX] graphsY = graphs1D[keyY] # order keys in natural order, i.e. from smallest BCID to largest # determine which of the bcid among those with collisions are indeed represented with a TGraphErrors() in the input graphs file # need to do this because PCC uses only subset of 5 bcids of all possible bcids with collisions for key in orderedIntKeysFirst(graphs.keys()): print "------>>>>" print "Now fitting BCID ", key graph = graphs[key] if '_2D' in FitName: result = fitter.doFit2D(graph, graphsX[key], graphsY[key], FitConfigInfo) for entry in result: print ">>", result, type(result) results[key] = result functions = result[0] canvas = fitter.doPlot2D(graphsX[key], graphsY[key], functions, Fill) else: result = fitter.doFit(graph, FitConfigInfo) results[key] = result functions = result[0] canvas = fitter.doPlot(graph, functions, Fill) resultsAll[keyAll] = results sys.stdout = sysstdout sys.stderr = sysstderr fitlogfile.close() print return resultsAll, fitter.table
coord = displacement coorde = [0.0 for a in coord] coord = array("d",coord) coorde = array("d", coorde) currProduct = [ a*b/1e22 for a,b in zip(fbct1, fbct2)] lumi = [a/b for a,b in zip(bxlumi,currProduct)] lumie = [a/b for a,b in zip(bxlumiErr,currProduct)] lumie = array("d",lumie) lumi = array("d",lumi) graphY = r.TGraphErrors(len(coord),coord,lumi,coorde,lumie) graphY.SetName(name) graphY.SetTitle(name) availableFits = FitManager.get_plugins(FitManager.FitProvider) fitter = availableFits['SGConst_Fit']() FitConfigFile = "fits/SGConst_Config.json" FitConfig=open(FitConfigFile) FitConfigInfo = json.load(FitConfig) FitConfig.close() result = fitter.doFit(graphX, FitConfigInfo) functions = result[0] canvas = fitter.doPlot(graphX, functions, "3804") print "X scan" for entry in fitter.table: print entry
def doRunVdmFitter(Fill, FitName, InputGraphsFile, OutputDir, FitConfigInfo): showAvailableFits() availableFits = FitManager.get_plugins(FitManager.FitProvider) key = FitName + '_Fit' if key not in availableFits: print "Fit " + FitName + " requested via json file does not exist, nothing to fit with, exit." sys.exit(1) fitter = availableFits[FitName + '_Fit']() FitLogFile = OutputDir + FitName + '.log' fitlogfile = open(FitLogFile, 'w') sysstdout = sys.stdout sys.stdout = fitlogfile sysstderr = sys.stderr sys.stderr = fitlogfile # temporarily: move graphs files over from forTmpStorage directory #list = os.listdir('./forTmpStorage/') #import shutil #for element in list: # shutil.copy('./forTmpStorage/'+element, InputDataDir) # for 2D fits if '_2D' in FitName: # test that when 2D fit function is requested, the graph file used is also a 2D one if not '2D' in InputGraphsFile: print "--?? You selected a 2D fitting function, but chose as input a graphs file without the \"2D\" in its name" print "??--" print " " sys.exit(1) if not os.path.isfile(InputGraphsFile): print "--?? Input data file ", InputGraphsFile, " does not exist" print "??--" print " " sys.exit(1) print " " print "Now open input graphs file: ", InputGraphsFile graphsAll = {} infile = open(InputGraphsFile, 'rb') graphsAll = pickle.load(infile) infile.close() print graphsAll # if input file is 2D graphs file, also open the corresponding 1D graph file if '_2D' in FitName: fileName1D = InputGraphsFile.replace("graphs2D", "graphs") infile1D = open(fileName1D, 'rb') graphs1D = pickle.load(infile1D) # print graphsList1D resultsAll = {} # first loop over scan numbers print ">>", graphsAll.keys() for keyAll in sorted(graphsAll.keys()): print "Looking at ", keyAll graphs = {} results = {} graphs = graphsAll[keyAll] if '_2D' in FitName: keyX = "Scan_" + keyAll.split("_")[1] keyY = "Scan_" + keyAll.split("_")[2] print "keyX", keyX print "keyY", keyY graphsX = graphs1D[keyX] graphsY = graphs1D[keyY] # order keys in natural order, i.e. from smallest BCID to largest # determine which of the bcid among those with collisions are indeed represented with a TGraphErrors() in the input graphs file # need to do this because PCC uses only subset of 5 bcids of all possible bcids with collisions print graphs.keys() for key in sorted(graphs.keys(), key=int): print "------>>>>" print "Now fitting BCID ", key graph = graphs[key] if '_2D' in FitName: result = fitter.doFit2D(graph, graphsX[key], graphsY[key], FitConfigInfo) for entry in result: print ">>", result, type(result) results[key] = result functions = result[0] canvas = fitter.doPlot2D(graphsX[key], graphsY[key], functions, Fill) else: result = fitter.doFit(graph, FitConfigInfo) for entry in result: print ">>", result, type(result) results[key] = result functions = result[0] canvas = fitter.doPlot(graph, functions, Fill) for entry in fitter.table: print entry resultsAll[keyAll] = results print resultsAll sys.stdout = sysstdout sys.stderr = sysstderr fitlogfile.close() return resultsAll, fitter.table
coord = displacement coorde = [0.0 for a in coord] coord = array("d", coord) coorde = array("d", coorde) currProduct = [a * b / 1e22 for a, b in zip(fbct1, fbct2)] lumi = [a / b for a, b in zip(bxlumi, currProduct)] lumie = [a / b for a, b in zip(bxlumiErr, currProduct)] lumie = array("d", lumie) lumi = array("d", lumi) graphY = r.TGraphErrors(len(coord), coord, lumi, coorde, lumie) graphY.SetName(name) graphY.SetTitle(name) availableFits = FitManager.get_plugins(FitManager.FitProvider) fitter = availableFits['SGConst_Fit']() FitConfigFile = "fits/SGConst_Config.json" FitConfig = open(FitConfigFile) FitConfigInfo = json.load(FitConfig) FitConfig.close() result = fitter.doFit(graphX, FitConfigInfo) functions = result[0] canvas = fitter.doPlot(graphX, functions, "3804") print "X scan" for entry in fitter.table: print entry
def doRunVdmFitter(Fill, FitName, InputGraphsFiles, OutputDir, PlotsTempPath, FitConfigInfo): showAvailableFits() availableFits = FitManager.get_plugins(FitManager.FitProvider) key = FitName + '_Fit' if key not in availableFits: print "Fit " + FitName + " requested via json file does not exist, nothing to fit with, exit." sys.exit(1) fitter = availableFits[FitName + '_Fit']() FitLogFile = OutputDir + FitName + '.log' fitlogfile = open(FitLogFile, 'w') sysstdout = sys.stdout sys.stdout = fitlogfile sysstderr = sys.stderr sys.stderr = fitlogfile # temporarily: move graphs files over from forTmpStorage directory #list = os.listdir('./forTmpStorage/') #import shutil #for element in list: # shutil.copy('./forTmpStorage/'+element, InputDataDir) # for 2D fits if '_2D' in FitName: # test that when 2D fit function is requested, the graph file used is also a 2D one if not '2D' in InputGraphsFiles: print "--?? You selected a 2D fitting function, but chose as input a graphs file without the \"2D\" in its name" print "??--" print " " sys.exit(1) for graphFile in InputGraphsFiles: if not os.path.isfile(graphFile): print "--?? Input data file ", graphFile, " does not exist" print "??--" print " " sys.exit(1) if (not any('VTX' in graph for graph in InputGraphsFiles) and len(InputGraphsFiles) > 1): print "--?? Input data file ", graphFile, " does not correspond to Vertex file" print "??--" print " " sys.exit(1) graphsAll_dict = {} graphsAll_list = [] resultsAll = {} for graphFile in InputGraphsFiles: print " " print "Now open input graphs file: ", graphFile infile = open(graphFile, 'rb') graphsAll_dict = pickle.load(infile) infile.close() graphsAll_list.append(graphsAll_dict) # if input file is 2D graphs file, also open the corresponding 1D graph file if '_2D' in FitName: fileName1D = InputGraphsFile.replace("graphs2D", "graphs") infile1D = open(fileName1D, 'rb') graphs1D = pickle.load(infile1D) # first loop over scan numbers orderedKeyList = [] if (len(InputGraphsFiles) == 1): for keyAll in sorted(graphsAll_dict.keys()): graphs = {} results = {} graphs = graphsAll_dict[keyAll] if '_2D' in FitName: keyX = "Scan_" + keyAll.split("_")[1] keyY = "Scan_" + keyAll.split("_")[2] graphsX = graphs1D[keyX] graphsY = graphs1D[keyY] # order keys in natural order, i.e. from smallest BCID to largest # determine which of the bcid among those with collisions are indeed represented with a TGraphErrors() in the input graphs file # need to do this because PCC uses only subset of 5 bcids of all possible bcids with collisions for key in orderedIntKeysFirst(graphs.keys()): print "------>>>>" print "Now fitting BCID ", key graph = graphs[key] if '_2D' in FitName: result = fitter.doFit2D(graph, graphsX[key], graphsY[key], FitConfigInfo) for entry in result: print ">>", result, type(result) results[key] = result functions = result[0] canvas = fitter.doPlot2D(graphsX[key], graphsY[key], functions, Fill) else: result = fitter.doFit(graph, FitConfigInfo) results[key] = result functions = result[0] canvas = fitter.doPlot(graph, functions, Fill, PlotsTempPath[0]) resultsAll[keyAll] = results table = [fitter.table] sys.stdout = sysstdout sys.stderr = sysstderr fitlogfile.close() return resultsAll, table else: #Sim Fit for (keyAll1, keyAll2) in sorted( zip(graphsAll_list[0].keys(), graphsAll_list[1].keys())): graphs = {} graphs1 = {} graphs2 = {} results = {} graphs1 = graphsAll_list[0][keyAll1] graphs2 = graphsAll_list[1][keyAll1] ds = [graphs1, graphs2] for k in graphs1.iterkeys(): graphs[k] = list(graphs[k] for graphs in ds) # order keys in natural order, i.e. from smallest BCID to largest # determine which of the bcid among those with collisions are indeed represented with a TGraphErrors() in the input graphs file # need to do this because PCC uses only subset of 5 bcids of all possible bcids with collisions for key in orderedIntKeysFirst(graphs.keys()): print "------>>>>" print "Now fitting BCID ", key result = fitter.doFit(graphs[key], FitConfigInfo) results[key] = result functions = result[0] canvas = fitter.doPlot(graphs[key][0], functions[:4], Fill, PlotsTempPath[0]) canvas = fitter.doPlot(graphs[key][1], functions[4:], Fill, PlotsTempPath[1]) sys.stdout = sysstdout sys.stderr = sysstderr fitlogfile.close() table = [fitter.table_Luminometer1, fitter.table_Luminometer2] return resultsAll, table