コード例 #1
0
        /// <summary>
        /// Look at a single set of stuff for the ABCD method
        /// </summary>
        /// <param name="explorer"></param>
        /// <param name="backgrounds"></param>
        /// <param name="output"></param>
        private static ABCDInfo DoABCDExploration(ABCDCutExplorer <EventType> explorer, IQueryable <EventType> backgrounds, FutureTDirectory output)
        {
            var info = explorer.ProcessBackground(output.mkdir("JnZ"), backgrounds);

            // And a few signals
            var signalList = SampleMetaData.AllSamplesWithTag("signal")
                             .Select(i => Tuple.Create(i.NickName, Files.GetSampleAsMetaData(i)));

            foreach (var source in signalList)
            {
                // Do everything
                var asEvents = source.Item2
                               .AsEventStream();
                explorer.ProcessSignal(output.mkdir(source.Item1), asEvents);

                // Now, look carefully at only "signal" jets
                var asCalSignalEvents = asEvents
                                        .Where(t => SampleUtils.IsGoodSignalJet.Invoke(t.Item1.Jet) && SampleUtils.IsGoodSignalJet.Invoke(t.Item2.Jet));
                explorer.ProcessSignal(output.mkdir($"{source.Item1}-CalOnly"), asCalSignalEvents);
            }

            return(info);
        }
コード例 #2
0
        /// <summary>
        /// Generate a ROOT file that will have all the MC events in them along with the vpion stuff.
        /// </summary>
        /// <param name="sample">The sample of data to skim</param>
        /// <param name="namePostfix">The output filename post-fix we should add.</param>
        public static IFutureValue <FileInfo> CreateVpionROOTFiles(this SampleMetaData sample, string namePostfix)
        {
            // Get the sample file
            var file = Files.GetSampleAsMetaData(sample);

            // The object that gives us access to the official event selection and ABCD method region
            // boundaries.
            var eventSelector = new SelectionHelperEventSelection();

            // Create the data we are going to write out. Every single event
            // has to be written out.
            // TODO:
            //   - Change to BDT13Lxy
            //   - Change to using BDT ordered jets
            //  Both of these require upgrading to the next version of the TTree, sadly.
            var dataStream = from evt in file
                             where evt.Data.LLPs.Count() == 2
                             let llp1                                                        = evt.Data.LLPs[0]
                                                              let llp2                       = evt.Data.LLPs[1]
                                                                                    let jets = evt.Data.Jets
                                                                                               .OrderByDescending(j => j.BDT13Lxy)
                                                                                               .Take(2)
                                                                                               let j1                   = jets.FirstOrDefault()
                                                                                                                 let j2 = jets.Skip(1).FirstOrDefault()
                                                                                                                          let minDR2Sum = evt.Data.Jets
                                                                                                                                          .Where(j => j.pT > 50.0 && Abs(j.eta) < 2.5 && j.isGoodLLP)
                                                                                                                                          .Sum(j => j.CalibJet_minDRTrkpt2)
                                                                                                                                          let isSelected = jets.Count() != 2
                                ? false
                                : eventSelector.eventSelection(j1.pT, j2.pT, j1.eta, j2.eta, j1.isGoodLLP, j2.isGoodLLP,
                                                               j1.phi, j2.phi, j1.time, j2.time, evt.Data.event_HTMiss, evt.Data.event_HT, minDR2Sum)
                                                                                                                                                           let passedTrigger = evt.Data.event_passCalRatio_TAU60
                                                                                                                                                                               let region = (jets.Count() != 2)
                                ? 0
                                : eventSelector.ABCDPlane(j1.pT, j2.pT, j1.BDT13Lxy, j2.BDT13Lxy, minDR2Sum)
                                                                                                                                                                                            select new VpionData
            {
                PassedCalRatio = passedTrigger,
                eventNumber    = evt.Data.eventNumber,
                llp1_E         = llp1.E,
                llp1_eta       = llp1.eta,
                llp1_phi       = llp1.phi,
                llp1_pt        = llp1.pT,
                llp1_Lxy       = llp1.Lxy,
                llp2_E         = llp2.E,
                llp2_eta       = llp2.eta,
                llp2_phi       = llp2.phi,
                llp2_pt        = llp2.pT,
                llp2_Lxy       = llp2.Lxy,
                event_weight   = evt.Data.eventWeight * Abs(evt.Data.pileupEventWeight),
                // TODO: get from Emma how to do this correctly (once we figure it out!!)
                RegionA = passedTrigger && isSelected && region == 1,
                RegionB = passedTrigger && isSelected && region == 2,
                RegionC = passedTrigger && isSelected && region == 3,
                RegionD = passedTrigger && isSelected && region == 4
            };

            // Now, write it out to a file.
            var f = dataStream
                    .FutureAsTTree(treeName: "extrapTree", treeTitle: "Used as input for the extrapolation");

            // Total up everything for final numbers, and dump it out.
            var total  = dataStream.FutureCount();
            var totalA = dataStream.Where(t => t.RegionA).FutureCount();
            var totalB = dataStream.Where(t => t.RegionB).FutureCount();
            var totalC = dataStream.Where(t => t.RegionC).FutureCount();
            var totalD = dataStream.Where(t => t.RegionD).FutureCount();

            FutureConsole.FutureWriteLine(() => $"EventInfo: {namePostfix} {total.Value} {totalA.Value} {totalB.Value} {totalC.Value} {totalD.Value}");

            // Total up everything for final numbers, and dump it out. Use weights
            var totalW  = dataStream.FutureAggregate(0.0, (ac, ev) => ac + ev.event_weight);
            var totalAW = dataStream.Where(t => t.RegionA).FutureAggregate(0.0, (ac, ev) => ac + ev.event_weight);
            var totalBW = dataStream.Where(t => t.RegionB).FutureAggregate(0.0, (ac, ev) => ac + ev.event_weight);
            var totalCW = dataStream.Where(t => t.RegionC).FutureAggregate(0.0, (ac, ev) => ac + ev.event_weight);
            var totalDW = dataStream.Where(t => t.RegionD).FutureAggregate(0.0, (ac, ev) => ac + ev.event_weight);

            FutureConsole.FutureWriteLine(() => $"EventInfo (weighted): {namePostfix} {totalW.Value:F1} {totalAW.Value:F1} {totalBW.Value:F1} {totalCW.Value:F1} {totalDW.Value:F1}");

#if DEBUG_TEST
            var csvdata = dataStream
                          .Where(e => e.RegionA || e.RegionB || e.RegionC || e.RegionD)
                          .FutureAsCSV(new FileInfo("events-in-signal-region.csv"));
#endif

            // Return only the first file - as there should be no more than that!
            return(f
                   .Select(flst =>
            {
                if (flst.Length != 1)
                {
                    throw new ArgumentException($"Got more than one file back when running LLP Extrapolation ntuple (found {flst.Length}!");
                }
                return flst;
            })
                   .Select(flst => flst[0])
                   .Select(fspec =>
            {
                var fnew = new FileInfo(Path.Combine(fspec.DirectoryName, $"LLPExtrapolationMCTree-{namePostfix}{fspec.Extension}"));
                return fspec.CopyTo(fnew.FullName, true);
            }));
        }