Esempio n. 1
0
        public void TestWithOneConstIndexedArray()
        {
            var aa = new ArrayAnalyzer();

            string filename = "TestWithOneConstIndexedArray.root";
            var    f        = new ROOTNET.NTFile(filename, "RECREATE");
            var    tree     = CreateTrees.CreateTreeWithConstIndexedSimpleVector(20);

            f.Write();

            ROOTClassShell sh = new ROOTClassShell();

            sh.Add(new Classitem()
            {
                ItemType = "int[]", Name = "arr"
            });
            var result = aa.DetermineAllArrayLengths(sh, tree, 10);

            Assert.AreEqual(10, result.Length, "# of events");
            Assert.IsTrue(result.All(x => x.Length == 1), "# of arrays");
            Assert.IsTrue(result.All(x => x[0].Item2 == 20), "Length of array");
            Assert.IsTrue(result.All(x => x[0].Item1 == "arr"), "variable name");

            f.Close();
        }
Esempio n. 2
0
        /// <summary>
        /// Look for all trees at the base directory of a TFile. We aren't
        /// scanning recursively!!
        /// </summary>
        /// <param name="inputFile"></param>
        /// <returns></returns>
        public IEnumerable <ROOTClassShell> ParseFile(FileInfo inputFile)
        {
            if (!inputFile.Exists)
            {
                throw new ArgumentException("input file does not exist");
            }

            var f = new ROOTNET.NTFile(inputFile.FullName, "READ");

            if (!f.IsOpen())
            {
                throw new ArgumentException("Failed to open file in ROOT");
            }

            ///
            /// See if we can find a file with further stuff we should be adding
            ///

            var fFurtherInfo = new FileInfo(Path.ChangeExtension(inputFile.FullName, ".root-extra-info"));
            Dictionary <string, string[]> extraInfo = fFurtherInfo.ParseAsINIFile(true);

            Console.WriteLine("Parsing the file '{0}'", inputFile.Name);

            //
            // Sometimes the same class is used in two different Tree's in the same file.
            // They have to be identical when that happens.
            //

            var classesByName = from sc in ParseTDirectory(f).ToArray()
                                group sc by sc.Name;
            var classesByNameCleaned = from scg in classesByName
                                       where scg.ClassesAreIdnetical()
                                       select scg.First();

            //
            // Go throught the classes and attach any extra info required.
            //

            foreach (var cls in classesByNameCleaned)
            {
                if (extraInfo.ContainsKey("CINT"))
                {
                    cls.CINTExtraInfo = extraInfo["CINT"];
                }
                if (extraInfo.ContainsKey("CreateDictionary"))
                {
                    ///
                    /// Do some basic syntax checking
                    ///

                    var allDictTypes = from l in extraInfo["CreateDictionary"]
                                       let spec = GetDictSpec(l)
                                                  where spec != null
                                                  select spec;
                    cls.ClassesToGenerate = allDictTypes.ToArray();
                }
                yield return(cls);
            }
        }
 /// <summary>
 /// Make it easy to load a file.
 /// </summary>
 /// <param name="fname"></param>
 /// <param name="treename"></param>
 /// <returns></returns>
 Tuple<ROOTNET.NTTree, ROOTNET.NTFile> GetTree(string fname, string treename)
 {
     var f = new ROOTNET.NTFile(fname, "READ");
     Assert.IsTrue(f.IsOpen(), "Test file not found");
     var t = f.Get(treename) as ROOTNET.NTTree;
     Assert.IsNotNull(t, "Tree not found");
     return Tuple.Create(t, f);
 }
        /// <summary>
        /// Make it easy to load a file.
        /// </summary>
        /// <param name="fname"></param>
        /// <param name="treename"></param>
        /// <returns></returns>
        Tuple <ROOTNET.NTTree, ROOTNET.NTFile> GetTree(string fname, string treename)
        {
            var f = new ROOTNET.NTFile(fname, "READ");

            Assert.IsTrue(f.IsOpen(), "Test file not found");
            var t = f.Get(treename) as ROOTNET.NTTree;

            Assert.IsNotNull(t, "Tree not found");
            return(Tuple.Create(t, f));
        }
