From a5843891d4cbda81714cc4b8b63b7f0696fbca97 Mon Sep 17 00:00:00 2001
From: Klaus Rabbertz <klaus.rabbertz@cern.ch>
Date: Sat, 30 Sep 2023 11:23:45 +0200
Subject: [PATCH] Fix order of scale-factor variations in run card

---
 2jetfc.fnl2412eff-fc-v2.run          |  23 ++-
 analysis/tasks/AllPlots.py           |  15 +-
 analysis/util.py                     |  17 +-
 combine-LO.ini                       |  46 +++++
 steeringfiles/2jet.fnl2412eff-fc.str | 269 ---------------------------
 5 files changed, 79 insertions(+), 291 deletions(-)
 create mode 100644 combine-LO.ini
 delete mode 100644 steeringfiles/2jet.fnl2412eff-fc.str

diff --git a/2jetfc.fnl2412eff-fc-v2.run b/2jetfc.fnl2412eff-fc-v2.run
index 68121d4..31e7d0e 100644
--- a/2jetfc.fnl2412eff-fc-v2.run
+++ b/2jetfc.fnl2412eff-fc-v2.run
@@ -23,11 +23,11 @@ RUN @CHANNEL@-CMS7-ak07     ! job name
   PDF = NNPDF31_nnlo_as_0118[0] ! PDFset[member]
   tcut = 1d-8                   ! y0, appears in filenames of warmup
   iseed   = @SEED@              ! seed index
-  cache_kinematics = .true.     ! normally true
-  reset_vegas_grid = .true.
+  cache_kinematics = .true.     ! caching for kinematics; normally true
+  reset_vegas_grid = .true.     ! normally true
   lips_reduce      = .true.     ! optimisation for identical particles in FS; normally true
-  angular_average  = .false.    ! azimuthal rotation; only relevant for NNLO; use RR false; R, RV true; rest: true
-  multi_channel    = .true.     ! color sampling; true means faster, but less precise; must be consistent between warmup & production
+  angular_average  = .true.     ! azimuthal rotation; only relevant for NNLO; can always be true; might be false for RR
+  multi_channel    = 5          ! color sampling; true faster, less precise; true/false must be consistent between warmup & production; can be set to 5 instead of true
   @RUNMODE@ = @EVENTS@[@ITERATIONS@] ! Normally #iterations is 1 for production
 END_RUN
 
@@ -51,13 +51,17 @@ END_PARAMETERS
 
 
 SELECTORS
+! Base event selection
+        select jets_pt min = 30.0
+        select jets_abs_y max = 3.0
+        select njets min = 2
+! Leading jets
         select ptj1 min =  60.0
-        select ptj2 min =  30.0
+!        select ptj2 min =  30.0            ! redundant
         select abs_yj1 max =  2.5
         select abs_yj2 max =  2.5
         select m12 min = 197.0 max = 5058.0
-        select max_abs_y_j12 min = 0.0 max = 2.5
-        select njets min = 2
+!        select max_abs_y_j12 max = 2.5     ! redundant
 END_SELECTORS
 
 
@@ -92,14 +96,15 @@ END_HISTOGRAMS
 
 
 SCALES
-!7-scale setup
+! Central scale followed by 6 scale-factor variations
+! To correspond to fastNLO, order must be:
     muf = 1.0 * m12     mur = 1.0 * m12
     muf = 0.5 * m12     mur = 0.5 * m12
     muf = 2.0 * m12     mur = 2.0 * m12
     muf = 1.0 * m12     mur = 0.5 * m12
-    muf = 1.0 * m12     mur = 2.0 * m12
     muf = 0.5 * m12     mur = 1.0 * m12
     muf = 2.0 * m12     mur = 1.0 * m12
+    muf = 1.0 * m12     mur = 2.0 * m12
 END_SCALES
 
 
diff --git a/analysis/tasks/AllPlots.py b/analysis/tasks/AllPlots.py
index 09ef9b8..ad0cb67 100644
--- a/analysis/tasks/AllPlots.py
+++ b/analysis/tasks/AllPlots.py
@@ -20,14 +20,15 @@ class AllPlots(law.WrapperTask):
 
     def requires(self):
         return {
-            'absolute': Absolute.req(self),
-            'kfaccomparison': KfacComparison.req(self),
-            'mergedgridclosure': MergedGridClosure.req(self),
-            'multigridclosure': MultiGridClosure.req(self),
-            'pdfuncertainty': PdfUncertainty.req(self),
+#            'plotvegasgrids': PlotVegasGrids.req(self),
             'plotruntime': PlotRuntime.req(self),
-            'plotvegasgrids': PlotVegasGrids.req(self),
-            'scaleuncertainty': ScaleUncertainty.req(self),
             'singlegridclosure': SingleGridClosure.req(self),
+            'multigridclosure': MultiGridClosure.req(self),
+            'mergedgridclosure': MergedGridClosure.req(self),
             'statuncertainty': StatUncertainty.req(self),
+            'absolute': Absolute.req(self),
+            'kfaccomparison': KfacComparison.req(self),
+            'scaleuncertainty': ScaleUncertainty.req(self),
+            'pdfuncertainty': PdfUncertainty.req(self),
+#            'datacomparison': DataComparison.req(self),
         }
