This project is read-only.

All ROOT.NET packages and libraries are now published on the main NuGet open source package server (as of version 2.5).

This tutorial sets up a simple project that uses the wrappers to load and save a file and create a histogram.

  1. Download ROOT. Make sure to grab a vc2010 version (I usually grab the non-debug, msi installer).
  2. Start an instance of Visual Studio 2010. The nuget package manager should be installed (if not, install it under tools –> Extension Manager).
  3. In VS2010 create a new C# console project.
  4. Right click on project References and select Manage NuGet Packages.
  5. In the Manage NuGet Packages dialog that comes up, find the search box and enter the version of ROOT you just installed. For example, “v5.30.01”. This will give you a complete list of packages that apply to that version of ROOT. If your version of ROOT is not there, do not try to use something else. In all likelihood it will end in tears. Contact me instead!
  6. Select the “ROOT.NET Core” package, and click the Install button. When it is done, click the Close button.
  7. Enter the code as shown below.
  8. Click Run. The console output should claim to have 500 entries and a mean of about 10.0 or so. The directory where the executable is you should find a root file called junk.root which contains the histogram.

The Code

This code you can replace in Program.cs in the default creation. It should just compile.

        static void Main(string[] args)
                /// Create a file with a single histogram in it

                var newFile = new ROOTNET.NTFile("junk.root", "RECREATE");
                var h = new ROOTNET.NTH1F("first", "The First Histo", 20, 0.0, 20.0);
                var r = new ROOTNET.NTRandom();
                foreach (var i in Enumerable.Range(0, 500))
                    var val = r.Gaus(10.0, 2.0);

                Console.WriteLine("Number of entries in the histogram: {0}.", h.GetEntries());


                /// When the file above is closed, ROOT deletes the object. Uncomment this line to see what
                /// that kind of crash looks like with these wrappers - it will help you sort out the
                /// types of bombs!
                //Console.WriteLine("Number of entries in the histogram: {0}.", h.GetEntries());

                /// Open up the file now

                var oldFile = new ROOTNET.NTFile("junk.root", "READ");
                var h = oldFile.Get("first") as ROOTNET.NTH1F;
                Console.WriteLine("The number of entries on the opened file is {0}.", h.GetEntries());
                Console.WriteLine(" and the mean is {0}.", h.GetMean());

Last edited Jul 12, 2012 at 8:11 AM by gwatts, version 7


krishnateja Apr 27, 2013 at 7:22 AM 
How to save a h.ShowBackground(80, "") into another histo ?