StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
main04.cc
1 // main04.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2012 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 is a simple test program.
7 // It illustrates how to generate and study "total cross section" processes,
8 // i.e. elastic, single and double diffractive, and the "minimum-bias" rest.
9 // All input is specified in the main06.cmnd file.
10 // Note that the "total" cross section does NOT include
11 // the Coulomb contribution to elastic scattering, as switched on here.
12 
13 #include "Pythia.h"
14 
15 using namespace Pythia8;
16 
17 //==========================================================================
18 
19 int main() {
20 
21  // Generator. Shorthand for the event.
22  Pythia pythia;
23  Event& event = pythia.event;
24 
25  // Read in commands from external file.
26  pythia.readFile("main04.cmnd");
27 
28  // Extract settings to be used in the main program.
29  int nEvent = pythia.mode("Main:numberOfEvents");
30  int nAbort = pythia.mode("Main:timesAllowErrors");
31 
32  // Initialize.
33  pythia.init();
34 
35  // Book histograms: multiplicities and mean transverse momenta.
36  Hist nChg("number of charged particles; all", 100, -0.5, 799.5);
37  Hist nChgSD("number of charged particles; single diffraction",
38  100, -0.5, 799.5);
39  Hist nChgDD("number of charged particles, double diffractive",
40  100, -0.5, 799.5);
41  Hist nChgND("number of charged particles, non-diffractive",
42  100, -0.5, 799.5);
43  Hist pTnChg("<pt>(n_charged) all", 100, -0.5, 799.5);
44  Hist pTnChgSD("<pt>(n_charged) single diffraction", 100, -0.5, 799.5);
45  Hist pTnChgDD("<pt>(n_charged) double diffraction", 100, -0.5, 799.5);
46  Hist pTnChgND("<pt>(n_charged) non-diffractive ", 100, -0.5, 799.5);
47 
48  // Book histograms: ditto as function of separate subsystem mass.
49  Hist mLogInel("log10(mass), by diffractive system", 100, 0., 5.);
50  Hist nChgmLog("<n_charged>(log10(mass))", 100, 0., 5.);
51  Hist pTmLog("<pT>_charged>(log10(mass))", 100, 0., 5.);
52 
53  // Book histograms: elastic/diffractive.
54  Hist tSpecEl("elastic |t| spectrum", 100, 0., 1.);
55  Hist tSpecElLog("elastic log10(|t|) spectrum", 100, -5., 0.);
56  Hist tSpecSD("single diffractive |t| spectrum", 100, 0., 2.);
57  Hist tSpecDD("double diffractive |t| spectrum", 100, 0., 5.);
58  Hist mSpec("diffractive mass spectrum", 100, 0., 100.);
59  Hist mLogSpec("log10(diffractive mass spectrum)", 100, 0., 4.);
60 
61  // Book histograms: inelastic nondiffractive "minbias".
62  double pTmax = 20.;
63  double bMax = 4.;
64  Hist pTspec("total pT_hard spectrum", 100, 0., pTmax);
65  Hist pTspecND("nondiffractive pT_hard spectrum", 100, 0., pTmax);
66  Hist bSpec("b impact parameter spectrum", 100, 0., bMax);
67  Hist enhanceSpec("b enhancement spectrum", 100, 0., 10.);
68  Hist number("number of interactions", 100, -0.5, 99.5);
69  Hist pTb1("pT spectrum for b < 0.5", 100, 0., pTmax);
70  Hist pTb2("pT spectrum for 0.5 < b < 1", 100, 0., pTmax);
71  Hist pTb3("pT spectrum for 1 < b < 1.5", 100, 0., pTmax);
72  Hist pTb4("pT spectrum for 1.5 < b", 100, 0., pTmax);
73  Hist bpT1("b spectrum for pT < 2", 100, 0., bMax);
74  Hist bpT2("b spectrum for 2 < pT < 5", 100, 0., bMax);
75  Hist bpT3("b spectrum for 5 < pT < 15", 100, 0., bMax);
76  Hist bpT4("b spectrum for 15 < pT", 100, 0., bMax);
77 
78  // Begin event loop.
79  int iAbort = 0;
80  for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
81 
82  // Generate events. Quit if too many failures.
83  if (!pythia.next()) {
84  if (++iAbort < nAbort) continue;
85  cout << " Event generation aborted prematurely, owing to error!\n";
86  break;
87  }
88 
89  // Extract event classification.
90  int code = pythia.info.code();
91 
92  // Charged multiplicity and mean pT: all and by event class.
93  int nch = 0;
94  double pTsum = 0.;
95  for (int i = 1; i < event.size(); ++i)
96  if (event[i].isFinal() && event[i].isCharged()) {
97  ++nch;
98  pTsum += event[i].pT();
99  }
100  nChg.fill( nch );
101  if (nch > 0) pTnChg.fill( nch, pTsum/nch);
102  if (code == 103 || code == 104) {
103  nChgSD.fill( nch );
104  if (nch > 0) pTnChgSD.fill( nch, pTsum/nch);
105  } else if (code == 105) {
106  nChgDD.fill( nch );
107  if (nch > 0) pTnChgDD.fill( nch, pTsum/nch);
108  } else if (code == 101) {
109  nChgND.fill( nch );
110  if (nch > 0) pTnChgND.fill( nch, pTsum/nch);
111  double mLog = log10( event[0].m() );
112  mLogInel.fill( mLog );
113  nChgmLog.fill( mLog, nch );
114  if (nch > 0) pTmLog.fill( mLog, pTsum / nch );
115  }
116 
117  // Charged multiplicity and mean pT: per diffractive system.
118  for (int iDiff = 0; iDiff < 2; ++iDiff)
119  if ( (iDiff == 0 && pythia.info.isDiffractiveA())
120  || (iDiff == 1 && pythia.info.isDiffractiveB()) ) {
121  int ndiff = 0;
122  double pTdiff = 0.;
123  for (int i = 5; i < event.size(); ++i)
124  if (event[i].isFinal() && event[i].isCharged()) {
125  // Trace back final particle to see which system it comes from.
126  int k = i;
127  do k = event[k].mother1();
128  while (k > 4);
129  if (k == iDiff + 3) {
130  ++ndiff;
131  pTdiff += event[i].pT();
132  }
133  }
134  double mLog = log10(event[iDiff+3].m() );
135  mLogInel.fill( mLog );
136  nChgmLog.fill( mLog, ndiff );
137  if (ndiff > 0) pTmLog.fill( mLog, pTdiff / ndiff );
138  }
139 
140  // Study pT spectrum of all hard collisions, no distinction.
141  double pT = pythia.info.pTHat();
142  pTspec.fill( pT );
143 
144  // Study t distribution of elastic/diffractive events.
145  if (code > 101) {
146  double tAbs = abs(pythia.info.tHat());
147  if (code == 102) {
148  tSpecEl.fill(tAbs);
149  tSpecElLog.fill(log10(tAbs));
150  }
151  else if (code == 103 || code == 104) tSpecSD.fill(tAbs);
152  else if (code == 105) tSpecDD.fill(tAbs);
153 
154  // Study diffractive mass spectrum.
155  if (pythia.info.isDiffractiveA()) {
156  mSpec.fill( event[3].m() );
157  mLogSpec.fill( log10(event[3].m()) );
158  }
159  if (pythia.info.isDiffractiveB()) {
160  mSpec.fill( event[4].m() );
161  mLogSpec.fill( log10(event[4].m()) );
162  }
163 
164  // Study nondiffractive inelastic events in (pT, b) space.
165  } else {
166  double b = pythia.info.bMPI();
167  double enhance = pythia.info.enhanceMPI();
168  int nMPI = pythia.info.nMPI();
169  pTspecND.fill( pT );
170  bSpec.fill( b );
171  enhanceSpec.fill( enhance );
172  number.fill( nMPI );
173  if (b < 0.5) pTb1.fill( pT );
174  else if (b < 1.0) pTb2.fill( pT );
175  else if (b < 1.5) pTb3.fill( pT );
176  else pTb4.fill( pT );
177  if (pT < 2.) bpT1.fill( b );
178  else if (pT < 5.) bpT2.fill( b );
179  else if (pT < 15.) bpT3.fill( b );
180  else bpT4.fill( b );
181  }
182 
183  // End of event loop.
184  }
185 
186  // Final statistics and histograms.
187  pythia.stat();
188  pTnChg /= nChg;
189  pTnChgSD /= nChgSD;
190  pTnChgDD /= nChgDD;
191  pTnChgND /= nChgND;
192  nChgmLog /= mLogInel;
193  pTmLog /= mLogInel;
194  cout << nChg << nChgSD << nChgDD << nChgND
195  << pTnChg << pTnChgSD << pTnChgDD << pTnChgND
196  << mLogInel << nChgmLog << pTmLog
197  << tSpecEl << tSpecElLog << tSpecSD << tSpecDD << mSpec << mLogSpec
198  << pTspec << pTspecND << bSpec << enhanceSpec << number
199  << pTb1 << pTb2 << pTb3 << pTb4 << bpT1 << bpT2 << bpT3 << bpT4;
200 
201  // Done.
202  return 0;
203 }