diff --git a/analysis/util.py b/analysis/util.py
index 87e7f07..599a8b9 100644
--- a/analysis/util.py
+++ b/analysis/util.py
@@ -49,12 +49,17 @@ def log_maybe_raise(level, *args, raise_cls=None, logger=None):
 def createRuncard(baseRuncard, params):
 
     substitutions = {
-        '@RUNMODE@': params['runmode'],
-        '@UNIT_PHASE@': params['unit_phase'],
-        '@CHANNEL@': params['channel'],
-        '@SEED@': params['seed'],
-        '@EVENTS@': params['events'],
-        '@ITERATIONS@': params['iterations']
+        '@RUNMODE@'          : params['runmode'],
+        '@UNIT_PHASE@'       : params['unit_phase'],
+        '@CHANNEL@'          : params['channel'],
+        '@SEED@'             : params['seed'],
+        '@CACHE_KINEMATICS@' : params['cache_kinematics'],
+        '@RESET_VEGAS_GRID@' : params['reset_vegas_grid'],
+        '@LIPS_REDUCE@'      : params['lips_reduce'],
+        '@ANGULAR_AVERAGE@'  : params['angular_average'],
+        '@MULTI_CHANNEL@'    : params['multi_channel'],
+        '@EVENTS@'           : params['events'],
+        '@ITERATIONS@'       : params['iterations']
     }
 
     data = baseRuncard
