StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
main80.cc
1 // main80.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2014 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL version 2, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
5 
6 // This program is written by Stefan Prestel.
7 // It illustrates how to do CKKW-L merging,
8 // see the Matrix Element Merging page in the online manual.
9 
10 #include "Pythia8/Pythia.h"
11 
12 using namespace Pythia8;
13 
14 int main() {
15 
16  // Generator. Input parameters.
17  Pythia pythia;
18  pythia.readFile("main80.cmnd");
19 
20  // Extract number of events and max number of jets in merging.
21  int nEvent = pythia.mode("Main:numberOfEvents");
22  int nMerge = pythia.mode("Merging:nJetMax");
23 
24  // Histograms combined over all jet multiplicities.
25  Hist pTWsum("pT of W, summed over all subruns", 100, 0., 200.);
26 
27  // Merged total cross section, summed over subruns.
28  double sigmaTotal = 0.;
29 
30  // Loop over subruns with varying number of jets.
31  for (int iMerge = 0; iMerge <= nMerge; ++iMerge) {
32  double sigmaSample = 0.;
33 
34  // Read in name of LHE file for current subrun and initialize.
35  pythia.readFile("main80.cmnd", iMerge);
36  pythia.init();
37 
38  // Histograms for current jet multiplicity.
39  Hist weightNow("event weights, current subrun", 100, 0., 2.5);
40  Hist pTWnow("pT of W, current subrun", 100, 0., 200.);
41 
42  // Start event generation loop.
43  for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
44 
45  // Generate next event. Break out of event loop if at end of LHE file.
46  if ( !pythia.next() ) {
47  if ( pythia.info.atEndOfFile() ) break;
48  else continue;
49  }
50 
51  // Get CKKWL weight of current event. Histogram and accumulate it.
52  double weight = pythia.info.mergingWeight();
53  weightNow.fill( weight);
54  sigmaSample += weight;
55 
56  // Find the final copy of the W+, which is after the full shower.
57  int iW = 0;
58  for (int i = 1; i < pythia.event.size(); ++i)
59  if (pythia.event[i].id() == 24) iW = i;
60 
61  // Fill the pT of the W histogram, with CKKWL weight.
62  double pTW = pythia.event[iW].pT();
63  pTWnow.fill( pTW, weight);
64 
65  // End of event loop.
66  }
67 
68  // Normalize pTW histogram, convert mb -> pb, and correct for bin width.
69  pTWnow *= 1e9 * pythia.info.sigmaGen() / (2. * pythia.info.nAccepted());
70 
71  // Print cross section and histograms for current subrun.
72  pythia.stat();
73  cout << weightNow << pTWnow;
74 
75  // Sum up merged cross section of current run.
76  sigmaSample *= pythia.info.sigmaGen() / double(pythia.info.nAccepted());
77  sigmaTotal += sigmaSample;
78 
79  // Add current histogram to the combined one. End of subrun loop.
80  pTWsum += pTWnow;
81  }
82 
83  // Print final histograms and info on merged cross section..
84  cout << pTWsum;
85  cout << "\n\n The inclusive cross section after merging is: "
86  << scientific << setprecision(4) << sigmaTotal << " mb " << endl;
87 
88  // Done
89  return 0;
90 
91 }