<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Josh Cogan&#039;s Projects &#187; scripts</title>
	<atom:link href="http://joshcogan.com/wp/tag/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://joshcogan.com/wp</link>
	<description>Fun stuff Josh works on</description>
	<lastBuildDate>Tue, 19 Aug 2014 16:30:41 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>Printing TTree Branches</title>
		<link>http://joshcogan.com/wp/2013/03/printing-ttree-branches/</link>
		<comments>http://joshcogan.com/wp/2013/03/printing-ttree-branches/#comments</comments>
		<pubDate>Fri, 15 Mar 2013 06:22:15 +0000</pubDate>
		<dc:creator><![CDATA[Josh]]></dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ROOT]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://joshcogan.com/wp/?p=51</guid>
		<description><![CDATA[I use ROOT, you use ROOT, all of high energy physics uses ROOT.  How many times have you found yourself scrolling through that graphical TBrowser trying to find that one particular TBranch in the TTree?  Like someone sends you the<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://joshcogan.com/wp/2013/03/printing-ttree-branches/">Read more &#8250;</a></div><!-- end of .read-more -->]]></description>
				<content:encoded><![CDATA[<p>I use ROOT, you use ROOT, all of high energy physics uses ROOT.  How many times have you found yourself scrolling through that graphical TBrowser trying to find that one particular TBranch in the TTree?  Like someone sends you the Release17 version of the blah-di-blah centrally produced NTuple and you just want to know if it has &#8220;photon_crazyRecoMethod_px&#8221; in it.  This crap happens to me all the time.  So I decided to write a little Unix-inspired bash script to solve all my life&#8217;s woes; or well..just this one.</p>
<p>The trick here is to get ROOT to echo all the TBranch names to stdout (through TTree::Print()) so that we can use all our normal grep tricks to find that one name we are looking for.  Here is the script in its totality:</p>
<pre>
#!/bin/bash
#./thisScript treeName fileName
{ echo "TFile f(\"$2\", \"READ\")" ; echo "$1-&gt;Print()" ; echo ".q" ; } |\
 root -l -b |\
 grep -v "^[*]Tree" |\
 sed -n -r "s/^[^:]*:([^ ]+)\s+:.*/\1/p"
#EOF</pre>
<p>Bash curly braces always freak me out, because they can do several different jobs. In this particular case, we are moving the output of several commands to stdin of another process.  Remember in the above script, the $1 and $2 get expanded to the first and second arguments passed to the shell script.  Here is, effectively, how the curly braces and ROOT call are interacting&#8230;</p>
<pre>$&gt; root -l -b
##ROOT ASCII ART###
&gt;&gt;&gt;TFile f("$2", "READ")
&gt;&gt;&gt;$1-&gt;Print()
&gt;&gt;&gt;.q
$&gt;</pre>
<p>Which causes ROOT to vomit lots of text like this&#8230;</p>
<pre>
...
*Entries : 172375 : Total Size= 23966439 bytes File Size = 13664685 *
*Baskets : 917 : Basket Size= 32000 bytes Compression= 1.75 *
*............................................................................*
*Br 180 :mooreseg_phi : vector&lt;double&gt; *
*Entries : 172375 : Total Size= 23968281 bytes File Size = 8502181 *
*Baskets : 917 : Basket Size= 32000 bytes Compression= 2.82 *
*............................................................................*
*Br 181 :mooreseg_theta : vector&lt;double&gt; *
*Entries : 172375 : Total Size= 23970123 bytes File Size = 14002768 *
*Baskets : 917 : Basket Size= 32000 bytes Compression= 1.71 *
*............................................................................*
...</pre>
<p>Since all that goes to stdout we can just grep/sed our way through it until we get a pretty list of branch names.  Now we just have a plain text stream.</p>
<pre>
$>./treeprint.sh CollectionTree data12_jte.root
...
mooreseg_z
mooreseg_phi
mooreseg_theta
...
$>
</pre>
<p>Pretty simple huh? How about that for <a href="http://en.wikipedia.org/wiki/Worse_is_better" title=""worse is better"" target="_blank">&#8220;worse is better&#8221;</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://joshcogan.com/wp/2013/03/printing-ttree-branches/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
