Rivet Analyses Reference

MC_WEIGHTS

MC analysis for distributions of event weights
Experiment: ()
Status: VALIDATED
Authors:
  • Frank Siegert
  • Christian Gutschow
No references listed
Beams: * *
Beam energies: ANY
Run details:
  • Suitable for any process.

Analysis for studying event weight distributions and fraction of events with negative weights. This analysis will not produce sensible distributions in case of correlated NLO sub-events.

Source code: MC_WEIGHTS.cc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// -*- C++ -*-
#include "Rivet/Analysis.hh"
#include "Rivet/AnalysisHandler.hh"

namespace Rivet {


  /// Analysis of the generated event-weight distributions
  class MC_WEIGHTS : public Analysis {
  public:

    RIVET_DEFAULT_ANALYSIS_CTOR(MC_WEIGHTS);


    /// @name Analysis methods
    /// @{

    /// Book histograms and initialise projections before the run
    void init() {
      /// @todo Convert to Scatter1D or Counter
      book(_h_weight_100, "weight_100", 200, -100.0, 100.0);
      book(_h_weight_10,  "weight_10",  200,  -10.0,  10.0);
      book(_h_logweight_pos, "logweight_pos", logspace(100, 0.1, 10000.0));
      book(_h_logweight_neg, "logweight_neg", logspace(100, 0.1, 10000.0));

      book(_h_xsfraction_neg, "xsfraction_neg");
    }


    /// Perform the per-event analysis
    void analyze(const Event& event) {

      const size_t numWeights = event.weights().size();
      for (size_t m = 0; m < numWeights; ++m) {
        const double weight = event.weights()[m];
        _h_weight_100.get()->_getPersistent(m)->fill(weight, 1.0);
        _h_weight_10.get()->_getPersistent(m)->fill(weight, 1.0);
        if (weight < 0.) {
          _h_logweight_neg.get()->_getPersistent(m)->fill(fabs(weight), 1.0);
        } else {
          _h_logweight_pos.get()->_getPersistent(m)->fill(weight, 1.0);
        }
      }
    }


    /// Normalise histograms etc., after the run
    void finalize() {
      const double sf = 1.0 / numEvents();
      scale(_h_weight_100, sf);
      scale(_h_weight_10, sf);
      scale(_h_logweight_pos, sf);
      scale(_h_logweight_neg, sf);

      const double totalSumW  = _h_logweight_neg->sumW() + _h_logweight_pos->sumW();
      const double totalSumW2 = _h_logweight_neg->sumW2() + _h_logweight_pos->sumW2();
      const double negFrac = _h_logweight_neg->sumW() / totalSumW;
      const double negFracErr = negFrac * totalSumW / sqrt(totalSumW2);
      _h_xsfraction_neg->addPoint(0, negFrac, 0.5, negFracErr);
    }

    /// @}


    /// @name Histograms
    /// @{
    Scatter2DPtr _h_xsfraction_neg;
    Histo1DPtr _h_weight_100, _h_weight_10, _h_logweight_pos, _h_logweight_neg;
    /// @}

  };



  RIVET_DECLARE_PLUGIN(MC_WEIGHTS);

}