rivet is hosted by Hepforge, IPPP Durham

Rivet analyses reference

CMS_2018_I1663958

Differential cross sections for top quark pair production using the lepton+jets final state in proton proton collisions at 13 TeV
Experiment: CMS (LHC)
Inspire ID: 1663958
Status: VALIDATED
Authors:
  • Otto Hindrichs
References:
  • arXiv: 1803.08856
  • CMS-TOP-17-002
  • Submitted to Phys. Rev. D.
Beams: p+ p+
Beam energies: (6500.0, 6500.0) GeV
Run details:
  • pp QCD interactions at $\sqrt{s} = 13$ TeV. Data collected by CMS during the year 2015. Selection of lepton+jets top pair candidate events at particle level.

Abstract: Differential and double-differential cross sections for the production of top quark pairs in proton-proton collisions at $\sqrt{s} = 13$\,TeV are measured as a function of kinematic variables of the top quarks and the top quark-antiquark ($\text{t}\bar{\text{t}}$) system. In addition, kinematic variables and multiplicities of jets associated with the $\text{t}\bar{\text{t}}$ production are measured. This analysis is based on data collected by the CMS experiment at the LHC in 2016 corresponding to an integrated luminosity of 35.8\,fb$^{-1}$. The measurements are performed in the lepton+jets decay channels with a single muon or electron and jets in the final state. The differential cross sections are presented at the particle level, within a phase space close to the experimental acceptance, and at the parton level in the full phase space. The results are compared to several standard model predictions that use different methods and approximations. The kinematic variables of the top quarks and the $\text{t}\bar{\text{t}}$ system are reasonably described in general, though none predict all the measured distributions. In particular, the transverse momentum distribution of the top quarks is more steeply falling than predicted. The kinematic distributions and multiplicities of jets are adequately modeled by certain combinations of next-to-leading-order calculations and parton shower models. Rivet: This analysis is to be run on $\text{t}\bar{\text{t}}$ Monte Carlo. The particle-level phase space is defined using the following definitions: \begin{description} \item[lepton]: an electron or muon with $p_\text{T}>30\,\text{GeV}$ and $|\eta|<2.4$, dressed within a cone of radius 0.1, \item[jet]: a jet is reconstructed with the anti-$k_\text{T}$ algorithm with a radius of 0.4, after removing the neutrinos and dressed leptons, with $p_\text{T]>25\,\text{GeV}$ and $|\eta|<2.4$, \item[b-jet]: a jet that contains a B-hadron. \end{description} A W boson is reconstructed from a lepton and the sum of the neutrino energies, while another W boson is reconstructed from a light jet pair. The two top quarks are reconstructed by combining b jets to these W boson. A check based on the W boson and top quark masses is performed to choose the proper combinations.

Source code: CMS_2018_I1663958.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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
#include "Rivet/Analysis.hh"
#include "Rivet/Projections/FinalState.hh"
#include "Rivet/Projections/VisibleFinalState.hh"
#include "Rivet/Projections/IdentifiedFinalState.hh"
#include "Rivet/Projections/VetoedFinalState.hh"
#include "Rivet/Projections/FastJets.hh"
#include "Rivet/Projections/DressedLeptons.hh"

namespace Rivet {


  class CMS_2018_I1663958 : public Analysis {
  public:

    struct Histo1DGroup {
      Histo1DGroup() {}
      Histo1DGroup(CMS_2018_I1663958* an, const vector<string>& hnames, const vector<double>& xbinranges);

      void fill(double x, double y, double w = 1.);
      void scale(double s, bool diff = true);
      void norm(bool diff = true);

      void gapfractionfromjetpt(Scatter2DPtr hgap, int njet);

      CMS_2018_I1663958* m_an;
      vector<double> m_xbins;
      vector<Histo1DPtr> m_histos;
    };


    CMS_2018_I1663958()
      : Analysis("CMS_2018_I1663958"),
        m_thad_decay(3), m_tlep_decay(3), m_tt_jets(4) {}


