StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VinciaWeights.h
1 // VinciaWeights.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2020 Peter Skands, Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL v2 or later, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // This file contains header information for the VinciaWeights class.
7 
8 #ifndef Vincia_VinciaWeights_H
9 #define Vincia_VinciaWeights_H
10 
11 #include "Pythia8/Info.h"
12 #include "Pythia8/Settings.h"
13 #include "Pythia8/VinciaCommon.h"
14 
15 namespace Pythia8 {
16 
18 
19 public:
20 
21  // Friends for internal private members.
22  friend class VinciaFSR;
23  friend class VinciaISR;
24 
25  // Constructor.
26  VinciaWeights() {}
27 
28  // Destructor.
29  ~VinciaWeights() {}
30 
31  // Initilize pointers.
32  bool initPtr(Info* infoPtrIn, VinciaCommon* vinComPtrIn);
33 
34  // Initilize.
35  void init();
36 
37  // Check if particular weight exists.
38  bool existsWeight(int iWeightIn = 0) {
39  if (iWeightIn >= 0 && iWeightIn < nWeightsSav) return true;
40  else return false;}
41 
42  // Get weight of current event weight. Normally 1 for set 0 (user
43  // settings). Use iWeightIn > 0 to access uncertainty weights.
44  double weight(int iWeightIn = 0) {
45  if (existsWeight(iWeightIn)) return weightsSav[iWeightIn];
46  return 0.0;}
47 
48  // Access the weight labels.
49  string weightLabel(int iWeightIn = 0) {
50  if (iWeightIn == 0) return "no variation";
51  if (existsWeight(iWeightIn) && iWeightIn-1 < (int)varLabels.size())
52  return varLabels[iWeightIn-1];
53  return "";}
54 
55  // Functions to access by VINCIA plugin.
56  int nWeights() {return nWeightsSav;}
57  bool reweightingOccurred() {return didReweight;}
58 
59  // Reset the weights, to be called at the beginning of each event.
60  void resetWeights(int nAccepted);
61 
62  // Scale all event weights.
63  void scaleWeightAll(double scaleFacIn);
64 
65  // Scale a particular event weight.
66  void scaleWeight(double scaleFacIn, int iWeightIn = 0);
67 
68  // Scale the uncertainty band weights.
69  void scaleWeightVar(vector<double> pAccept, bool accept, bool isHard);
70 
71  // Scale the uncertainty band weights if branching is accepted.
72  void scaleWeightVarAccept(vector<double> pAccept);
73 
74  // Scale the uncertainty band weights if branching is rejected.
75  void scaleWeightVarReject(vector<double> pAccept);
76 
77  // Enhanced kernels: reweight if branching is accepted.
78  void scaleWeightEnhanceAccept(double enhanceFac = 1.);
79 
80  // Enhanced kernels: reweight if branching is rejected.
81  void scaleWeightEnhanceReject(double pAcceptUnenhanced,
82  double enhanceFac = 1.);
83 
84  // Helper function for keyword evaluation.
85  int doVarNow(string keyIn, int iAntPhys, string type) ;
86 
87  // Helper function for antenna function.
88  double ant(double antIn, double cNSIn) {return (antIn+cNSIn);}
89 
90  // Main function to perform the weighting.
91  void doWeighting();
92 
93 private:
94 
95  // Verbosity.
96  int verbose;
97 
98  // Pointers.
99  Info* infoPtr;
100  Settings* settingsPtr;
101  VinciaCommon* vinComPtr;
102 
103  // Internal flag.
104  bool isInitPtr;
105 
106  // Constants.
107  static const double TINYANT, PACCEPTVARMAX, MINVARWEIGHT;
108 
109  // Parameters taken from settings.
110  bool uncertaintyBands;
111  vector<string> varLabels;
112  vector< vector<string> > varKeys;
113  vector< vector<double> > varVals;
114 
115  // Helper parameters.
116  vector<string> allKeywords;
117  map<int,string> iAntToKeyFSR, iAntToKeyISR;
118  double nWeightsSav;
119  int nReportWeight, nReportedWeight;
120  bool doAlphaSvar, doFiniteVar;
121 
122  // Weights (from input events, enhancement, MC violations, or variations).
123  vector<double> weightsSav;
124  vector<double> weightsOld;
125  vector<double> weightsMax, weightsMin;
126  // Weight sums.
127  vector<double> weightSum, weightSum2;
128  // Contribution of current event.
129  vector<double> contribSum, contribSum2;
130 
131  // Counter for total number of weights = nr of events.
132  int nTotWeights;
133  // Counter for initial and main weight (MC violation only).
134  int nNonunityWeight, nNegativeWeight,
135  nNonunityInitialWeight, nNegativeInitialWeight;
136  // Counter for current event.
137  int nNonunityWeightNow, nNegativeWeightNow,
138  nNonunityInitialWeightNow, nNegativeInitialWeightNow;
139 
140  // Flag to tell if reweighting due to MC violations occured.
141  bool didReweight;
142 
143  // Flag if doWeighting called for the first time.
144  bool firstCall;
145 
146 };
147 
148 //==========================================================================
149 
150 } // end namespace Pythia8
151 
152 #endif // end Pythia8_VinciaWeights_H