1 // main15.cc is a part of the PYTHIA event generator.
2 // Copyright (C) 2010 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.
6 // This is a simple test program.
7 // It illustrates how either
8 // (a) B decays (sections marked "Repeated decays:), or
9 // (b) all hadronization (sections marked "Repeated hadronization:")
10 // could be repeated a number of times for each event,
11 // to improve statistics when this could be a problem.
12 // Option (a) is faster than (b), but less generic.
15 using namespace Pythia8;
19 // Main switchs: redo B decays only or redo all hadronization, but not both.
20 bool redoBDecays = false;
21 bool redoHadrons = true;
22 if (redoHadrons) redoBDecays = false;
24 // Number of events, generated and listed ones.
28 // Number of times decays/hadronization should be redone for each event.
30 if (!redoBDecays && !redoHadrons) nRepeat = 1;
32 // Generator. Shorthand for event.
34 Event& event = pythia.event;
36 // Simulate b production above given pTmin scale.
37 // Warning: these processes do not catch all possible production modes.
38 // You would need to use HardQCD:all or even SoftQCD:minBias for that.
39 pythia.readString("HardQCD:gg2bbbar = on");
40 pythia.readString("HardQCD:qqbar2bbbar = on");
41 pythia.readString("PhaseSpace:pTHatMin = 50.");
43 // Repeated decays: list of weakly decaying B hadrons.
44 // Note: this list is overkill; some will never be produced.
45 int bCodes[28] = {511, 521, 531, 541, 5122, 5132, 5142, 5232, 5242,
46 5332, 5342, 5412, 5414, 5422, 5424, 5432, 5434, 5442, 5444, 5512,
47 5514, 5522, 5524, 5532, 5534, 5542, 5544, 5544 };
50 // Repeated decays: location of B handrons.
54 // Repeated hadronization: spare copy of event.
57 // Repeated hadronization: switch off normal HadronLevel call.
58 if (redoHadrons) pythia.readString("HadronLevel:all = off");
60 // Initialize for LHC energies.
61 pythia.init( 2212, 2212, 14000.);
63 // Show changed settings and particleData.
64 pythia.settings.listChanged();
65 pythia.particleData.listChanged();
67 // Histogram invariant mass of muon pairs.
68 Hist nBperEvent("number of b quarks in an event", 10, -0.5, 9.5);
69 Hist nSameEvent("number of times same event is used", 10, -0.5, 9.5);
70 Hist oppSignMass("mass of opposite-sign muon pair", 100, 0.0, 100.0);
71 Hist sameSignMass("mass of same-sign muon pair", 100, 0.0, 100.0);
74 for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
76 // Repeated decays: switch off decays of weakly decaying B hadrons.
77 // (More compact solution than repeated readString(..).)
78 if (redoBDecays) for (int iC = 0; iC < nCodes; ++iC)
79 pythia.particleData.mayDecay( bCodes[iC], false);
81 // Generate event. Skip it if error.
82 if (!pythia.next()) continue;
84 // List first few events.
87 pythia.process.list();
91 // Find and histogram number of b quarks.
94 for (int i = 0; i < event.size(); ++i) {
95 stat = event[i].statusAbs();
96 if (event[i].idAbs() == 5 && (stat == 62 || stat == 63)) ++nBquark;
98 nBperEvent.fill( nBquark );
100 // Repeated decays: find all locations where B hadrons are stored.
103 for (int i = 0; i < event.size(); ++i) {
104 int idAbs = event[i].idAbs();
105 for (int iC = 0; iC < 28; ++iC)
106 if (idAbs == bCodes[iC]) {
112 // Repeated decays: check that #b = #B.
113 nBHad = iBHad.size();
114 if (nBquark != nBHad) cout << " Warning: " << nBquark
115 << " b quarks but " << nBHad << " B hadrons" << endl;
117 // Repeated decays: store size of current event.
120 // Repeated decays: switch back on weakly decaying B hadrons.
121 for (int iC = 0; iC < nCodes; ++iC)
122 pythia.particleData.mayDecay( bCodes[iC], true);
124 // Repeated hadronization: copy event into spare position.
125 } else if (redoHadrons) {
129 // Begin loop over rounds of decays / hadronization for same event.
131 for (int iRepeat = 0; iRepeat < nRepeat; ++iRepeat) {
133 // Repeated decays: remove B decay products from previous round.
138 // Repeated decays: mark decayed B hadrons as undecayed.
139 for (int iB = 0; iB < nBHad; ++iB) event[ iBHad[iB] ].statusPos();
142 // Repeated decays: do decays of B hadrons, sequentially for products.
143 // Note: modeDecays does not work for bottomonium (or heavier) states,
144 // since there decays like Upsilon -> g g g also need hadronization.
145 // Also, there is no provision for Bose-Einstein effects.
146 if (!pythia.moreDecays()) continue;
149 // Repeated hadronization: restore saved event record.
150 } else if (redoHadrons) {
151 if (iRepeat > 0) event = savedEvent;
153 // Repeated hadronization: do HadronLevel (repeatedly).
154 if (!pythia.forceHadronLevel()) continue;
157 // List last repetition of first few events.
158 if ( (redoBDecays || redoHadrons) && iEvent < nList
159 && iRepeat == nRepeat - 1) event.list();
161 // Look for muons among decay products (also from charm/tau/...).
162 vector<int> iMuNeg, iMuPos;
163 for (int i = 0; i < event.size(); ++i) {
164 int id = event[i].id();
165 if (id == 13) iMuNeg.push_back(i);
166 if (id == -13) iMuPos.push_back(i);
169 // Check whether pair(s) present.
170 int nMuNeg = iMuNeg.size();
171 int nMuPos = iMuPos.size();
172 if (nMuNeg + nMuPos > 1) {
175 // Fill masses of opposite-sign pairs.
176 for (int iN = 0; iN < nMuNeg; ++iN)
177 for (int iP = 0; iP < nMuPos; ++iP)
179 (event[iMuNeg[iN]].p() + event[iMuPos[iP]].p()).mCalc() );
181 // Fill masses of same-sign pairs.
182 for (int i1 = 0; i1 < nMuNeg - 1; ++i1)
183 for (int i2 = i1 + 1; i2 < nMuNeg; ++i2)
185 (event[iMuNeg[i1]].p() + event[iMuNeg[i2]].p()).mCalc() );
186 for (int i1 = 0; i1 < nMuPos - 1; ++i1)
187 for (int i2 = i1 + 1; i2 < nMuPos; ++i2)
189 (event[iMuPos[i1]].p() + event[iMuPos[i2]].p()).mCalc() );
191 // Finished analysis of current round.
194 // End of loop over many rounds. fill number of rounds with pairs.
196 nSameEvent.fill( nWithPair );
198 // End of event loop.
201 // Statistics. Histograms.
203 cout << nBperEvent << nSameEvent << oppSignMass << sameSignMass << endl;