Skip to content

Commit

Permalink
Merge pull request #42 from lcorcodilos/dev
Browse files Browse the repository at this point in the history
Handle a few of the issues before Beta 1.4
  • Loading branch information
lcorcodilos authored Mar 19, 2021
2 parents b1c0ee5 + debbd73 commit c2dcde5
Show file tree
Hide file tree
Showing 15 changed files with 671 additions and 18 deletions.
48 changes: 46 additions & 2 deletions TIMBER/Analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

from TIMBER.Utilities.CollectionGen import BuildCollectionDict, GetKeyValForBranch, StructDef, StructObj
from TIMBER.Tools.Common import GetHistBinningTuple, CompileCpp, ConcatCols, GetStandardFlags
from TIMBER.Tools.Common import GetHistBinningTuple, CompileCpp, ConcatCols, GetStandardFlags, ExecuteCmd
from clang import cindex
from collections import OrderedDict

Expand Down Expand Up @@ -146,7 +146,7 @@ def __init__(self,fileName,eventsTreeName="Events",runTreeName="Runs", createAll
continue
else:
break
self.lhaid = str(int(self.lhaid)-1) if self.lhaid[-1] == 1 else self.lhaid
self.lhaid = str(int(self.lhaid)-1) if self.lhaid[-1] == "1" else self.lhaid
print ('LHA ID: '+self.lhaid)

self.ActiveNode = self.BaseNode
Expand Down Expand Up @@ -222,6 +222,27 @@ def Snapshot(self,columns,outfilename,treename,lazy=False,openOption='RECREATE')
'''@see Node#Snapshot'''
self.ActiveNode.Snapshot(columns,outfilename,treename,lazy,openOption)

def SaveRunChain(self,filename,merge=True):
'''Save the Run tree (chain of all input files) to filename.
If filename already exists, some staging will occur to properly
merge the files via hadd.
@param filename (str): Output file name.
@param merge (bool, optional): Whether to merge with a file that already exists. Defaults to True.
Returns:
None
'''
if (not os.path.exists(filename)) or (not merge): # If it doesn't already exist, nothing special
self.RunChain.Merge(filename)
elif merge:
merge_filename = filename.replace('.root','_temp1.root')
current_filename = filename.replace('.root','_temp2.root')
ExecuteCmd('cp %s %s'%(filename, current_filename)) # copy existing file to <filename>_temp2.root
self.RunChain.Merge(merge_filename) # create merged tree as <filename>_temp1.root
ExecuteCmd('hadd -f %s %s %s'%(filename,merge_filename,current_filename)) # hadd them together into original filename (force overwrite not the greatest)
ExecuteCmd('rm %s %s'%(merge_filename,current_filename)) # clean up

def Range(self,*argv):
'''@see Node#Range'''
return self.SetActiveNode(self.ActiveNode.Range(*argv))
Expand Down Expand Up @@ -840,6 +861,29 @@ def MakeWeightCols(self,name='',node=None,correctionNames=None,dropList=[]):
# self.TrackNode(returnNode)
return self.SetActiveNode(returnNode)

def GetWeightName(self,corr,variation,name=""):
'''Return the branch/column name of the requested weight
@param corr (str,Correction): Either the correction object or the name of the correction.
@param variation (str): "up" or "down".
@param name (str,optional): Name given MakeWeightCols to denote group of weight columns. Defaults to "".
Raises:
NameError: If weight name does not exist in the columns.
Returns:
str: Name of the requested weight branch/column.
'''
if isinstance(corr,Correction):
corrname = corr.name
elif isinstance(corr,str):
corrname = corr
namemod = '' if name == '' else '_'+name
weightname = 'weight%s__%s_%s'%(namemod,corrname,variation)
if weightname not in self.DataFrame.GetColumnNames():
raise NameError("The weight name `%s` does not exist in the current columns. Are you sure the correction has been made and MakeWeightCols has been called?"%weightname)
return weightname

def MakeTemplateHistos(self,templateHist,variables,node=None):
'''Generates the uncertainty template histograms based on the weights created by #MakeWeightCols().
Expand Down
6 changes: 6 additions & 0 deletions activate_ext.csh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if (`echo "$PATH" | grep "$TIMBERPATH"` == "") then
setenv PATH ${PATH}:${TIMBERPATH}
echo 'TIMBER added to PATH'
else
echo 'TIMBER already on PATH'
endif
87 changes: 87 additions & 0 deletions docs/archive_8h_source.html

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions docs/archive__entry_8h_source.html

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions docs/class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer-members.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,21 @@
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#ade0c62b73ea95b2f11ff8f5add708066">GetFlagString</a>(self, flagList=GetStandardFlags())</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a1940e059a8d927b3b6524f289ecc882f">GetTrackedNodeNames</a>(self)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a818bf6c1ef57461de293ebf6a4c7ea6a">GetTriggerString</a>(self, trigList)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a1cbf92036a120cc45e7bb032c3d61296">isData</a></td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#aeb0781b4175a60575386701b2ac1cc4d">lhaid</a></td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a033c29fbbeb320baadaec86ca25ff829">MakeHistsWithBinning</a>(self, histDict, name='', weight=None)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a611faeda8b08b76181109820e549c232">MakeTemplateHistos</a>(self, templateHist, variables, node=None)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#af222479f97b45564dfcc91fec275c48b">MakeWeightCols</a>(self, name='', node=None, correctionNames=None, dropList=[])</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a2f0e7e0c026da9b2cbc160816a2db28b">MergeCollections</a>(self, name, collectionNames)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a3eb0b4446dc99738630ed127b7184345">Nminus1</a>(self, cutgroup, node=None)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#aa933d8e2ef227f994f60ee3b278eb0f6">ObjectFromCollection</a>(self, name, basecoll, index, skip=[])</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#ae4125cd5a36c17e021b2a6a1af9c4fec">preV6</a></td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a2ef44f04939b9ca846de543ef8c8676e">PrintNodeTree</a>(self, outfilename, verbose=False, toSkip=[])</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a361306a468fa48145cf99ee48c82bf25">Range</a>(self, argv)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a1c671ab3d2fef88e680beb8299eb4962">ReorderCollection</a>(self, name, basecoll, newOrderCol, skip=[])</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a3f5844d119f0a72b4f647fbffdb114ce">RunChain</a></td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a2f8118d1dc9a46dd6155791323a8ad63">GetWeightName</a>(self, corr, variation, name=&quot;&quot;)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a1cbf92036a120cc45e7bb032c3d61296">isData</a></td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#aeb0781b4175a60575386701b2ac1cc4d">lhaid</a></td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a033c29fbbeb320baadaec86ca25ff829">MakeHistsWithBinning</a>(self, histDict, name='', weight=None)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a611faeda8b08b76181109820e549c232">MakeTemplateHistos</a>(self, templateHist, variables, node=None)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#af222479f97b45564dfcc91fec275c48b">MakeWeightCols</a>(self, name='', node=None, correctionNames=None, dropList=[])</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a2f0e7e0c026da9b2cbc160816a2db28b">MergeCollections</a>(self, name, collectionNames)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a3eb0b4446dc99738630ed127b7184345">Nminus1</a>(self, cutgroup, node=None)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#aa933d8e2ef227f994f60ee3b278eb0f6">ObjectFromCollection</a>(self, name, basecoll, index, skip=[])</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#ae4125cd5a36c17e021b2a6a1af9c4fec">preV6</a></td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a2ef44f04939b9ca846de543ef8c8676e">PrintNodeTree</a>(self, outfilename, verbose=False, toSkip=[])</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a361306a468fa48145cf99ee48c82bf25">Range</a>(self, argv)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a1c671ab3d2fef88e680beb8299eb4962">ReorderCollection</a>(self, name, basecoll, newOrderCol, skip=[])</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a3f5844d119f0a72b4f647fbffdb114ce">RunChain</a></td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a71c3df3ecfe0afd1abe50caabea431c6">SaveRunChain</a>(self, filename, merge=True)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#a3f19f4e3f9344e283f5cf6ae2371fc70">SetActiveNode</a>(self, node)</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr class="even"><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#ad3b30a4c790299b3affccd8a9bf9bd17">silent</a></td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
<tr><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html#ac9396d0acbc67a31bbae81c20944900c">Snapshot</a>(self, columns, outfilename, treename, lazy=False, openOption='RECREATE')</td><td class="entry"><a class="el" href="class_t_i_m_b_e_r_1_1_analyzer_1_1analyzer.html">analyzer</a></td><td class="entry"></td></tr>
Expand Down
Loading

0 comments on commit c2dcde5

Please sign in to comment.