diff --git a/combine-LO.ini b/combine-LO.ini
new file mode 100644
index 0000000..c4ac144
--- /dev/null
+++ b/combine-LO.ini
@@ -0,0 +1,46 @@
+[Paths]
+raw_dir = .
+out_dir = Combined
+
+
+[Observables]
+ALL
+
+#> rebin an observable
+# observable > observable_rebin : [x0, x1, x2, ... xN]
+
+
+[Parts]
+LO
+#V
+#R
+#RRa
+#RRb
+#RV
+#VV
+
+
+
+[Final]
+LO        = LO
+#R         = R
+#V         = V
+#RRa       = RRa
+#RRb       = RRb
+#RV        = RV
+#VV        = VV
+#NLO       = LO + R + V
+#NNLO      = LO + R + V + RRa + RRb + RV + VV
+#NLO_only  = R + V
+#NNLO_only = RRa + RRb + RV + VV
+
+
+[Options]
+#> search the directory structure recursive for data files
+# recursive = True
+
+#> output weight tables: for APPLfast
+weights = True
+
+#> restrict merge to only certain columns: e.g. drop channel breakdown for performance
+# columns = ['tot_scale01', 'tot_scale02', 'tot_scale03', 'tot_scale04', 'tot_scale05', 'tot_scale06', 'tot_scale07']
diff --git a/steeringfiles/2jet.fnl2412eff-fc.str b/steeringfiles/2jet.fnl2412eff-fc.str
deleted file mode 100644
index d577c88..0000000
--- a/steeringfiles/2jet.fnl2412eff-fc.str
+++ /dev/null
@@ -1,269 +0,0 @@
-# -*-sh-*-
-# ==================================================================== #
-#
-#   A steering file for creating a fastNLO table/grid (with NNLOJET)
-#   This is an example for a global steering for ALL tables/grids of a scenario
-#
-#   The grid production is performed in three steps:
-#   I.   A warmup run for NNLOJET to perform essential integrations
-#        See NNLOJET for details. fastNLO is not used or called at this stage.
-#   II.  A warmup run for fastNLO that determines the accessed phase space
-#        in momentum fraction x and process scale mu_r, mu_f.
-#        Only a few fastNLO settings are used here, see below.
-#        The output is written into a warmup file named after the
-#        the NNLOJET process name, e.g. 'ZJ', the NNLOJET job name, e.g.
-#        'LO-CMS13-ak07', and the NNLOJET grid name, e.g.
-#        ptz > ZJtriple_yb0_ystar0_ptz [30, 100, 200, 300, 400, 1000] grid = ZJtriple_yb0_ystar0_ptz.fast
-#              NNLOJET histo                                                 fastNLO grid
-#        ==> ZJ.LO-CMS13-ak07.ZJtriple_yb0_ystar0_ptz.wrm
-#        This warmup file stores some settings for fastNLO in addition to
-#        the accessed phase space (with number of events per bin!) for
-#        each order of NNLOJET run (LO, R, V, RRa, RRb, RV, VV).
-#        For a later combination ALL production runs in step III below
-#        MUST use the SAME warmup file. The latter should be the largest
-#        accessed phase space as combined from any order in NNLOJET!
-#        ==> the expected filename for this unique warmup file is
-#            ZJ.ZJtriple_yb0_ystar0_ptz.wrm
-#        without the job name info.
-#   III. Many production runs filling fastNLO grids for various orders
-#        of a process from NNLOJET that later must be combined.
-#        See NNLOJET for details.
-#        Most fastNLO settings are taken into account here.
-#
-#   This steering file has to be used in combination with a NNLOJET
-#   run card, where most of the essential seetings like the
-#   observable and its binning are defined.
-#   Modifications or additional settings respect the following hierarchy:
-#   1.  From the interface package nnlo-bridge default settings for
-#       fastNLO with NNLOJET are made and information from NNLOJET is
-#       passed to fastNLO.
-#   2.  A steering file named after the NNLOJET grid name for fastNLO,
-#       e.g. from the example above
-#             ==> ZJ.ZJtriple_yb0_ystar0_ptz.str
-#       can be used to set steer parameters individually for each fastNLO grid.
-#       Settings from step 1 can be overwritten. Be careful not to make
-#       changes inconsistent with what is defined in the NNLOJET run card
-#       or what is mandatory for the interface to work!
-#   3a. In production runs the previously derived warmup file is read.
-#   3b. A global steering file named after only the first part of
-#       the NNLOJET grid name for fastNLO, 'ZJtriple', which is also used
-#       as fastNLO scenario name,
-#             ==> ZJ.ZJtriple.str
-#       can be used to set steer parameters globally for all fastNLO grids.
-#       Settings from step 2 are not overwritten, but lead to warnings.
-#   4.  In principal, parameters can also be set on the command line, but
-#       this has not been tested yet.
-#
-#   Special remarks on scale settings:
-#   ----------------------------------
-#   Lacking sufficient scale choice information from NNLOJET the following
-#   settings are assumed for flexible-scale tables that allow two central
-#   scale choices to be stored simultaneously:
-#                                          DIS       pp
-#   - the 1st scale set for muf defines   scale1   scale2
-#   - the 1st scale set for mur defines   scale2   scale1
-#   To check the closure between NNLOJET and fastNLO the proper
-#   ASYMMETRIC central scale choice must be used when evaluating a
-#   fastNLO grid with fnlo-tk-cppread, either scale12 or scale21.
-#
-#   It is recommended to set ScaleDescriptionScale1 and
-#   ScaleDescriptionScale2 accordingly.
-#
-#   If multiple entries per event are requested using NNLOJET COMPOSITE
-#   histos AND a scale definition varying with each entry is desired,
-#   then one central scale, e.g. ptmax=ptj1, must be defined for both
-#   muf and mur, and the InclusiveJets flag must be set in the fastNLO
-#   steering file.
-#   In that case the following definitions hold depending on the
-#   nnlo-bridge code version:
-#
-#   BRIDGE 0.0.40:
-#   (requires additional fixed-scale combinations of
-#    muf =  2.718281828459045  mur =  2.718281828459045
-#    muf =  4.481689070338065  mur =  4.481689070338065
-#    muf =  4.481689070338065  mur =  2.718281828459045
-#    muf =  2.718281828459045  mur =  4.481689070338065
-#    muf = 12.18249396070347   mur =  2.718281828459045
-#    muf =  2.718281828459045  mur = 12.18249396070347
-#    in the SCALES section of the NNLOJET run card.)
-#
-#                                              DIS       pp
-#   - the 1st scale set for muf&mur defines   scale1   scale2
-#   - the stored observable defines           scale2   scale1
-#   To check the closure between NNLOJET and fastNLO the proper
-#   SYMMETRIC central scale choice must be used when evaluating a
-#   fastNLO grid with fnlo-tk-cppread, either scale1 or scale2.
-#
-#   BRIDGE 0.0.46:
-#   (requires additional fixed-scale combinations of
-#    muf =  90.0171313005      mur =  90.0171313005
-#    muf =  54.5981500331      mur =  54.5981500331
-#    muf = 148.4131591026      mur = 148.4131591026
-#    muf =  54.5981500331      mur =  90.0171313005
-#    muf =  90.0171313005      mur =  54.5981500331
-#    muf = 148.4131591026      mur =  90.0171313005
-#    in the SCALES section of the NNLOJET run card.)
-#
-#                                              DIS(?)   pp
-#   - the 1st scale set for muf&mur defines   scale1   scale2=mu/obs(!)
-#   - the stored observable defines           scale2   scale1
-#   To check the closure between NNLOJET and fastNLO the proper
-#   SYMMETRIC central scale choice must be used when evaluating a
-#   fastNLO grid with fnlo-tk-cppread, i.e. for pp scale1*scale2.
-#
-# ==================================================================== #
-
-# ==================================================================== #
-#
-#   Scenario specific settings
-#
-#   Either set individually for each fastNLO grid or globally for all
-#
-# ==================================================================== #
-
-# -------------------------------------------------------------------- #
-#   Settings to be modified already for Warmup
-#   (These are stored in the warmup file!)
-# -------------------------------------------------------------------- #
-#CheckScaleLimitsAgainstBins     true             # (def.=true) Set limits for scale nodes to bin borders, if possible. Good if scale equals the binned observable.
-                                                  # Scales and scale factors must be set in the NNLOJET run card
-ScaleDescriptionScale1          "m12_[GeV]"      # (def.='scale1') Reset the 1st scale name and unit, e.g. "<pT_1,2>_[GeV]" (Note: The 1st scale must always be in units of [GeV]!)
-ScaleDescriptionScale2          "m12_[GeV]"      # (def.='scale2') Reset the 2nd scale name and unit (ONLY for flexible-scale tables)
-#DifferentialDimension             1              # (must be 1) So far the interface to NNLOJET supports only 1-dim histograms. DO NOT CHANGE!
-DimensionLabels {                                # Labels (symbol and unit) for the measurement dimension (from outer to inner "loop")
-   "m12_[GeV]"                                   # The default following the example above would be: "ptz"
-}
-#DimensionIsDifferential {                        # (must be 2) Specify for each dimension whether
-#   2                                             #   0 : the cross section is NOT differential,        i.e. there are two bin borders,
-#}                                                #                                                     but NO division (normalization) by bin width
-                                                  #   1 : the cross section is point-wise differential, i.e. only one point is given
-                                                  #   2 : the cross section is bin-wise differential,   i.e. there are two bin borders
-                                                  # Since NNLOJET provides bin-wise differential distributions use option 2. DO NOT CHANGE!
-
-# -------------------------------------------------------------------- #
-#   Description of scenario
-#
-#   (Write each line of description in quotation marks)
-# -------------------------------------------------------------------- #
-ScenarioName fnl2412eff-fc                        # (def.=NNLOJET process name) No white space allowed here!
-                                                  # Here: Either one description for all
-ScenarioDescription {                             # Replace generic one-line text by desired (multi-line) description
-    "d2sigma-dijet_dMjj_dy_max_[pb_GeV]"
-    "CMS_Collaboration"
-    "Dijet_Mass_m12_ym0-ym4"
-    "anti-kT_R=0.7"
-    "CMS-PAPER-QCD-11-004, arXiv:1212.6660, Phys. Rev. D 87 (2013) 112002."
-    "RIVET_ID=CMS_2013_I1208923/D06-x01-y01,SPIRES_ID=9901922,INSPIRE_RECORD=1208923"
-    "THEORY_LABEL=NNLOJET modules2 FC"
-    "provided by:"
-    "fastNLO_2.3.1"
-    "If you use this table, please cite:"
-    "  D. Britzger, T. Kluge, K. Rabbertz, F. Stober, M. Wobisch, arXiv:1109.1310"
-}
-PublicationUnits                12               # (def.=12) Cross section unit to be used for output (negative power of 10, e.g. 12->pb, 15->fb)
-                                                 # For comparison, e.g. via Rivet, should correspond to published data cross sections
-
-# -------------------------------------------------------------------- #
-#   Cuts
-# -------------------------------------------------------------------- #
-# To bet set via NNLOJET run card
-
-# -------------------------------------------------------------------- #
-#   Observable normalization
-# -------------------------------------------------------------------- #
-#CalculateBinSize               true              # (def.=true)    Calculate bin width from lower and upper bin boundaries
-#BinSizeFactor                    1.              # (def.=1.)      Possibility to provide additional normalization factor, e.g. of 2. for bins in |y|
-#BinSize { x1 x2 x3 ... }                         # (def. not set) If 'CalculateBinSize' is 'false' provide table with bin widths 'by hand' for normalization
-
-# -------------------------------------------------------------------- #
-#   Observable binning
-# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-#   Use either 'SingleDifferentialBinning' or
-#     'DoubleDifferentialBinning' or
-#     'TripleDifferentialBinning'
-#   in accord with 'DifferentialDimension' above
-# -------------------------------------------------------------------- #
-# To bet set via the NNLOJET run card
-
-# ==================================================================== #
-#
-#   Process specific and therefore at least partially theory-code
-#   dependent settings
-#
-# ==================================================================== #
-# To bet set directly from NNLOJET interface and via the NNLOJET run card
-
-# ==================================================================== #
-#
-#   A few special settings only used with NNLOJET so far
-#
-# ==================================================================== #
-#InclusiveJets                   true             # (def.=false) Flag to vary the mur, muf scale per entry, not just per event
-#                                                 # Must be set in accordance with NNLOJET run card!
-#                                                 # Only possible with flexible-scale grids
-
-# ==================================================================== #
-#
-#   General fastNLO settings
-#
-# ==================================================================== #
-GlobalVerbosity                 INFO             # (def.=WARNING) Global output verbosity of fastNLO toolkit,
-                                                 # (and of user scenario code if implemented).
-                                                 # Possible values are: DEBUG, MANUAL, INFO, WARNING, ERROR, SILENT
-FlexibleScaleTable              true             # (def.=false) Create table fully flexible in mu_f (larger size), true, or
-                                                  # table with fixed number of mu_f scale factors
-CacheType                       0                # For now switch off caching feature
-#CacheMax                        30
-#CacheCompare                    10
-
-# ==================================================================== #
-#
-#   Specific fastNLO settings (normally do not need to be changed)
-#   Only change when you know what you are doing ...!
-#
-# ==================================================================== #
-#OutputFilename           fastNLO.tab             # Overwrites default filename of fastNLO output table, e.g. ZJ.LO-CMS13.vBa.ZJtriple_yb0_ystar0_ptz.s92394.tab.gz
-#OutputPrecision                 8                # (def.=8) Number of decimal digits to store in output table
-#OutputCompression               true             # (def.=true) Write out fastNLO table/grid in gzipped format (requires zlib)
-#CacheType                       0
-#CacheMax                       30
-#CacheCompare                   10
-#ScaleVariationFactors {                          # (def.=1.0 0.5 2.0) Must be set in accordance with NNLOJET run card! Factorization scale variations (only needed for fixed-scale tables)
-#  1.0 0.5 2.0                                    # List of scale factors must include factor '1.0'
-#}                                                # Scale factors will be ordered according to fastNLO convention: (1, min, ... , max)
-#ReadBinningFromSteering         false            # (must be true) Specify where the binning is defined.
-#ApplyPDFReweighting             true             # (def.=true) Apply reweighting of PDFs for an optimized interpolation
-
-# -------------------------------------------------------------------- #
-#   Choose fastNLO interpolation kernels and distance measures
-# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-#   Currently implemented interpolation kernels
-#     Catmull
-#     Lagrange
-#     OneNode
-#     Linear
-#
-#   Currently implemented distance measures
-#     linear
-#     loglog025        eq. to (log(log(4*x)))
-#     log10
-#     sqrtlog10        eq. to sqrt(log_10(x))
-#
-#   For a constant scale like M_Z use e.g.
-#     Mu1_Kernel                      OneNode
-#     Mu1_DistanceMeasure             "log10"
-#     Mu1_NNodes                      1
-# -------------------------------------------------------------------- #
-#X_Kernel                        Lagrange         # (def.= pp: Lagrange;  DIS: Catmull)
-#X_DistanceMeasure               sqrtlog10        # (def.= pp: sqrtlog10; DIS: log10)
-#X_NNodes                        20               # (def.= pp: 20;        DIS: 18)
-#X_NNodeCounting                 NodesPerBin      # (def.=NodesPerBin)
-
-#Mu1_Kernel                      Lagrange         # (def.=Lagrange)
-#Mu1_DistanceMeasure             "loglog025"      # (def.=loglog025)
-#Mu1_NNodes                      6                # (def.=6)
-
-# Scale2 not used for fixed-scale tables
-Mu2_Kernel                      OneNode          # (def.=Lagrange)
-Mu2_DistanceMeasure             "loglog025"      # (def.=loglog025)
-Mu2_NNodes                      1                # (def.=6)
-- 
GitLab