    virtual void init() {
      const FinalState fs(Cuts::abseta < 6.);
      declare(fs, "FS");
      const VisibleFinalState vfs(Cuts::abseta < 6.);
      declare(vfs, "vFS");

      VetoedFinalState invisibles(fs);
      invisibles.addVetoOnThisFinalState(vfs);
      declare(invisibles, "Invisibles");

      IdentifiedFinalState all_photons(vfs);
      all_photons.acceptId(PID::PHOTON);
      IdentifiedFinalState leptons(vfs);
      leptons.acceptIds({PID::ELECTRON, -PID::ELECTRON, PID::MUON,-PID::MUON});

      DressedLeptons dressed_leptons(all_photons, leptons, m_lepdressdr,
                                     Cuts::abseta < m_lepetamax && Cuts::pT > m_vetolepptmin*GeV, true);
      declare(dressed_leptons, "MyLeptons");

      VetoedFinalState photons(all_photons);
      photons.addVetoOnThisFinalState(dressed_leptons);
      declare(photons, "MyPhotons");

      VetoedFinalState isolationparticles(vfs);
      isolationparticles.addVetoOnThisFinalState(dressed_leptons);
      declare(isolationparticles, "IsoParticles");

      declare(FastJets(vfs, FastJets::ANTIKT, m_jetdr), "Jets");

      m_hist_thadpt = bookHisto1D("d01-x01-y01");
      m_hist_thady = bookHisto1D("d03-x01-y01");
      m_hist_tleppt = bookHisto1D("d05-x01-y01");
      m_hist_tlepy = bookHisto1D("d07-x01-y01");
      m_hist_ttm = bookHisto1D("d09-x01-y01");
      m_hist_ttpt = bookHisto1D("d11-x01-y01");
      m_hist_tty = bookHisto1D("d13-x01-y01");
      m_hist_njet = bookHisto1D("d15-x01-y01");
      /// @todo Memory leak
      m_hist_njet_ttm = new Histo1DGroup(this, {"d17-x01-y01", "d18-x01-y01", "d19-x01-y01", "d20-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5});
      m_hist_njet_thadpt = new Histo1DGroup(this, {"d22-x01-y01", "d23-x01-y01", "d24-x01-y01", "d25-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5});
      m_hist_njet_ttpt = new Histo1DGroup(this, {"d27-x01-y01", "d28-x01-y01", "d29-x01-y01", "d30-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5});
      m_hist_thady_thadpt = new Histo1DGroup(this, {"d32-x01-y01", "d33-x01-y01", "d34-x01-y01", "d35-x01-y01"}, {0.0,0.5, 1.0, 1.5, 2.5});
      m_hist_ttm_tty = new Histo1DGroup(this, {"d37-x01-y01", "d38-x01-y01", "d39-x01-y01", "d40-x01-y01"}, {300., 450., 625., 850., 2000.});
      m_hist_thadpt_ttm = new Histo1DGroup(this, {"d42-x01-y01", "d43-x01-y01", "d44-x01-y01", "d45-x01-y01"}, {0., 90., 180., 270., 800.});
      m_hist_jetspt = new Histo1DGroup(this, {"d47-x01-y01", "d48-x01-y01", "d49-x01-y01", "d50-x01-y01", "d51-x01-y01", "d52-x01-y01", "d53-x01-y01", "d54-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5});
      m_hist_jetseta = new Histo1DGroup(this, {"d56-x01-y01", "d57-x01-y01", "d58-x01-y01", "d59-x01-y01", "d60-x01-y01", "d61-x01-y01", "d62-x01-y01", "d63-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5});
      m_hist_jetsdrjets = new Histo1DGroup(this, {"d65-x01-y01", "d66-x01-y01", "d67-x01-y01", "d68-x01-y01", "d69-x01-y01", "d70-x01-y01", "d71-x01-y01", "d72-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5});
      m_hist_jetsdrtops = new Histo1DGroup(this, {"d74-x01-y01", "d75-x01-y01", "d76-x01-y01", "d77-x01-y01", "d78-x01-y01", "d79-x01-y01", "d80-x01-y01", "d81-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5});
      m_hist_njetspt = new Histo1DGroup(this, {"d169-x01-y01", "d170-x01-y01", "d171-x01-y01", "d172-x01-y01"}, {0., 40., 60., 80., 120.});

      m_nhist_thadpt = bookHisto1D("d83-x01-y01");
      m_nhist_thady = bookHisto1D("d85-x01-y01");
      m_nhist_tleppt = bookHisto1D("d87-x01-y01");
      m_nhist_tlepy = bookHisto1D("d89-x01-y01");
      m_nhist_ttm = bookHisto1D("d91-x01-y01");
      m_nhist_ttpt = bookHisto1D("d93-x01-y01");
      m_nhist_tty = bookHisto1D("d95-x01-y01");
      m_nhist_njet = bookHisto1D("d97-x01-y01");
      /// @todo Memory leak
      m_nhist_njet_ttm = new Histo1DGroup(this, {"d99-x01-y01", "d100-x01-y01", "d101-x01-y01", "d102-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5});
      m_nhist_njet_thadpt = new Histo1DGroup(this, {"d104-x01-y01", "d105-x01-y01", "d106-x01-y01", "d107-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5});
      m_nhist_njet_ttpt = new Histo1DGroup(this, {"d109-x01-y01", "d110-x01-y01", "d111-x01-y01", "d112-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5});
      m_nhist_thady_thadpt = new Histo1DGroup(this, {"d114-x01-y01", "d115-x01-y01", "d116-x01-y01", "d117-x01-y01"}, {0.0,0.5, 1.0, 1.5, 2.5});
      m_nhist_ttm_tty = new Histo1DGroup(this, {"d119-x01-y01", "d120-x01-y01", "d121-x01-y01", "d122-x01-y01"}, {300., 450., 625., 850., 2000.});
      m_nhist_thadpt_ttm = new Histo1DGroup(this, {"d124-x01-y01", "d125-x01-y01", "d126-x01-y01", "d127-x01-y01"}, {0., 90., 180., 270., 800.});
      m_nhist_jetspt = new Histo1DGroup(this, {"d129-x01-y01", "d130-x01-y01", "d131-x01-y01", "d132-x01-y01", "d133-x01-y01", "d134-x01-y01", "d135-x01-y01", "d136-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5});
      m_nhist_jetseta = new Histo1DGroup(this, {"d138-x01-y01", "d139-x01-y01", "d140-x01-y01", "d141-x01-y01", "d142-x01-y01", "d143-x01-y01", "d144-x01-y01", "d145-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5});
      m_nhist_jetsdrjets = new Histo1DGroup(this, {"d147-x01-y01", "d148-x01-y01", "d149-x01-y01", "d150-x01-y01", "d151-x01-y01", "d152-x01-y01", "d153-x01-y01", "d154-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5});
      m_nhist_jetsdrtops = new Histo1DGroup(this, {"d156-x01-y01", "d157-x01-y01", "d158-x01-y01", "d159-x01-y01", "d160-x01-y01", "d161-x01-y01", "d162-x01-y01", "d163-x01-y01"}, {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5});
      m_hist_gap1 = bookScatter2D("d165-x01-y01");
      m_hist_gap2 = bookScatter2D("d167-x01-y01");
    }


    void analyze(const Event& event) {
      const double weight = event.weight();
      m_leptons.clear();
      m_vetoleptons.clear();
      m_neutrinos.clear();
      m_bjets.clear();
      m_ljets.clear();
      m_additionalobjects.clear();
      m_additionaljets.clear();

      const Particles& isopars = applyProjection<VetoedFinalState>(event, "IsoParticles").particles();
      const vector<DressedLepton>& dressedleptons = applyProjection<DressedLeptons>(event, "MyLeptons").dressedLeptons();
      for (const DressedLepton& lep : dressedleptons) {
        double isolation = accumulate(isopars.begin(), isopars.end(), 0., [&](double iso, const Particle& par) {if(deltaR(lep, par) < m_lepisodr){return iso + par.pt();} else {return iso;}});
        isolation = isolation/lep.pt();
        if (isolation > m_lepisomax) continue;
        if (lep.pt() > m_lepptmin && lep.abseta() < m_lepetamax) m_leptons.push_back(lep);
        else if(lep.pt() > m_vetolepptmin && lep.abseta() < m_vetolepetamax) m_vetoleptons.push_back(lep);
      }

      const Particles& photons = applyProjection<VetoedFinalState>(event, "MyPhotons").particles(Cuts::abseta < m_phetamax && Cuts::pT > m_phptmin*GeV);
      for (const Particle& ph : photons) {
        double isolation = accumulate(isopars.begin(), isopars.end(), 0., [&](double iso, const Particle& par) {if(deltaR(ph, par) < m_phisodr){return iso + par.pt();} else {return iso;}});
        isolation = isolation/ph.pt() - 1.;
        if (isolation > m_phisomax) continue;
        m_additionalobjects.push_back(ph);
      }

      const Particles& invfspars = apply<FinalState>(event, "Invisibles").particles();
      for (const Particle& par : invfspars) m_neutrinos.push_back(par);

      const Jets& allJets = apply<FastJets>(event, "Jets").jetsByPt(Cuts::abseta < m_jetetamax && Cuts::pT > m_jetptmin*GeV);
      for (const Jet& jet : allJets) {
        //clean jets from leptons
        if (find_if(m_leptons.begin(), m_leptons.end(),
                    [&](const Particle& par){return deltaR(jet, par) < m_jetdr;}) != m_leptons.end()) continue;
        //clean jets from veto leptons
        if (find_if(m_vetoleptons.begin(), m_vetoleptons.end(),
                    [&](const Particle& par){return deltaR(jet, par) < m_jetdr;}) != m_vetoleptons.end()) continue;
        //clean other objects (photons)
        if (find_if(m_additionalobjects.begin(), m_additionalobjects.end(),
                    [&](const Particle& par){return deltaR(jet, par) < m_jetdr;}) != m_additionalobjects.end()) continue;

        if (jet.bTagged()) {
          m_bjets.push_back(jet);
        } else {
          m_ljets.push_back(jet);
        }
      }

      //Semi-leptonic reconstruction
      if (m_leptons.size() != 1 || m_vetoleptons.size() != 0 || m_bjets.size() < 2 || m_ljets.size() < 2) return;

      FourMomentum nusum = accumulate(m_neutrinos.begin(), m_neutrinos.end(), FourMomentum(0.,0.,0.,0.),
                                      [&](FourMomentum& invmom, const Particle& par) {return invmom += par.momentum();});

      FourMomentum wl = nusum + m_leptons[0].momentum();

      double Kmin = numeric_limits<double>::max();
      for (size_t a = 0 ; a <  m_ljets.size() ; ++a){
        const Jet& lja = m_ljets[a];
        for (size_t b = 0 ; b < a ; ++b) {
          const Jet& ljb = m_ljets[b];
          FourMomentum wh(lja.momentum() + ljb.momentum());
          for (const Jet& bjh : m_bjets) {
            FourMomentum th(wh + bjh.momentum());
            for (const Jet& bjl : m_bjets) {
              if (&bjh == &bjl) continue;
              FourMomentum tl(wl + bjl.momentum());

              double K = pow(wh.mass() - 80.4, 2) + pow(th.mass() - 172.5, 2) + pow(tl.mass() - 172.5, 2);
              if (K < Kmin)
              {
                Kmin = K;
                m_thad = Particle(6, th);
                m_thad_decay[0] = Particle(5, bjh);
                m_thad_decay[1] = lja.pt() > ljb.pt() ? Particle(1, lja) : Particle(1, ljb);
                m_thad_decay[2] = lja.pt() <= ljb.pt() ? Particle(1, lja) : Particle(1, ljb);
                m_tlep = Particle(-6, tl);
                m_tlep_decay[0] = Particle(5, bjl);
                m_tlep_decay[1] = m_leptons[0];
                m_tlep_decay[2] = Particle(-1*(m_leptons[0].pdgId()+1), nusum);
              }
            }
          }
        }
      }

      m_tt_jets[0] = m_tlep_decay[0];
      m_tt_jets[1] = m_thad_decay[0];
      m_tt_jets[2] = m_thad_decay[1];
      m_tt_jets[3] = m_thad_decay[2];

      const double eps = 1E-5;
      for (const Jet& jet : m_bjets) {
        if(jet.pt() < m_addjetptmin || jet.abseta() > m_addjetetamax) continue;
        if(find_if(m_tt_jets.begin(), m_tt_jets.end(), [&](const Particle& par){return deltaR(jet, par) < eps;}) != m_tt_jets.end()) continue;
        m_additionaljets.push_back(Particle(5, jet.momentum()));
      }
      for (const Jet& jet : m_ljets) {
        if(jet.pt() < m_addjetptmin || jet.abseta() > m_addjetetamax) continue;
        if(find_if(m_tt_jets.begin(), m_tt_jets.end(), [&](const Particle& par){return deltaR(jet, par) < eps;}) != m_tt_jets.end()) continue;
        if(jet.cTagged())
        {
          m_additionaljets.push_back(Particle(4, jet.momentum()));
        }
        else
        {
          m_additionaljets.push_back(Particle(1, jet.momentum()));
        }
      }

      sort(m_additionaljets.begin(), m_additionaljets.end(), [](const Particle& ja, const Particle& jb) {return ja.pt() > jb.pt();});

      FourMomentum tt(m_thad.momentum() + m_tlep.momentum());

      m_hist_thadpt->fill(m_thad.pt(), weight);
      m_nhist_thadpt->fill(m_thad.pt(), weight);
      m_hist_thady->fill(abs(m_thad.rapidity()), weight);
      m_nhist_thady->fill(abs(m_thad.rapidity()), weight);
      m_hist_tleppt->fill(m_tlep.pt(), weight);
      m_nhist_tleppt->fill(m_tlep.pt(), weight);
      m_hist_tlepy->fill(abs(m_tlep.rapidity()), weight);
      m_nhist_tlepy->fill(abs(m_tlep.rapidity()), weight);
      m_hist_ttm->fill(tt.mass(), weight);
      m_nhist_ttm->fill(tt.mass(), weight);
      m_hist_ttpt->fill(tt.pt(), weight);
      m_nhist_ttpt->fill(tt.pt(), weight);
      m_hist_tty->fill(abs(tt.rapidity()), weight);
      m_nhist_tty->fill(abs(tt.rapidity()), weight);
      m_hist_njet->fill(min(m_additionaljets.size(), (size_t)5), weight);
      m_nhist_njet->fill(min(m_additionaljets.size(), (size_t)5), weight);
      int njet = min((size_t)3, m_additionaljets.size());
      m_hist_njet_ttm->fill(njet, tt.mass(), weight);
      m_nhist_njet_ttm->fill(njet, tt.mass(), weight);
      m_hist_njet_thadpt->fill(njet, m_thad.pt(), weight);
      m_nhist_njet_thadpt->fill(njet, m_thad.pt(), weight);
      m_hist_njet_ttpt->fill(njet, tt.pt(), weight);
      m_nhist_njet_ttpt->fill(njet, tt.pt(), weight);
      m_hist_thady_thadpt->fill(abs(m_thad.rapidity()), m_thad.pt(), weight);
      m_nhist_thady_thadpt->fill(abs(m_thad.rapidity()), m_thad.pt(), weight);
      m_hist_ttm_tty->fill(tt.mass(), abs(tt.rapidity()), weight);
      m_nhist_ttm_tty->fill(tt.mass(), abs(tt.rapidity()), weight);
      m_hist_thadpt_ttm->fill(m_thad.pt(), tt.mass(), weight);
      m_nhist_thadpt_ttm->fill(m_thad.pt(), tt.mass(), weight);
      int jpos = -1;
      for (const Particles& jets : {m_tt_jets, m_additionaljets}) {
        for (const Particle& jet : jets) {
          jpos++;
          m_hist_jetspt->fill(jpos, jet.pt(), weight);
          m_nhist_jetspt->fill(jpos, jet.pt(), weight);
          m_hist_jetseta->fill(jpos, abs(jet.eta()), weight);
          m_nhist_jetseta->fill(jpos, abs(jet.eta()), weight);
          double drmin = 1E10;
          for (const Particle& tjet : m_tt_jets) {
            double dr = deltaR(jet, tjet);
            if(dr > eps && dr < drmin)
            {
              drmin = dr;
            }
          }
          m_hist_jetsdrjets->fill(jpos, drmin, weight);
          m_nhist_jetsdrjets->fill(jpos, drmin, weight);
          m_hist_jetsdrtops->fill(jpos, min(deltaR(jet, m_thad), deltaR(jet, m_tlep)), weight);
          m_nhist_jetsdrtops->fill(jpos, min(deltaR(jet, m_thad), deltaR(jet, m_tlep)), weight);
        }
      }
      for (double ptcut : {30, 50, 75, 100}) {
        m_hist_njetspt->fill(ptcut , count_if(m_additionaljets.begin(), m_additionaljets.end(),
                                              [&ptcut](const Particle& j) {return j.pt() > ptcut;}), weight);
      }
    }


    virtual void finalize()
    {
      m_hist_jetspt->gapfractionfromjetpt(m_hist_gap1, 1);
      m_hist_jetspt->gapfractionfromjetpt(m_hist_gap2, 2);
      scale(m_hist_thadpt, crossSection()/sumOfWeights());
      scale(m_hist_thady, crossSection()/sumOfWeights());
      scale(m_hist_tleppt, crossSection()/sumOfWeights());
      scale(m_hist_tlepy, crossSection()/sumOfWeights());
      scale(m_hist_ttpt, crossSection()/sumOfWeights());
      scale(m_hist_tty, crossSection()/sumOfWeights());
      scale(m_hist_ttm, crossSection()/sumOfWeights());
      scale(m_hist_njet, crossSection()/sumOfWeights());
      m_hist_njet_ttm->scale(crossSection()/sumOfWeights(), false);
      m_hist_njet_thadpt->scale(crossSection()/sumOfWeights(), false);
      m_hist_njet_ttpt->scale(crossSection()/sumOfWeights(), false);
      m_hist_thady_thadpt->scale(crossSection()/sumOfWeights());
      m_hist_ttm_tty->scale(crossSection()/sumOfWeights());
      m_hist_thadpt_ttm->scale(crossSection()/sumOfWeights());
      m_hist_jetspt->scale(crossSection()/sumOfWeights(), false);
      m_hist_jetseta->scale(crossSection()/sumOfWeights(), false);
      m_hist_jetsdrjets->scale(crossSection()/sumOfWeights(), false);
      m_hist_jetsdrtops->scale(crossSection()/sumOfWeights(), false);
      m_hist_njetspt->scale(crossSection()/sumOfWeights(), false);


      scale(m_nhist_thadpt, 1./m_nhist_thadpt->sumW(false));
      scale(m_nhist_thady, 1./m_nhist_thady->sumW(false));
      scale(m_nhist_tleppt, 1./m_nhist_tleppt->sumW(false));
      scale(m_nhist_tlepy, 1./m_nhist_tlepy->sumW(false));
      scale(m_nhist_ttpt, 1./m_nhist_ttpt->sumW(false));
      scale(m_nhist_tty, 1./m_nhist_tty->sumW(false));
      scale(m_nhist_ttm, 1./m_nhist_ttm->sumW(false));
      scale(m_nhist_njet, 1./m_nhist_njet->sumW(false));
      m_nhist_njet_ttm->norm(false);
      m_nhist_njet_thadpt->norm(false);
      m_nhist_njet_ttpt->norm(false);
      m_nhist_thady_thadpt->norm(true);
      m_nhist_ttm_tty->norm(true);
      m_nhist_thadpt_ttm->norm(true);
      m_nhist_jetspt->norm(false);
      m_nhist_jetseta->norm(false);
      m_nhist_jetsdrjets->norm(false);
      m_nhist_jetsdrtops->norm(false);

    }


    Histo1DPtr m_hist_thadpt;
    Histo1DPtr m_hist_thady;
    Histo1DPtr m_hist_tleppt;
    Histo1DPtr m_hist_tlepy;
    Histo1DPtr m_hist_ttpt;
    Histo1DPtr m_hist_tty;
    Histo1DPtr m_hist_ttm;
    Histo1DPtr m_hist_njet;
    Histo1DGroup* m_hist_njet_ttm;
    Histo1DGroup* m_hist_njet_thadpt;
    Histo1DGroup* m_hist_njet_ttpt;
    Histo1DGroup* m_hist_thady_thadpt;
    Histo1DGroup* m_hist_ttm_tty;
    Histo1DGroup* m_hist_thadpt_ttm;
    Histo1DGroup* m_hist_jetspt;
    Histo1DGroup* m_hist_jetseta;
    Histo1DGroup* m_hist_jetsdrjets;
    Histo1DGroup* m_hist_jetsdrtops;
    Histo1DGroup* m_hist_njetspt;

    Histo1DPtr m_nhist_thadpt;
    Histo1DPtr m_nhist_thady;
    Histo1DPtr m_nhist_tleppt;
    Histo1DPtr m_nhist_tlepy;
    Histo1DPtr m_nhist_ttm;
    Histo1DPtr m_nhist_ttpt;
    Histo1DPtr m_nhist_tty;
    Histo1DPtr m_nhist_njet;
    Histo1DGroup* m_nhist_njet_ttm;
    Histo1DGroup* m_nhist_njet_thadpt;
    Histo1DGroup* m_nhist_njet_ttpt;
    Histo1DGroup* m_nhist_thady_thadpt;
    Histo1DGroup* m_nhist_ttm_tty;
    Histo1DGroup* m_nhist_thadpt_ttm;
    Histo1DGroup* m_nhist_jetspt;
    Histo1DGroup* m_nhist_jetseta;
    Histo1DGroup* m_nhist_jetsdrjets;
    Histo1DGroup* m_nhist_jetsdrtops;
    Scatter2DPtr m_hist_gap1;
    Scatter2DPtr m_hist_gap2;

    Particles m_neutrinos;
    Particles m_leptons;
    Particles m_vetoleptons;
    Jets m_bjets;
    Jets m_ljets;

    Particle m_thad;
    Particles m_thad_decay;
    Particle m_tlep;
    Particles m_tlep_decay;
    Particles m_tt_jets;
    Particles m_additionalobjects;
    Particles m_additionaljets;

    double m_jetptmin = 25.;
    double m_jetetamax = 2.4;
    double m_addjetptmin = 30.;
    double m_addjetetamax = 2.4;
    double m_jetdr = 0.4;
    double m_lepptmin = 30.;
    double m_lepetamax = 2.4;
    double m_vetolepptmin = 15.;
    double m_vetolepetamax = 2.4;
    double m_lepisomax = 0.35;
    double m_lepisodr = 0.4;
    double m_lepdressdr = 0.1;
    double m_phptmin = 15.;
    double m_phetamax = 2.4;
    double m_phisomax = 0.25;
    double m_phisodr = 0.4;

  };


  DECLARE_RIVET_PLUGIN(CMS_2018_I1663958);


  CMS_2018_I1663958::Histo1DGroup::Histo1DGroup(CMS_2018_I1663958* an, const vector<string>& hnames, const vector<double>& xbinranges) : m_an(an), m_xbins(xbinranges) {
    for (const string& hname : hnames) {
      m_histos.push_back(an->bookHisto1D(hname));
    }
  }

  void CMS_2018_I1663958::Histo1DGroup::fill(double x, double y, double w) {
    if (x < m_xbins[0]) {return;}
    if (x >= m_xbins[m_xbins.size()-1]) {return;}
    int xbin = upper_bound(m_xbins.begin(), m_xbins.end(), x) - m_xbins.begin()-1;
    m_histos[xbin]->fill(y, w);
  }

  void CMS_2018_I1663958::Histo1DGroup::scale(double s, bool diff) {
    for (size_t h = 0 ; h < m_histos.size() ; ++h) {
      double sc = s;
      if (diff) {sc /= m_xbins[h+1]-m_xbins[h];}
      m_an->scale(m_histos[h], sc);
    }
  }

  void CMS_2018_I1663958::Histo1DGroup::norm(bool diff) {
    double sum = 0.;
    for (Histo1DPtr hist : m_histos) {sum+=hist->sumW(false);}
    scale(1./sum, diff);
  }

  void CMS_2018_I1663958::Histo1DGroup::gapfractionfromjetpt(Scatter2DPtr hgap, int njet) {
    double total = m_histos[0]->integral();
    int hn = njet+3;
    double totalj = m_histos[hn]->integral();
    double acc = total-totalj;
    for (size_t nb = 0 ; nb < m_histos[hn]->numBins() ; ++nb) {
      double gf = acc/total;
      double bl = m_histos[njet+3]->bin(nb).xMin();
      double bh = m_histos[njet+3]->bin(nb).xMax();
      double bc = 0.5*(bh+bl);
      hgap->addPoint(bc, gf, bc-bl, bh-bc, 0., 0.);
      acc += m_histos[njet+3]->bin(nb).area();
    }

  }

}