From 5bdfaaef7934952fd6c9a178166a3ed27e774f39 Mon Sep 17 00:00:00 2001
From: Andrew Edmonds <aedmonds@lbl.gov>
Date: Mon, 11 Nov 2019 15:49:38 -0600
Subject: [PATCH 1/2] Updating sequential mixing skipping so that it will work
 for all background frames

---
 EventMixing/src/MixBackgroundFrames_module.cc | 18 ++++++------------
 JobConfig/mixing/prolog.fcl                   |  3 +--
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/EventMixing/src/MixBackgroundFrames_module.cc b/EventMixing/src/MixBackgroundFrames_module.cc
index 88280ade54..b415235f5a 100644
--- a/EventMixing/src/MixBackgroundFrames_module.cc
+++ b/EventMixing/src/MixBackgroundFrames_module.cc
@@ -53,13 +53,9 @@ namespace mu2e {
           Comment("control the level of debug output"),
           0u
           };
-      Atom<int> minSkip { Name("minSkip"),
-	  Comment("minimum number of background events to skip at the start of a file"),
-	  0
-	  };
-      Atom<int> maxSkip { Name("maxSkip"),
-	  Comment("maximum number of background events to skip at the start of a file"),
-	  10000
+      Atom<int> skipFactor { Name("skipFactor"),
+	  Comment("mixer will skip a number of background events between 0 and this integer mulitplied by meanEventsPerProton and PBI intensity at the start of each secondary input file."),
+	  1
 	  };
     };
 
@@ -96,8 +92,7 @@ namespace mu2e {
 
     ProtonBunchIntensity pbi_;
     int totalBkgCount_;
-    int minSkip_;
-    int maxSkip_;
+    int skipFactor_;
 
   public:
     MixBackgroundFramesDetail(const fhicl::ParameterSet& pset, art::MixHelper &helper);
@@ -120,8 +115,7 @@ namespace mu2e {
     , engine_{helper.createEngine(art::ServiceHandle<SeedService>()->getSeed())}
     , urbg_{ engine_ }
     , totalBkgCount_(0)
-    , minSkip_{ retrieveConfiguration("mu2e", pset).minSkip() }
-    , maxSkip_{ retrieveConfiguration("mu2e", pset).maxSkip() }
+    , skipFactor_{ retrieveConfiguration("mu2e", pset).skipFactor() }
   {}
 
   //================================================================
@@ -142,7 +136,7 @@ namespace mu2e {
   //================================================================
   size_t MixBackgroundFramesDetail::eventsToSkip() {
     //FIXME: Ideally, we would know the number of events in the secondary input file
-    std::uniform_int_distribution<size_t> uniform(minSkip_, maxSkip_);
+    std::uniform_int_distribution<size_t> uniform(0, skipFactor_*meanEventsPerProton_*pbi_.intensity());
     size_t result = uniform(urbg_);
     if(debugLevel_ > 0) { 
       std::cout << " Skipping " << result << " Secondaries " << std::endl; 
diff --git a/JobConfig/mixing/prolog.fcl b/JobConfig/mixing/prolog.fcl
index 545db582a3..38cffd5462 100644
--- a/JobConfig/mixing/prolog.fcl
+++ b/JobConfig/mixing/prolog.fcl
@@ -21,8 +21,7 @@ mixerTemplateCommon: {
       protonBunchIntensityTag: "protonBunchIntensity"
       meanEventsPerProton: @nil
       products: @nil
-      minSkip : 0
-      maxSkip : 1000 # temporary
+      skipFactor : 1 # temporary
    }
 }
 

From 39b035497e45a6b3fc8b09d33d4098b2ef28ad12 Mon Sep 17 00:00:00 2001
From: Andrew Edmonds <aedmonds@lbl.gov>
Date: Tue, 12 Nov 2019 13:09:49 -0600
Subject: [PATCH 2/2] Changing skipFactor from int to float

---
 EventMixing/src/MixBackgroundFrames_module.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/EventMixing/src/MixBackgroundFrames_module.cc b/EventMixing/src/MixBackgroundFrames_module.cc
index b415235f5a..c9ab75d179 100644
--- a/EventMixing/src/MixBackgroundFrames_module.cc
+++ b/EventMixing/src/MixBackgroundFrames_module.cc
@@ -53,8 +53,8 @@ namespace mu2e {
           Comment("control the level of debug output"),
           0u
           };
-      Atom<int> skipFactor { Name("skipFactor"),
-	  Comment("mixer will skip a number of background events between 0 and this integer mulitplied by meanEventsPerProton and PBI intensity at the start of each secondary input file."),
+      Atom<float> skipFactor { Name("skipFactor"),
+	  Comment("mixer will skip a number of background events between 0 and this numberr multiplied by meanEventsPerProton and PBI intensity at the start of each secondary input file."),
 	  1
 	  };
     };
@@ -92,7 +92,7 @@ namespace mu2e {
 
     ProtonBunchIntensity pbi_;
     int totalBkgCount_;
-    int skipFactor_;
+    float skipFactor_;
 
   public:
     MixBackgroundFramesDetail(const fhicl::ParameterSet& pset, art::MixHelper &helper);