Esempio n. 5
0
        /// <summary>
        /// Look for all trees at the base directory of a TFile. We aren't
        /// scanning recursively!!
        /// </summary>
        /// <param name="inputFile"></param>
        /// <returns></returns>
        public IEnumerable<ROOTClassShell> ParseFile(FileInfo inputFile)
        {
            if (!inputFile.Exists)
                throw new ArgumentException("input file does not exist");

            var f = new ROOTNET.NTFile(inputFile.FullName, "READ");
            if (!f.IsOpen())
            {
                throw new ArgumentException("Failed to open file in ROOT");
            }

            ///
            /// See if we can find a file with further stuff we should be adding
            /// 

            var fFurtherInfo = new FileInfo(Path.ChangeExtension(inputFile.FullName, ".root-extra-info"));
            Dictionary<string, string[]> extraInfo = fFurtherInfo.ParseAsINIFile(true);

            Console.WriteLine("Parsing the file '{0}'", inputFile.Name);

            //
            // Sometimes the same class is used in two different Tree's in the same file.
            // They have to be identical when that happens.
            //

            var classesByName = from sc in ParseTDirectory(f).ToArray()
                                   group sc by sc.Name;
            var classesByNameCleaned = from scg in classesByName
                             where scg.ClassesAreIdnetical()
                             select scg.First();
            //
            // Go throught the classes and attach any extra info required.
            //

            foreach (var cls in classesByNameCleaned)
            {
                if (extraInfo.ContainsKey("CINT"))
                {
                    cls.CINTExtraInfo = extraInfo["CINT"];
                }
                if (extraInfo.ContainsKey("CreateDictionary"))
                {
                    ///
                    /// Do some basic syntax checking
                    /// 

                    var allDictTypes = from l in extraInfo["CreateDictionary"]
                                       let spec = GetDictSpec(l)
                                       where spec != null
                                       select spec;
                    cls.ClassesToGenerate = allDictTypes.ToArray();
                }
                yield return cls;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Make some basic plots about tracks.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="allTracks"></param>
        /// <param name="p"></param>
        /// <param name="p_2"></param>
        private static void PlotTracks(ROOTNET.NTFile output, IQueryable <ROOTTTreeDataModel.CollectionTreetracks> tracks, string nameAdd, string titleAdd)
        {
            ///
            /// Dump out pt and eta and phi. Note that we are using the form of the Plot method that takes a lambda to select what we want to plot.
            ///

            output.Add(tracks.Plot(nameAdd + "TracksPt", titleAdd + " Track p_{T}", 100, 0.0, 100.0, t => t.pt / 1000.0));
            output.Add(tracks.Plot(nameAdd + "TracksPtZoom", titleAdd + " Track p_{T}", 100, 0.0, 20.0, t => t.pt / 1000.0));
            output.Add(tracks.Plot(nameAdd + "TracksEta", titleAdd + " Track \\eta", 100, -3.0, 3.0, t => t.eta));
            output.Add(tracks.Plot(nameAdd + "TracksPhi", titleAdd + " Track \\phi", 100, -Math.PI, Math.PI, t => t.phi));
        }
Esempio n. 7
0
        public void TestTreesWithPounds()
        {
            var f      = new ROOTNET.NTFile("atest.root", "READ");
            var t      = f.Get("##Shapes") as ROOTNET.Interface.NTTree;
            var p      = new ParseTTree();
            var result = p.GenerateClasses(t).ToArray();

            Assert.AreEqual(1, result.Length, "# of classes");
            var obj = result[0];

            Assert.IsFalse(obj.UserInfoPath.Contains("#"), "user path: " + obj.UserInfoPath);
        }
Esempio n. 8
0
        public void TestForNoObjects()
        {
            using (var f = new FileCreator("TestForNoObjects_empty.root"))
            {
            }
            var fin = new ROOTNET.NTFile("TestForNoObjects_empty.root", "READ");

            Assert.AreEqual(0, Utils.FindAllOfType <ROOTNET.Interface.NTObject>(fin).Count(), "was an empty file");
            fin.Close();

            using (var f = new FileCreator("TestForNoObjects_wrong.root"))
            {
                f.AddObject <ROOTNET.NTObject>(5);
            }
            fin = new ROOTNET.NTFile("TestForNoObjects_wrong.root", "READ");
            Assert.AreEqual(0, Utils.FindAllOfType <ROOTNET.Interface.NTH1F>(fin).Count(), "was a file with incorrect objects file");
            fin.Close();
        }
Esempio n. 9
0
        /// <summary>
        /// Create an output int file... unique so we don't have to regenerate...
        /// </summary>
        /// <param name="numberOfIter"></param>
        /// <returns></returns>
        public static Uri CreateFileOf(string filename, Func <ROOTNET.NTTree> maker)
        {
            FileInfo result = new FileInfo(filename);
            var      u      = new Uri("file://" + result.FullName);

            if (result.Exists)
            {
                return(u);
            }

            var f = new ROOTNET.NTFile(filename, "RECREATE");

            f.cd();
            var tree = maker();

            f.Write();
            f.Close();
            return(u);
        }
Esempio n. 10
0
        public void TestForSomeObjects()
        {
            using (var f = new FileCreator("TestForSomeObjects_only.root"))
            {
                f.AddObject <ROOTNET.NTObject>(5);
            }
            var fin = new ROOTNET.NTFile("TestForSomeObjects_only.root", "READ");

            Assert.AreEqual(5, Utils.FindAllOfType <ROOTNET.Interface.NTObject>(fin).Count(), "was just the right types in it");
            fin.Close();

            using (var f = new FileCreator("TestForSomeObjects_combo.root"))
            {
                f.AddObject <ROOTNET.NTObject>(5);
                f.AddObject <ROOTNET.NTH1F>(5);
            }
            fin = new ROOTNET.NTFile("TestForSomeObjects_combo.root", "READ");
            Assert.AreEqual(10, Utils.FindAllOfType <ROOTNET.Interface.NTObject>(fin).Count(), "was just the right types in it");
            Assert.AreEqual(5, Utils.FindAllOfType <ROOTNET.Interface.NTH1F>(fin).Count(), "was just the mostly the types in it");
            fin.Close();
        }
Esempio n. 11
0
        public void QueueTMVAObject()
        {
            var t = new TypeHandlerROOT();

            var f = new ROOTNET.NTFile("hi.root", "RECREATE");

            try
            {
                var origRootObj = new ROOTNET.NTMVA.NFactory(new ROOTNET.NTString("hi"), f);
                var rootObj     = Expression.Constant(origRootObj);

                var gc     = new GeneratedCode();
                var result = t.ProcessConstantReference(rootObj, gc, MEFUtilities.MEFContainer);

                Assert.IsNotNull(result);

                Assert.AreEqual(1, gc.VariablesToTransfer.Count(), "Variables to transfer");
            } finally
            {
                f.Close();
            }
        }
Esempio n. 12
0
        public void GenerateClassesWithCustomClassesAndSubClasses()
        {
            var f = new ROOTNET.NTFile("ComplexNtupleTestInput.root", "READ");

            try {
                Assert.IsTrue(f.IsOpen(), "Test file not found");
                var t = f.Get("btag") as ROOTNET.Interface.NTTree;
                Assert.IsNotNull(t.Name); // Make sure we got the tree correctly
                var p      = new ParseTTree();
                var result = p.GenerateClasses(t).ToArray();

                // Make sure the global features are right
                Assert.AreEqual(1, result.Where(c => c.IsTopLevelClass).Count(), "# of top level classes");
                Assert.AreEqual(3, result.Length, "# of classes");
                var classMap = result.ToDictionary(r => r.Name, r => r);
                Assert.IsTrue(classMap.ContainsKey("btag"), "btag class present");
                Assert.IsTrue(classMap.ContainsKey("MuonInBJet"), "MuonInBJet class present");
                Assert.IsTrue(classMap.ContainsKey("BTagJet"), "btag class present");
            } finally
            {
                f.Close();
            }
        }
Esempio n. 13
0
        public void GenerateClassesWithCustomClassesAndSubClasses()
        {
            var f = new ROOTNET.NTFile("ComplexNtupleTestInput.root", "READ");
            try {
                Assert.IsTrue(f.IsOpen(), "Test file not found");
                var t = f.Get("btag") as ROOTNET.Interface.NTTree;
                Assert.IsNotNull(t.Name); // Make sure we got the tree correctly
                var p = new ParseTTree();
                var result = p.GenerateClasses(t).ToArray();

                // Make sure the global features are right
                Assert.AreEqual(1, result.Where(c => c.IsTopLevelClass).Count(), "# of top level classes");
                Assert.AreEqual(3, result.Length, "# of classes");
                var classMap = result.ToDictionary(r => r.Name, r => r);
                Assert.IsTrue(classMap.ContainsKey("btag"), "btag class present");
                Assert.IsTrue(classMap.ContainsKey("MuonInBJet"), "MuonInBJet class present");
                Assert.IsTrue(classMap.ContainsKey("BTagJet"), "btag class present");
            } finally
            {
                f.Close();
            }
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            List <string> tempFileList = new List <string>();

            //var h = new ROOTNET.NTH1F();


            //File list from Blizz Americas Championship
            //tempFileList.Add("test.png");
            //tempFileList.Add("test480.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h19m07s974.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h19m25s545.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h19m35s253.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h19m55s213.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h19m59s995.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h20m11s857.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h20m19s473.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h20m35s166.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h20m38s961.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h20m56s916.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h21m03s792.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h21m30s637.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h21m36s183.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m00s213.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m09s622.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m22s416.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m33s378.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m45s875.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m50s183.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m06s850.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m11s075.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m20s624.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m25s391.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m35s019.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m39s636.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m49s060.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h24m34s479.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h24m44s448.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h24m56s372.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h25m05s414.png");

            fileImageProducer blizzAmericas = new fileImageProducer(tempFileList);

            var newFile = new ROOTNET.NTFile("output.root", "RECREATE");
            //String win1 = "Edge output test"; //Window name
            //CvInvoke.NamedWindow(win1); //Create the window with the name persona 3 style
            Mat outImage = new Mat();

            RegionOfInterest leftBlizz  = new RegionOfInterest(510f / 1280f, 0f / 720f, 100f / 1280f, 20f / 700f);
            RegionOfInterest rightBlizz = new RegionOfInterest(665f / 1280f, 0f / 720f, 100f / 1280f, 20f / 700f);

            var bestRowHisto = new ROOTNET.NTH1I("bestRows", "Top rows by discrimination", 20, 0, 20);
            //newFile.Add(bestRowHisto);

            //Text for comparison. "TEMPO STORM"
            TextSize    textSizeTest    = new TextSize(leftBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage));
            PeakPattern peakPatternTest = new PeakPattern(leftBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage), 200.0);

            //PeakPattern peakPatternTest2 = new PeakPattern(rightBlizz.getROIImage(blizzAmericas.Last().loadedImage));

            for (int iImage = 0; iImage < blizzAmericas.Count(); iImage++)
            {
                Image testc       = blizzAmericas.ElementAt(iImage);
                Mat   leftRegion  = leftBlizz.getROIImage(testc.loadedImage);
                Mat   rightRegion = rightBlizz.getROIImage(testc.loadedImage);

                List <Tuple <int, int> > rowResult = topThree(entropyList <Bgr, byte>(leftRegion, rightRegion, new byte[] { 180, 180, 180 }));

                ROOTNET.NTH1F tempLeft  = drawHisto <Bgr, double>(leftRegion, rowResult[0].Item1, 0, "left " + iImage);
                ROOTNET.NTH1F tempRight = drawHisto <Bgr, double>(rightRegion, rowResult[0].Item1, 0, "right " + iImage);

                //newFile.Add(tempLeft);
                //newFile.Add(tempRight);

                bestRowHisto.Fill(rowResult[0].Item1);
                bestRowHisto.Fill(rowResult[1].Item1);
                bestRowHisto.Fill(rowResult[3].Item1);

                //Console.WriteLine("Row {0} with {1}, row {2} with {3}, row {4} with {5}.",
                //    rowResult[0].Item1, rowResult[0].Item2,
                //    rowResult[1].Item1, rowResult[1].Item2,
                //    rowResult[2].Item1, rowResult[2].Item2);
                Console.WriteLine("File {0}", tempFileList[iImage]);
                //Console.WriteLine("TextSize Probability left {0}, TextSize probability right {1}.",
                //    textSizeTest.ProbabilityMatch(leftRegion),
                //    textSizeTest.ProbabilityMatch(rightRegion));
                Console.WriteLine("PeakPattern cosine left {0}, PeakPattern cosine right {1}.",
                                  peakPatternTest.ProbabilityMatch(leftRegion),
                                  peakPatternTest.ProbabilityMatch(rightRegion));
            }


            //CvInvoke.Imshow(win1, testMat);
            //TesseractEngine testOCR = new TesseractEngine("langDat", "eng", Tesseract.EngineMode.Default);
            //testOCR.DefaultPageSegMode(Tesseract.PageSegMode.SingleChar);
            //testOCR.

            //ImageViewer.Show(outImage, "test");

            //Some numbers from a 720p image in paint for ROI testing.

            //ImageViewer.Show(leftBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage), "leftName");
            //ImageViewer.Show(rightBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage), "rightName");

            Mat testProcessing      = leftBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage);
            Mat testProcessingRight = rightBlizz.getROIImage(blizzAmericas.ElementAt(1).loadedImage);

            System.Drawing.Rectangle textRegion  = ProcessingTools.findTextEdge <Bgr, double>(testProcessing, new double[] { 180.0, 180.0, 180.0 });
            System.Drawing.Rectangle textRegion2 = ProcessingTools.findTextEdge <Bgr, double>(testProcessingRight, new double[] { 180.0, 180.0, 180.0 });

            //CvInvoke.Rectangle(testProcessing, textRegion, new Bgr(0, 0, 255).MCvScalar);
            //ImageViewer.Show(leftBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage), "leftName");

            //CvInvoke.Rectangle(testProcessingRight, textRegion2, new Bgr(0, 0, 255).MCvScalar);
            //ImageViewer.Show(testProcessingRight, "rightName");



            //ImageViewer.Show(testProcessing);
            //Mat[] leftBlizzChannels = leftBlizz.getROIImage(outImage).Split();
            //Mat[] rightBlizzChannels = rightBlizz.getROIImage(outImage).Split();

            //foreach( Mat iMat in leftBlizzChannels)
            //{
            //    ImageViewer.Show(iMat);
            //}

            Console.ReadKey(); //Wait for return to finish!
            newFile.Write();
            //newFile.Close();
        }
