After using the Homebrew package manager to install a few gtk-related packages on my Macbook (macOS Sierra, 10.12.4), I experienced an alarming problem: I could no longer launch ROOT. When I tried, I got a message like this:

err: dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /usr/local/lib/libjpeg.8.dylib

Yikes! Luckily, I’m not the first one to have this problem. It turns out that installing the gtk-related packages also installs various image-related packages (jpeg, libtiff, libpng). The interplay between Homebrew and MacOS sometimes results in a conflict, where Homebrew places a dynamic library in /usr/local/lib, and then that takes precedence over the system’s dynamic library in /System/Library/.  (You’d think that this wouldn’t happen, given that Homebrew is designed for MacOS, but still…) There are a few different possibilities for trying to force the correct library (in /System/Library/) to load, but perhaps the most straightforward is to blow up the new library in /usr/local/lib and replace it with a symbolic link to the system library. Here’s a nice blog post with a clear explanation, starting about halfway down the page with the paragraph beginning “But we’re not quite done yet.”

To sum up, there’s a two-command sequence which you’ll want to repeat for all three libraries (first after confirming that the correct libraries really do exist in the /System directory):

$cd /usr/local/lib$ rm libjpeg.dylib
$ln -s /System/Library/Frameworks/ImageIO.framework/Resources/libJPEG.dylib libJPEG.dylib$ rm libtiff.dylib
$ln -s /System/Library/Frameworks/ImageIO.framework/Resources/libTIFF.dylib libTIFF.dylib$ rm libpng.dylib
ln -s /System/Library/Frameworks/ImageIO.framework/Resources/libPng.dylib libPng.dylib You may also have a libgif issue, which you can clean up the same way; for whatever reason, I did not. ## Extracting a pointer to an unnamed object in a ROOT file One of ROOT’s less endearing quirks is its tendency to write objects to files in such a way that they can’t easily be accessed later. Okay, yes, you can often use a TBrowser in interactive mode, but that isn’t much help if you are hoping to access the object in a macro or in compiled code. Wouldn’t it be much simpler for everyone if, by default, ROOT included a name with every TGraph it wrote to file? Ah, but then I’d update this blog even less frequently… A while ago I explained how to retrieve an object from a file if its pointer is stored in a TPad object (also written to file). But what do you do if there is no handy TPad object in the file, just a TGraph(Errors) with no name? If the TGraph is written in a file, then there’s a way to retrieve it through the file keys, even if it doesn’t have a name. I found most of what I needed in this ROOT guide, although true to form, the sample code throws an error when executed. Here’s the recipe that works for me. Start from the pointer to the file in question (let’s say TFile *myfile, and extract the list of keys as a TIter object (which will allow us to iterate through it). Assuming our TGraph is the only key in the list, we can get it this way: > TIter keylist(myfile->GetListOfKeys()); > TKey *key = (TKey*)keylist.Next(); > if (!strncmp(key->GetClassName(), "TGraphErrors", 15){ > TGraphErrors *mygraph = dynamic_cast<TGraphErrors*>(key->ReadObj()); > } The first line gets the list of keys from the file; the second line retrieves the first key from the list. (If you need to start again for some reason, keylist.Reset() is the command that you want.) The conditional double-checks to make sure that the key corresponds to a TGraphErrors object, and if so, the fourth line retrieves a pointer to the object that we want, using the TKey::ReadObj() function. If there’s more than one key in the list, you can use a while loop to work your way through: while ((key=(TKey*)keylist.Next())){ ... } With a pointer to the TGraph, you can now do whatever you like with it. I might suggest starting by writing it to file with a name! ## Filling a TGraph with data from a TTree It’s incredibly easy to fill a histogram with data from a TTree, using the TTree::Draw() or TTree::Project() functions. However, sometimes a histogram won’t cut it. For example, the inherent binning of a histogram can obscure fine structure, and error handling is often easier in a graph. There’s no direct TTree member function that will fill a graph with data, however; that would be too easy. You will have to obtain vectors of the desired values, and then create a TGraph using those vectors. But, you don’t have to iterate through the tree leaf by leaf, populating your vectors one entry at a time. It turns out that the TTree::Draw() function automatically creates those vectors, containing all the data that it’s also piping into the histogram. (Yes, selections included.) Here’s an example: mytree->Draw("yvar:xvar", "veto != 1", "goff"); TGraph *mygraph = new TGraph(mytree->GetSelectedRows(), mytree->GetV2(), mytree->GetV1()); In the TTree::Draw() command, we’re creating a histogram of the yvar branch plotted against the xvar branch — or at least, all the entries for which the veto variable is not equal to 1. The “goff” option turns off graphical output, so that ROOT skips the time-consuming step of plotting the histogram on a canvas. Behind the scenes, the TTree::Draw() command has also achieved something else, though: it’s filled two vectors (V1 and V2) with the y and x components of the plotted variables (but only those for which veto!=1). It’s also filled in an important number: TTree:GetSelectedRows() returns an integer corresponding to the number of entries that satisfied the selection condition, and therefore the number of entries in the vectors. We can use that piece of information, and the two vectors, to create the TGraph that we always wanted. Note one quirk of ordering: the vectors V1 and V2 take their ordering from y vs x (or the yvar:xvar notation of the TTree::Draw() command — not the alternative convention of (x,y) or the formatting of the TGraph constructor. That’s why the arguments for TGraph look sort of backwards: V2 before V1. ## CMake Error: Could not find CMAKE_ROOT !!! While trying to build the newest version of ROOT, I came across an unexpected problem. The first step is to use cmake in order to configure the build, but when I typed “cmake ..” from the build directory, I received the following error message: CMake Error: Could not find CMAKE_ROOT !!! CMake has most likely not been installed correctly. Modules directory not found ... I’ve recently started using MacPorts as a package manager, which has been a huge help. I tried redoing my cmake installation: sudo port install cmake Then I tried explicitly uninstalling and installing: sudo port uninstall cmake sudo port install cmake Still no luck. Much to my surprise, rebooting my machine — with no other changes, alterations, new environment variable settings, etc — fixed the problem. ## Creating a custom theme in PowerPoint 2011 for Mac I have trouble starting on a PowerPoint presentation before choosing a theme — themes help me structure my slides. I’ve spent some time in Master View laying out slides that I like — with fancy borders or nicer fonts or absolutely no objects with shadows by default. To use such formatting in a second presentation, you can either copy the first file to a second and change out all the content, or you can save the custom theme. Once you have a presentation with a theme you like, you can save the theme by going to the “Themes” tab of the ribbon, and then clicking on the “Save Theme” button. It will be saved in the .thmx file format, and you can choose a file name as descriptive (or not) as you like. Next, you want to be able to select this theme for a new presentation. This took me a little while to figure out, so I’ve got a screenshot below. On the “Themes” tab in the ribbon, there’s a section displaying the title slides of various different themes. If you mouse over it, you will now see a little downward-pointing triangle, indicating a drop-down menu. Click on the triangle and the menu will open up; your new theme (in this case, “BlueBorder”) will be available under the heading “Custom”. ## Automatic line wrapping within LaTeX tables LaTeX tables are simple, straightforward and beautiful when you have a small number of columns and the contents are mostly numbers. Things start to get complex when words come into the picture, though. A table cell with some verbal description of even moderate length can soon send the table marching right off the end of the page. In the past, I’ve spent an embarrassing amount of time fixing this problem by laboriously entering manual line breaks, with each new text line corresponding to a new table row. Today I hit my limit and went searching for a better way. Thanks to this blog entry, I discovered the tabularx package, which handles line wrapping behind the scenes after you give it just a few inputs. First, in the preamble, include the package: \usepackage{tabularx} Second, replace the familiar \tabular environment with \tabularx. \tabularx takes a new argument: write the allowed width of the table in curly braces after invoking \tabularx. Next, the familiar column arguments change slightly. Let’s say that you want three left-justified columns, which would normally be specified [lll]. Now let’s say that it’s the third column that’s likely to go over-long. Replace that l with an X: \begin{table}[htdp] \caption{Sample tabularx table.} \begin{center} \begin{tabularx}{15cm}{llX} \textbf{Column A} & \textbf{Column B} & \textbf{Column C} \\ \hline A Tale of Two Cities & Charles Dickens & “It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity…” \\ \end{tabularx} \end{center} \label{tab:sample} \end{table} There are many more details you may want to consider, such as the width of one column relative to another, or the justification of column text (full justification in this example). However, just these basics will make a lot of tasks run more smoothly. ## Permissions problems in launchctl The Mac OSX equivalent of a task scheduler (what would be a cron job on your typical Linux machine) is launchd. You write a property list to configure the job (let’s call ours com.launchd_doX.plist ) and place it in /Library/LaunchAgents. Then you need to get things started with the launchctl command: sudo launchctl load -w com.launchd_doX.plist Sometimes, though, you’ll get a confusing error message: /Library/LaunchAgents/com.launchd_doX.plist: Path had bad ownership/permissions In my case, it turned out that it wasn’t the path that has bad permissions; it was the plist file. Luckily, I found the nice solution on stackexchange, at http://superuser.com/questions/793872/can-t-launch-daemon-with-launchctl-in-yosemite . There are two essential permissions and ownership issues to keep track of: • Launch daemons must be owned by root. Launch agents must also be owned in root, if located in /Library/LaunchAgents • A security requirement: Group and world writes to the plist must be forbidden. I disabled group and world writes using the chmod command: sudo chmod g-w com.launchd_doX.plist sudo chmod o-w com.launchd_doX.plist and was then able to successfully get the plist running in the task manager. ## Shorter figure captions for display in the List of Figures In a large scientific document — a dissertation, for example — it’s convenient for the front matter to include not only a table of contents, but also a list of figures and a list of tables. These lists allow the reader to quickly look up the location of a figure or table that interests them; with the \hyperref package, the reader can even click to be taken to the right spot in the PDF. Here are the commands you would use, in the document environment, to include all of these three lookup tables in your document: \tableofcontents \listoffigures \listoftables The list of figures will display the caption text for each figure, but that leads to another problem: often, figure captions are packed with information that’s very useful for someone looking directly at the figure, but utterly useless for someone paging through the front matter. If every entry in the list of figures is a paragraph long, including explanations for each solid, dotted, dashed, and dash-dotted line; each marker style; and each coordinate system, then the list of figures will be useless for its intended purpose. Luckily, the \caption command provides an easy way to specify BOTH a short caption (for display in the list of figures) and a long caption (for display with the figure). The long caption is the argument in curly braces{}; the short caption is the optional argument in square braces[]. Here’s an example: \begin{figure}[tb] \centering \includegraphics[width=0.5\textwidth]{/figs/waveform.pdf} \caption[Typical photon pulse] {A typical photon pulse from the GSO detector, measured using the triggered mode of the new DAQ. This photon has nearly the maximum energy expected from a signal photon in this system.} \label{fig:waveform} \end{figure} Table captions work the same way. In fact, you can even use this same argument syntax for your \chapter and \section headings, to change how the headers are displayed in the table of contents. (I’m not sure why one would want to do this — but it’s possible!) ## Using Design Assistant to change Inventor file names For just about any hardware system of significant complexity, it doesn’t take long for the corresponding Inventor model to involve dozens or hundreds of files corresponding to parts, sub-assemblies, and even drawings. Over the course of this process, there is often cause to regret naming choices made in the first flush of modeling. Maybe “glass tube 3″ made a lot of sense six months ago, but now that part is going to be made of ceramic, and with a dozen different tubes in the model the original numbering scheme has been lost. Or maybe the part manufacturer sent you .stp files for a dozen assemblies, and in each assembly, the parts were all given helpful names like “PRODUCT 1″ or “PRODUCT 2″. (This really happens.) Changing file names must be done with care, however, if you’re not going to break associations in any assemblies that use the part. There are ways to do this in Vault; even if you don’t use Vault, though, you can do it with the Design Assistant tool. In Inventor 2010, you can access this tool through the Windows Program menu, under Autodesk -> Autodesk Inventor 2010 -> Design Assistant 2010. Once Design Assistant is open, use the File Menu to open the assembly you’re concerned with, then click on Manage in the gray sidebar at the left. You should see a menu much like the one in the screenshot below. You’ll see that for each file name there is a corresponding “Action” column. Click in that “Cell” — the Action entry for that part — and you will be presented with four choices: Rename, Copy, Replace, Clear. If you select the Copy option for a part, the color of the row will change, and the entry will display the message Requires Edit under the “Modified” column. You can then actually make the edit — changing the part name to “ceramic tube 1″, for example — by clicking in the “Name” column. When you’re done, hit the Save button in the upper left, and breathe a sigh of relief. You did it! ## LaTeX table formatting: centrist headers and right-leaning values It is well known that when you start to look closely at LaTeX output, you are in grave danger of going down a rabbit hole. Such is the case when you start worrying about the alignment of entries in a table. One usual way to format a table is just to center-justify all columns. This works well in general, but not when some of the table entries are positive, and some are negative. Here’s a simple example, with x and y values drawn more or less out of a hat. The basic code, \begin{table}[htdp] \begin{center} \caption{Some nifty results.} \label{tab:results_center} \begin{tabular}{cc}x$&$y$\\ \hline 0.0 &$3.045$\\ 1.0 &$0.015$\\ 2.0 &$-0.330$\\ 3.0 &$-2.444\\ \end{tabular} \end{center} \label{default} \end{table} gives an ugly output: See how the minus signs throw the y values out of alignment? To line them up properly — that is, with all the decimal points in a column — you would need to right-justify the y values. But applying that justification to the column would slide the header all the way to the right, which doesn’t look good either. Luckily, it’s possible to fix this using the \multicolumn command. Basically, this command allows you to create a new, local definition for the column format in your table. It’s designed for making table cells that span multiple columns, but because it has its own justification scheme we can exploit it to solve this alignment problem. Here’s the basic structure of \multicolumn: \multicolumn{number cols}{align}{text} % align: l,c,r In our table, we can turn the header cells into multicolumn cells. Each header spans one table column (so its width won’t change), but is center-justified within that one-column width. \begin{table}[htdp] \begin{center} \caption{Some nifty results.} \label{tab:results_multicolumn} \begin{tabular}{lr} \multicolumn{1}{c}{x$} & \multicolumn{1}{c}{$y$} \\ \hline 0.0 &$3.045$\\ 1.0 &$0.015$\\ 2.0 &$-0.330$\\ 3.0 &$-2.444\$\\
\end{tabular}
\end{center}
\label{default}
\end{table}
And this solves the problem: