-
Notifications
You must be signed in to change notification settings - Fork 4
2D plotting changes #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abasnet97
wants to merge
6
commits into
master
Choose a base branch
from
2D_plotting_changes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
88f75ea
modified parse_nll script to fetch unique grid scan points for 2D plo…
abasnet97 ad4b9e5
modifying eft plotter for 2D random starting points
abasnet97 ba67d63
added a line to remove tmp.root file and also switched to using numpy…
abasnet97 43afac0
implemented tmp.root removal to ContourPlotEFT method
abasnet97 21caf2d
some minor cleaning of EFTPlotter
abasnet97 30d752e
merged master changes and cleaned the script
abasnet97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,9 +152,9 @@ def AppendStrToItemsInLst(self,in_lst,in_str): | |
|
|
||
|
|
||
| # Takes as input the name of a root file (assumed to be in ../fit_files) | ||
| # Retruns [wc vals in the scan, delta nll vals at each point] | ||
| # Returns [wc vals in the scan, delta nll vals at each point] | ||
| # Optionally removes duplicate wc points (choosing min nll) | ||
| def GetWCsNLLFromRoot(self,base_name_lst,wc,unique=False): | ||
| def GetWCsNLLFromRoot(self,base_name_lst,wc_lst,unique=False): | ||
|
|
||
| graphwcs = [] | ||
| graphnlls = [] | ||
|
|
@@ -170,7 +170,13 @@ def GetWCsNLLFromRoot(self,base_name_lst,wc,unique=False): | |
| # Get coordinates for TGraph | ||
| for entry in range(limitTree.GetEntries()): | ||
| limitTree.GetEntry(entry) | ||
| graphwcs.append(limitTree.GetLeaf(wc).GetValue(0)) | ||
| if len(wc_lst) == 1: | ||
| graphwcs.append(limitTree.GetLeaf(wc_lst[0]).GetValue(0)) | ||
| elif len(wc_lst) == 2: | ||
| graphwcs.append([limitTree.GetLeaf(wc_lst[0]).GetValue(0),limitTree.GetLeaf(wc_lst[1]).GetValue(0)]) | ||
| else: | ||
| logging.error("Cannot handle the case with more than 2 WCs!") | ||
|
|
||
| graphnlls.append(2*limitTree.GetLeaf('deltaNLL').GetValue(0)) | ||
|
|
||
| rootFile.Close() | ||
|
|
@@ -185,6 +191,28 @@ def GetWCsNLLFromRoot(self,base_name_lst,wc,unique=False): | |
| return [graphwcs,graphnlls] | ||
|
|
||
|
|
||
| def CreateNewLimitTreefor2DScan(self,name_lst,wc_lst): | ||
| graphwcs, graphnlls = self.GetWCsNLLFromRoot(name_lst,wc_lst,unique=True) | ||
| newRootFile = ROOT.TFile("tmp.root","RECREATE") #temporary root file with new limit tree | ||
| limit = ROOT.TTree("limit","limit") | ||
| wc0 = numpy.array([0],dtype='f') | ||
| wc1 = numpy.array([0],dtype='f') | ||
| deltanll = numpy.array([0],dtype='f') | ||
| #Create new branches with two WCs being scanned and deltaNLL | ||
| limit.Branch("{}".format(wc_lst[0]),wc0,"{}".format(wc_lst[0])) | ||
| limit.Branch("{}".format(wc_lst[1]),wc1,"{}".format(wc_lst[1])) | ||
| limit.Branch("deltaNLL",deltanll,"deltaNLL") | ||
|
|
||
| for idx in range(len(graphnlls)): | ||
| wc0[0] = graphwcs[idx][0] | ||
| wc1[0] = graphwcs[idx][1] | ||
| deltanll[0] = graphnlls[idx] | ||
| limit.Fill() | ||
| limit.Write() | ||
|
|
||
| return newRootFile | ||
|
|
||
|
|
||
|
|
||
| def ResetHistoFile(self, name=''): | ||
| ROOT.TFile('Histos{}.root'.format(name),'RECREATE') | ||
|
|
@@ -200,7 +228,7 @@ def LLPlot1DEFT(self, name_lst=['.test'], frozen=False, wc='', log=False): | |
| ROOT.gROOT.SetBatch(True) | ||
| canvas = ROOT.TCanvas() | ||
|
|
||
| graphwcs, graphnlls = self.GetWCsNLLFromRoot(name_lst,wc,unique=True) | ||
| graphwcs, graphnlls = self.GetWCsNLLFromRoot(name_lst,[wc],unique=True) | ||
| if graphwcs == [] or graphnlls == []: | ||
| # Something went wrong | ||
| print("Error, probably could not find root file") | ||
|
|
@@ -677,22 +705,19 @@ def BatchOverlayZoomLLPlot1DEFT(self, basename1='.EFT.SM.Float', basename2='.EFT | |
| for wc in wcs: | ||
| self.OverlayZoomLLPlot1DEFT(basename1+'.'+wc, basename2+'.'+wc, wc, log) | ||
|
|
||
| def LLPlot2DEFT(self, name='.test', wcs=[], ceiling=1, log=False, final=False): | ||
| def LLPlot2DEFT(self, name_lst=['.test'], wcs=[], ceiling=1, log=False, final=False): | ||
| if len(wcs)!=2: | ||
| logging.error("Function 'LLPlot2D' requires exactly two wcs!") | ||
| return | ||
| if not os.path.exists('../fit_files/higgsCombine{}.MultiDimFit.root'.format(name)): | ||
| logging.error("File higgsCombine{}.MultiDimFit.root does not exist!".format(name)) | ||
| return | ||
|
|
||
| ROOT.gROOT.SetBatch(True) | ||
|
|
||
| canvas = ROOT.TCanvas('c','c',800,800) | ||
|
|
||
| # Open file and draw 2D histogram | ||
| # wcs[0] is y-axis variable, wcs[1] is x-axis variable | ||
| rootFile = ROOT.TFile.Open('../fit_files/higgsCombine{}.MultiDimFit.root'.format(name)) | ||
| limitTree = rootFile.Get('limit') | ||
| rootFile = self.CreateNewLimitTreefor2DScan(name_lst,wcs) | ||
| limitTree = rootFile.limit | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line actually works? I would have expected it to be limitTree = rootFile.Get('limit') |
||
| hname = '{}{}less{}'.format(wcs[0],wcs[1],ceiling) | ||
| if log: | ||
| hname += "_log" | ||
|
|
@@ -752,7 +777,10 @@ def LLPlot2DEFT(self, name='.test', wcs=[], ceiling=1, log=False, final=False): | |
| hist.Write() | ||
| outfile.Close() | ||
| hist.SetDirectory(0) | ||
| #return hist | ||
|
|
||
| #close the tmp root file | ||
| rootFile.Close() | ||
| os.remove("tmp.root") | ||
|
|
||
| ''' | ||
| Example: | ||
|
|
@@ -924,25 +952,22 @@ def LLPlot2DVarEFT(self, names=['.test'], wcs=[], ceiling=1, log=False, final=Fa | |
| rootFile.Close() | ||
| os.system('rm ../fit_files/higgsCombine.var{}.MultiDimFit.root'.format(names[0])) | ||
|
|
||
| def ContourPlotEFT(self, name='.test', wcs=[], final=False): | ||
| def ContourPlotEFT(self, name_lst=['.test'], wcs=[], final=False): | ||
| #hist2d = self.LLPlot2DEFT(name,wcs,9,False) | ||
| #hist = ROOT.TH2F('hist', hname, points, self.wc_ranges[wcs[1]][0], self.wc_ranges[wcs[1]][1], points, self.wc_ranges[wcs[0]][0], self.wc_ranges[wcs[0]][1]) | ||
| #limitTree.Draw('2*(deltaNLL-{}):{}:{}>>hist({},{},{},{},{},{})'.format(minZ,wcs[1],wcs[0],points,self.wc_ranges[wcs[0]][0],self.wc_ranges[wcs[0]][1],points,self.wc_ranges[wcs[1]][0],self.wc_ranges[wcs[1]][1]), '2*(deltaNLL-{})<{}'.format(minZ,ceiling), 'prof colz') | ||
| if len(wcs)!=2: | ||
| logging.error("Function 'ContourPlot' requires exactly two wcs!") | ||
| return | ||
| if not os.path.exists('../fit_files/higgsCombine{}.MultiDimFit.root'.format(name)): | ||
| logging.error("File higgsCombine{}.MultiDimFit.root does not exist!".format(name)) | ||
| return | ||
|
|
||
| best2DeltaNLL = 1000000 | ||
| ROOT.gROOT.SetBatch(True) | ||
| canvas = ROOT.TCanvas('c','c',800,800) | ||
|
|
||
| # Get Grid scan and copy to h_contour | ||
| # wcs[0] is y-axis variable, wcs[1] is x-axis variable | ||
| gridFile = ROOT.TFile.Open('../fit_files/higgsCombine{}.MultiDimFit.root'.format(name)) | ||
| gridTree = gridFile.Get('limit') | ||
| gridFile = self.CreateNewLimitTreefor2DScan(name_lst,wcs) | ||
| gridTree = gridFile.limit | ||
| minZ = gridTree.GetMinimum('deltaNLL') | ||
| points = 100 | ||
| #gridTree.Draw('2*(deltaNLL-{}):{}:{}>>+hist'.format(minZ,wcs[0],wcs[1]), '2*(deltaNLL-{})<{}'.format(minZ,9)) | ||
|
|
@@ -1042,7 +1067,8 @@ def ContourPlotEFT(self, name='.test', wcs=[], final=False): | |
| self.CMS_extra.SetTextFont(52) | ||
| if not final: self.CMS_extra.Draw('same') | ||
| scan_name = 'Other WCs profiled' | ||
| if 'Froz' in name or 'Freeze' in name or 'frozen' in name: | ||
|
|
||
| if 'Froz' in [name for name in name_lst] or 'Freeze' in [name for name in name_lst] or 'frozen' in [name for name in name_lst]: | ||
| scan_name = 'Other WCs fixed to SM' | ||
| self.scan_type = ROOT.TLatex(0.15, 0.885, scan_name) | ||
| self.scan_type.SetNDC(1) | ||
|
|
@@ -1168,6 +1194,10 @@ def ContourPlotEFT(self, name='.test', wcs=[], final=False): | |
|
|
||
| ROOT.gStyle.SetPalette(57) | ||
|
|
||
| #close the tmp root file | ||
| gridFile.Close() | ||
| os.remove("tmp.root") | ||
|
|
||
| def LLPlot1DSM(self, name='.test', param='', log=False): | ||
| if not param: | ||
| logging.error("No parameter specified!") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would be more efficient to pass around the tree instead of making a temporary file. Don't worry about doing that in this PR, but maybe just something to think about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea. I think my logic back then was that this function would allow us to dump out a root file (if need be), and we could investigate the TTree inside this file if we wanted to. Since this was 2 years ago, I definitely didn't have as good of an understanding of the code as I have now, so I would probably have opted for a different way.