Esempio n. 15
0
        public void TestTreesWithPounds()
        {
            var f = new ROOTNET.NTFile("atest.root", "READ");
            var t = f.Get("##Shapes") as ROOTNET.Interface.NTTree;
            var p = new ParseTTree();
            var result = p.GenerateClasses(t).ToArray();

            Assert.AreEqual(1, result.Length, "# of classes");
            var obj = result[0];
            Assert.IsFalse(obj.NtupleProxyPath.Contains("#"), "proxy path: " + obj.NtupleProxyPath);
            Assert.IsFalse(obj.UserInfoPath.Contains("#"), "user path: " + obj.UserInfoPath);
        }
Esempio n. 16
0
        /// <summary>
        /// Simple demo to look at jets in a local root-tuple. This demo is based on the feature
        /// set that can be found in version 0.1. Basic cuts, Count, and histogram making.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            FileInfo rootFile = new FileInfo(@"..\..\..\output.root");

            if (!rootFile.Exists)
            {
                Console.WriteLine("Unable to find the input file '" + rootFile.FullName + "'");
                return;
            }

            var rf1 = Queryablebtag.Create(rootFile);
            //rf1.IgnoreQueryCache = true;
            //rf1.CleanupQuery = false;

            ///
            /// Count the # of events in the file
            ///

            int count = rf1.Count();

            Console.WriteLine("The number of events in the ntuple, counted the hard way is {0}.", count);


            ///
            /// Next, count the number of jets in the file
            ///

            var alljets = from e in rf1
                          from j in e.jets
                          select j;

            Console.WriteLine("The number of jets in the ntuple is {0}.", alljets.Count());

            var jetsPerEvent = from e in rf1
                               select e.jets;
            var firstJetPerEvent = from jts in jetsPerEvent
                                   from j in jts.Take(1)
                                   select j;
            var secondJetPerEvent = from jts in jetsPerEvent
                                    from j in jts.Skip(1).Take(1)
                                    select j;

            var firstGoodJetPerEvent = from jts in jetsPerEvent
                                       from j in jts.Where(j => j.Pt() / 1000.0 > 30.0).Take(1)
                                       select j;

            ///
            /// Apply some very simple cuts
            ///

            var ptCutJets = from j in alljets
                            where j.Pt() / 1000.0 > 30.0
                            select j;

            Console.WriteLine("The number of jets with a pT greater than 30 GeV is {0}", ptCutJets.Count());

            var etaCutJets = from j in alljets
                             where Math.Abs(j.Eta()) < 1.0
                             select j;

            Console.WriteLine("The number of jets with an eta less than 1.0 is {0}", etaCutJets.Count());

            ///
            /// Make some histos of all of these.
            ///

            var outputFile = new ROOTNET.NTFile("result.root", "RECREATE");

            MakeGenericHistos(alljets, "alljets", outputFile);
            MakeGenericHistos(ptCutJets, "ptjets", outputFile);
            MakeGenericHistos(etaCutJets, "etajets", outputFile);

            MakeGenericHistos(firstJetPerEvent, "firstjet", outputFile);
            MakeGenericHistos(firstGoodJetPerEvent, "first30GeVjet", outputFile);
            MakeGenericHistos(secondJetPerEvent, "secondjet", outputFile);

            var jetCountGood = jetsPerEvent.ApplyToObject(new ROOTNET.NTH1F("nGoodJets", "N_{J}", 10, 0.0, 10.0), (h, x) => h.Fill((from j in x where (j.Pt() / 1000.0 > 30.0) select j).Count()));

            jetCountGood.SetDirectory(outputFile);

            var jetCount = jetsPerEvent.ApplyToObject(new ROOTNET.NTH1F("nJets", "N_{J}", 10, 0.0, 10.0), (h, x) => h.Fill(x.Count()));

            jetCount.SetDirectory(outputFile);

            outputFile.Write();
            outputFile.Close();
        }
