static void Main(string[] args)
        {
            var dataset = "user.emmat.mc15_13TeV.361022.Pythia8EvtGen_A14NNPDF23LO_jetjet_JZ2W.merge.AOD.e3668_s2576_s2132_r6765_r6282__EXOT15_v3_EXT0";
            var jobFiles = GRIDJobs.FindJobFiles("DiVertAnalysis", 3, dataset);

            var events = QueryablerecoTree.CreateQueriable(jobFiles);
            events.CleanupQuery = false; // Set to keep C++ around
            events.IgnoreQueryCache = true; // Set to ignore query cache for speed

            using (var f = new FutureTFile("S2.root"))
            {
                var count = events.FutureCount();

                var jets = events
                    .SelectMany(e => e.Jet)
                    .Where(j => Math.Abs(j.eta) < 1.5);

                jets
                    .FuturePlot("pt", "Jet pT; pT [GeV]", 100, 0.0, 100.0, j => j.pT)
                    .Save(f);

                jets
                    .FuturePlot("eta", "Jet eta; eta", 100, -2.0, 2.0, j => j.eta)
                    .Save(f);

                Console.WriteLine($"Saw {count.Value} events.");
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            WriteLine("Finding the files");
            var backgroundEvents = Files.GetJZ(2).Select(e => e.Data);
            //var signalHV125pi15Events = Files.Get125pi15();
            //var signalHV125pi40Events = Files.Get125pi40();
            var signalHV600pi100Events = Files.Get600pi150lt9m();
            //var signalGet200pi25lt5mEvents = Files.Get200pi25lt5m();

            //
            // Do a simple cut training here
            //

            var t = TrainingIQueriable(signalHV600pi100Events, true)
                .AsSignal("HV600pi100")
                .Background(TrainingIQueriable(backgroundEvents, false), "J2Z")
                .IgnoreVariables(p => p.lowestPtTrack);

            var mCuts = t.AddMethod(ROOTNET.Interface.NTMVA.NTypes.EMVA.kCuts, "SimpleCuts")
                .Option("!H:V:FitMethod=MC:EffSel:SampleSize=200000:VarTransform=Decorrelate")
                .ParameterOption(p => p.logR, "VarProp", "FSmart")
                .ParameterOption(p => p.nTracks, "VarProp", "FSmart")
                .ParameterOption(p => p.lowestPtTrack, "VarProp", "FSmart");

            var mMVA = t.AddMethod(ROOTNET.Interface.NTMVA.NTypes.EMVA.kBDT, "SimpleBDT")
                .Option("MaxDepth=3");

            t.Train("VerySimpleTraining");

            // Lets make a measurement of the efficiency for the standard cut.
            var effResults = new FutureTFile(Path.Combine(FileInfoUtilities.FindDirectoryWithFileMatching("*.sln").FullName,"trainingResults.root"));
            var stdCutVale = CalcEff(effResults.mkdir("std"), td => (td.logR > 1.2 && td.nTracks == 0) ? 1.0 : 0.0, 0.5, TrainingIQueriable(backgroundEvents, false), TrainingIQueriable(signalHV600pi100Events, true));

            // Next, do it with a reader

#if false
            var r = new ROOTNET.NTMVA.NReader();
            var s = new FileInfo("C:\\Users\\gordo\\Documents\\Code\\calratio2015\\JetCutStudies\\SimpleJetCutTraining\\bin\\x86\\Debug\\weights\\VerySimpleTraining_SimpleCuts.weights.xml");
            float[] logR = new float[2];
            float[] nTracks = new float[2];
            r.AddVariable("logR".AsTS(), logR);
            r.AddVariable("nTracks".AsTS(), nTracks);
            r.BookMVA("SimpleCuts".AsTS(), s.FullName.AsTS());
            Expression<Func<TrainingData, double>> simpleCutsReader = tv => TMVAReaders.TMVASelectorSimpleCutsTest(r, tv.logR, tv.lowestPtTrack, stdCutVale.Value);
#else
            Expression<Func<TrainingData, double>> simpleCutsReader = tv => TMVAReaders.TMVASelectorSimpleCuts(tv.logR, tv.nTracks, 0.72);
#endif
            var simpleCutValue = CalcEff(effResults.mkdir("SimpleCuts"), simpleCutsReader, 0.5, TrainingIQueriable(backgroundEvents, false), TrainingIQueriable(signalHV600pi100Events, true));

            // Next, we need to get the MVA and figure out the efficiency.
            Expression<Func<TrainingData, double>> simpleMVAReader = tv => TMVAReaders.TMVASelectorSimpleBDT(tv.logR, tv.nTracks);
            var simpleBDTValue = CalcEff(effResults.mkdir("SimpleBDT"), simpleMVAReader, 0.99999, TrainingIQueriable(backgroundEvents, false), TrainingIQueriable(signalHV600pi100Events, true));

            // Write out everything
            effResults.Write();
            effResults.Close();

            //Emit();
        }
Ejemplo n.º 3
0
        public void FutureFileEmptyInUsing()
        {
            var f = new FileInfo("FutureFileWriteHisto.root");
            if (f.Exists)
            {
                f.Delete();
            }

            using (var ftf = new FutureTFile(f))
            {

            }

            f.Refresh();
            Assert.IsTrue(f.Exists);
        }
Ejemplo n.º 4
0
        public void FutureFileEmpty()
        {
            // Create an empty TFile, make sure that is good!
            var f = new FileInfo("FutureFileEmpty.root");
            if (f.Exists)
            {
                f.Delete();
            }

            var ftf = new FutureTFile(f);
            ftf.Write();
            ftf.Close();

            f.Refresh();
            Assert.IsTrue(f.Exists);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var opt = ParseOptions<Options>(args);

            var signalSources = SampleMetaData.AllSamplesWithTag("signal")
                .Select(info => Tuple.Create(info.NickName, Files.GetSampleAsMetaData(info)));

            using (var outputHistograms = new FutureTFile("LLPInvestigations.root"))
            {
                foreach (var s in signalSources)
                {
                    FutureWriteLine(s.Item1);
                    ProcessSample(s.Item2, outputHistograms.mkdir(s.Item1));
                }
            }

            FutureConsole.DumpToCout();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Make generic plots of the signal or background
        /// </summary>
        /// <param name="args"></param>
        /// <remarks>
        /// TODO: Would studies of efficiencies here be better served by splitting into forward and central eta regions?
        /// TODO: What is going on with the jetPT?
        /// TODO: What is eta distribution of the jets that make it through, in particular with NTrack = 0?
        ///       It could be those are far forward and thus have no tracks.
        /// TODO: Should any of these plots look at stuff in the way that Heather has (2D heat maps for cuts)?
        /// </remarks>
        static void Main(string[] args)
        {
            var opt = CommandLineUtils.ParseOptions<Options>(args);

            Console.WriteLine("Finding the files");

            // All the background samples have to be done first.
            var backgroundSamples = SampleMetaData.AllSamplesWithTag("background")
                .Select(info => Tuple.Create(Files.GetSampleAsMetaData(info), info.NickName))
                .ToArray();

            var backgroundEvents = Files.GetAllJetSamples().Select(e => e.Data);

            // All the signal we are going to make plots of.
            var signalSamples = SampleMetaData.AllSamplesWithTag("signal")
                .Select(info => Tuple.Create(Files.GetSampleAsMetaData(info), info.NickName))
                .ToArray();

            // Output file
            Console.WriteLine("Opening output file");
            using (var outputHistograms = new FutureTFile("GenericPerformancePlots.root"))
            {
                // First, lets do a small individual thing for each individual background sample.
                var bkgDir = outputHistograms.mkdir("background");
                Console.WriteLine("Making background plots.");
                foreach (var background in backgroundSamples)
                {
                    BuildSuperJetInfo(background.Item1.Select(md => md.Data))
                        .PlotBasicDataPlots(bkgDir.mkdir(background.Item2), "all");
                }

                // Do a quick study for each signal sample, using all the backgrounds at once to make
                // performance plots.
                Console.WriteLine("Making the signal/background plots.");
                foreach (var sample in signalSamples)
                {
                    var status = PerSampleStudies(backgroundEvents, sample.Item1.Select(md => md.Data), outputHistograms.mkdir(sample.Item2));
                    DumpResults($"Sample {sample.Item2}:", status);
                }

                // Write out the histograms
                outputHistograms.Write();
            }
        }
Ejemplo n.º 7
0
        public void FutureFileWriteWithClose()
        {
            var f = new FileInfo("FutureFileWriteWithClose.root");
            if (f.Exists)
            {
                f.Delete();
            }
            while (f.Exists)
            {
                f.Refresh();
            }

            using (var ftf = new FutureTFile(f))
            {
                ftf.Close();
            }

            f.Refresh();
            Assert.IsTrue(f.Exists);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Look at a number of MVA trainings and use them as results.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Parse the arguments.
            var opt = CommandLineUtils.ParseOptions<Options>(args);

            // Get all the samples we want to look at, and turn them into
            // jets with the proper weights attached for later use.

            var backgroundJets = CommandLineUtils.GetRequestedBackground();
            var allBackgrounds = new List<Tuple<string, IQueryable<Files.MetaData>>>()
            {
                Tuple.Create("QCD", backgroundJets),
            };

            var allSources = SampleMetaData.AllSamplesWithTag(opt.SignalTag)
                .Select(info => Tuple.Create(info.NickName, Files.GetSampleAsMetaData(info, false)))
                .ToArray();
            if (allSources.Length == 0)
            {
                throw new ArgumentException($"No samples were found with tag '{opt.SignalTag}'.");
            }

            // List the artifacts that we are going to be using.
            var mvaResults = new MVAInfo[]
            {
                new MVAInfo() { Name = "13VariableLxy", Artifact = new Uri("http://higgs.phys.washington.edu:8080/job/CalRatio2016/job/JetMVATraining/38/artifact/Jet.MVATraining-Jet.CalRat.NTrac.SumPtOfAllTrac.MaxTrack.JetWid.JetDRTo2GeVTra.EnergyDensi.HadronicLayer1Fracti.JetL.JetLo.FirstClusterRadi.ShowerCent_BDT.weights.xml") },
                new MVAInfo() { Name = "13VariableLxyNoDR", Artifact = new Uri("http://higgs.phys.washington.edu:8080/job/CalRatio2016/job/JetMVATraining/39/artifact/Jet.MVATraining-Jet.CalRat.NTrac.SumPtOfAllTrac.MaxTrack.JetWid.EnergyDensi.HadronicLayer1Fracti.JetL.JetLo.FirstClusterRadi.ShowerCent_BDT.weights.xml") },
                new MVAInfo() { Name = "13VariableLxyNoDRNTrack", Artifact = new Uri("http://higgs.phys.washington.edu:8080/job/CalRatio2016/job/JetMVATraining/40/artifact/Jet.MVATraining-Jet.CalRat.SumPtOfAllTrac.MaxTrack.JetWid.EnergyDensi.HadronicLayer1Fracti.JetL.JetLo.FirstClusterRadi.ShowerCent_BDT.weights.xml") },
                new MVAInfo() { Name = "13VariableLxyNoNTrack", Artifact = new Uri("http://higgs.phys.washington.edu:8080/job/CalRatio2016/job/JetMVATraining/41/artifact/Jet.MVATraining-Jet.CalRat.NTrac.SumPtOfAllTrac.MaxTrack.JetWid.EnergyDensi.HadronicLayer1Fracti.JetL.JetLo.FirstClusterRadi.ShowerCent_BDT.weights.xml") },
            };

            // Fill an output file with the info for each MVA
            using (var f = new FutureTFile("TrainingTestResults.root"))
            {
                foreach (var mva in mvaResults)
                {
                    // The directory
                    var d = f.mkdir(mva.Name);

                    // Get the weight file.
                    var weights = ArtifactAccess.GetArtifactFile(mva.Artifact).Result;

                    // Now, create the MVA value from the weight file
                    var mvaValue = MVAWeightFileUtils.MVAFromWeightFile<TrainingTree>(weights);

                    // Do the backgrounds (e.g. ones where we don't filter for signal).
                    foreach (var s in allBackgrounds)
                    {
                        var sampleD = d.mkdir(s.Item1);
                        PlotMVAResult(s.Item2.AsGoodJetStream().FilterNonTrainingEvents(), sampleD, mvaValue);
                    }

                    // And now we can make the plots for signal
                    foreach (var s in allSources)
                    {
                        Console.WriteLine($"{mva.Name} - {s.Item1}");
                        var sampleD = d.mkdir(s.Item1);
                        PlotMVAResult(s.Item2.AsGoodJetStream().FilterNonTrainingEvents().FilterLLPNear(), sampleD, mvaValue);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            // Get command line arguments
            var opt = ParseOptions<Options>(args);

            // Build our own set of background samples so we can experiment.
            var jets = SampleMetaData.AllSamplesWithTag("background")
                .Select(info => Files.GetSampleAsMetaData(info));

            // Count them individually
            var individualCounts = jets.Select(sample => sample.FutureCount()).ToArray();
            var firstsum = from c1 in individualCounts[0] from c2 in individualCounts[1] select c1 + c2;
            var sum = individualCounts.Skip(2).Aggregate(firstsum, (tot, val) => from t in tot from v in val select t + v);

            // Get the samples with an official weight attached to them.
            var allSamplesToTest =
                new[] { Tuple.Create("JZAll", GetAllJetSamples()) }
                .Concat(SampleMetaData.AllSamplesWithTag("background").Select(info => Tuple.Create(info.NickName, Files.GetSampleAsMetaData(info))))
                .ToArray();

            var totalCount = GetAllJetSamples().FutureCount();

            // Make a pT plot
            using (var outputHistograms = new FutureTFile("JZPlotter.root"))
            {
                foreach (var sampleInfo in allSamplesToTest)
                {
                    var events = sampleInfo.Item2;
                    var hdir = outputHistograms.mkdir(sampleInfo.Item1);

                    events
                        .Select(e => e.Data.eventWeight)
                        .FuturePlot("event_weights", "Sample EventWeights", 100, 0.0, 1000.0)
                        .Save(hdir);

                    events
                        .AsGoodJetStream()
                        .FuturePlot(JetPtPlotJetStream.ResetWeight(), "pt_unweighted")
                        .Save(hdir);
                    events
                        .AsGoodFirstJetStream()
                        .FuturePlot(JetPtPlotJetStream.ResetWeight(), "first_pt_unweighted")
                        .Save(hdir);

                    events
                        .AsGoodJetStream()
                        .FuturePlot(JetPtPlotJetStream, "pt_weighted")
                        .Save(hdir);
                    events
                        .AsGoodFirstJetStream()
                        .FuturePlot(JetPtPlotJetStream, "first_jet_pt_weighted")
                        .Save(hdir);
                }
            }

            // Print out summary of numbers
            Console.WriteLine($"Sum by adding individually: {sum.Value}.");
            Console.WriteLine($"Sum when done all as one: {totalCount.Value}");
            foreach (var s in individualCounts)
            {
                Console.WriteLine($"  Sample Events: {s.Value}.");
            }
        }