1 // main10.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 // Example how you can use UserHooks to trace pT spectrum through program,
7 // and veto undesirable jet multiplicities.
10 using namespace Pythia8;
12 //==========================================================================
14 // Put histograms here to make them global, so they can be used both
15 // in MyUserHooks and in the main program.
17 Hist pTtrial("trial pT spectrum", 100, 0., 400.);
18 Hist pTselect("selected pT spectrum (before veto)", 100, 0., 400.);
19 Hist pTaccept("accepted pT spectrum (after veto)", 100, 0., 400.);
20 Hist nPartonsB("number of partons before veto", 20, -0.5, 19.5);
21 Hist nJets("number of jets before veto", 20, -0.5, 19.5);
22 Hist nPartonsA("number of partons after veto", 20, -0.5, 19.5);
23 Hist nFSRatISR("number of FSR emissions at first ISR emission",
26 //==========================================================================
28 // Write own derived UserHooks class.
30 class MyUserHooks : public UserHooks {
34 // Constructor creates cone-jet finder with (etaMax, nEta, nPhi).
35 MyUserHooks() { coneJet = new CellJet(5., 100, 64); }
37 // Destructor deletes cone-jet finder.
38 ~MyUserHooks() {delete coneJet;}
40 // Allow process cross section to be modified...
41 virtual bool canModifySigma() {return true;}
43 // ...which gives access to the event at the trial level, before selection.
44 virtual double multiplySigmaBy(const SigmaProcess* sigmaProcessPtr,
45 const PhaseSpace* phaseSpacePtr, bool inEvent) {
47 // All events should be 2 -> 2, but kill them if not.
48 if (sigmaProcessPtr->nFinal() != 2) return 0.;
50 // Extract the pT for 2 -> 2 processes in the event generation chain
51 // (inEvent = false for initialization).
53 pTHat = phaseSpacePtr->pTHat();
54 // Fill histogram of pT spectrum.
55 pTtrial.fill( pTHat );
58 // Here we do not modify 2 -> 2 cross sections.
62 // Allow a veto for the interleaved evolution in pT.
63 virtual bool canVetoPT() {return true;}
65 // Do the veto test at a pT scale of 5 GeV.
66 virtual double scaleVetoPT() {return 5.;}
68 // Access the event in the interleaved evolution.
69 virtual bool doVetoPT(int iPos, const Event& event) {
71 // iPos <= 3 for interleaved evolution; skip others.
72 if (iPos > 3) return false;
74 // Fill histogram of pT spectrum at this stage.
77 // Extract a copy of the partons in the hardest system.
79 nPartonsB.fill( workEvent.size() );
81 // Find number of jets with eTjet > 10 for R = 0.7.
82 coneJet->analyze(event, 10., 0.7);
83 int nJet = coneJet->size();
86 // Veto events which do not have exactly three jets.
87 if (nJet != 3) return true;
89 // Statistics of survivors.
90 nPartonsA.fill( workEvent.size() );
93 // Do not veto events that got this far.
98 // Allow a veto after (by default) first step.
99 virtual bool canVetoStep() {return true;}
101 // Access the event in the interleaved evolution after first step.
102 virtual bool doVetoStep( int iPos, int nISR, int nFSR, const Event& ) {
104 // Only want to study what happens at first ISR emission
105 if (iPos == 2 && nISR == 1) nFSRatISR.fill( nFSR );
107 // Not intending to veto any events here.
113 // The cone-jet finder.
116 // Save the pThat scale.
121 //==========================================================================
128 // Process selection. No need to study hadron level.
129 pythia.readString("HardQCD:all = on");
130 pythia.readString("PhaseSpace:pTHatMin = 50.");
131 pythia.readString("HadronLevel:all = off");
133 // Set up to do a user veto and send it in.
134 MyUserHooks* myUserHooks = new MyUserHooks();
135 pythia.setUserHooksPtr( myUserHooks);
137 // Tevatron initialization.
138 pythia.init( 2212, -2212, 1960.);
141 for (int iEvent = 0; iEvent < 1000; ++iEvent) {
146 // End of event loop.
149 // Statistics. Histograms.
151 cout << pTtrial << pTselect << pTaccept
152 << nPartonsB << nJets << nPartonsA