Esempio n. 17
0
        public void TestWithOneConstIndexedArray()
        {
            var aa = new ArrayAnalyzer();

            string filename = "TestWithOneConstIndexedArray.root";
            var f = new ROOTNET.NTFile(filename, "RECREATE");
            var tree = CreateTrees.CreateTreeWithConstIndexedSimpleVector(20);
            f.Write();

            ROOTClassShell sh = new ROOTClassShell();
            sh.Add(new classitem() { ItemType = "int[]", Name = "arr" });
            var result = aa.DetermineAllArrayLengths(sh, tree, 10);

            Assert.AreEqual(10, result.Length, "# of events");
            Assert.IsTrue(result.All(x => x.Length == 1), "# of arrays");
            Assert.IsTrue(result.All(x => x[0].Item2 == 20), "Length of array");
            Assert.IsTrue(result.All(x => x[0].Item1 == "arr"), "variable name");

            f.Close();
        }
Esempio n. 18
0
        /// <summary>
        /// This demo shows how to work with an ntuple that contains a large number of arrays that
        /// are actually linked together (that is. pt, eta, phi, one entry for each jet). You will need
        /// to look at the Genq
        /// erateArrayNtupleXMLSpec for the generation of the items.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var f = new FileInfo(@"..\..\..\hvsample.root");

            if (!f.Exists)
            {
                Console.WriteLine("could not find btag input files: " + f.FullName);
                return;
            }

            var evts = ROOTTTreeDataModel.QueryableCollectionTree.Create(f);

            ///
            /// Make a plot of pt of a track (a renamed and grouped variable). This is with the full
            /// select statement done out.
            ///

            var trackPt = from e in evts
                          from t in e.tracks
                          select t.pt / 1000.0;

            var output = new ROOTNET.NTFile("output.root", "RECREATE");

            output.Add(trackPt.Plot("trackpt", "Track p_{T}", 100, 0.0, 200.0));

            ///
            /// Create a stream of tracks so we can do more "interesting" things on it.
            ///

            var allTracks = from e in evts
                            from t in e.tracks
                            select t;

            PlotTracks(output, allTracks, "all", "All");

            var centralTracks = from t in allTracks
                                where Math.Abs(t.eta) < 1.0
                                select t;

            PlotTracks(output, centralTracks, "central", "Central");

            ///////////////////////////////////////////////////////////
            ///
            /// Next, do a few btagging ntuple things. This
            /// ntuple is more complex so we can show of more features.
            ///

            var fbtag      = new FileInfo(@"..\..\..\btag-slim.root");
            var btagEvents = ROOTTTreeDataModel.Queryablevtuple.Create(fbtag);

            var btagTracks = from e in btagEvents
                             from t in e.tracks
                             select t.pt / 1000.0;

            output.Add(btagTracks.Plot("btag_alltracks_pt", "All tracks for btagging p_{T}", 100, 0.0, 100.0));

            ///
            /// Muons are crazy because they are referenced by other jets. This is the one line way of saving
            /// a plot to a file.
            ///

            (from e in btagEvents select e.muons.Count()).Plot("btag_allmuon_count", "Number of muons in each btag event", 20, 0.0, 20.0).SaveToROOTDirectory(output);

            ///
            /// Look at jets (note the pT is renamed here)
            ///

            var btagJets = from e in btagEvents
                           from j in e.jets06
                           select j;

            (from j in btagJets select j.pt / 1000.0).Plot("btag_all_jet_pt", "all 0.6 jets, p_{T}", 100, 0.0, 100.0).SaveToROOTDirectory(output);

            ///
            /// Muons are associated with jets - so lets look at this. First, this
            ///

            (from j in btagJets from m in j.muon_ptrel select m / 1000.0).Plot("btag_allmuon_nearjet_ptrel", "Number of muons associated with every jets", 100, -10.0, 20.0).SaveToROOTDirectory(output);

            ///
            /// And tracks. This is a index linkage - so we can see the track object from the muons.
            ///

            (from j in btagJets select j).Plot("btag_alljet_ntracks", "# of tracks near jet", 20, 0.0, 20.0, v => v.ntracks).SaveToROOTDirectory(output);

            var tracksNearJets = from j in btagJets
                                 from t in j.associatedTracks
                                 select t;

            tracksNearJets.Plot("btag_alljet_neartrack_pt", "p_{T} of tracks near jets", 100, 0.0, 100.0, v => v.pt / 1000.0).SaveToROOTDirectory(output);

            ///
            /// All muon pt's
            ///

            var btagMuons = from e in btagEvents
                            from m in e.muons
                            select m;

            (from m in btagMuons select m.mupt / 1000.0).Plot("btag_allmuon_pt", "p_{T} of any muon in the event", 100, -10.0, 100.0).SaveToROOTDirectory(output);

            ///
            /// And a 2D plot
            ///

            btagMuons.Plot("btag_allmuon_pteta", "p_{T} vs \\eta for all muons in event", 100, 0.0, 100.0, 20, -4.0, 4.0, v => v.mupt / 1000.0, v => v.mueta).SaveToROOTDirectory(output);

            output.Write();
            output.Clone();
        }
Esempio n. 19
0
 public FileCreator(string name)
 {
     _file = new ROOTNET.NTFile(name, "RECREATE");
 }