11 #include "Pythia8/Pythia.h"
12 #include "Pythia8/Pythia8ToHepMC.h"
13 #include "HepMC/GenEvent.h"
14 #include "HepMC/IO_GenEvent.h"
16 using namespace Pythia8;
19 #include "fastjet/PseudoJet.hh"
20 #include "fastjet/ClusterSequence.hh"
21 #include "fastjet/CDFMidPointPlugin.hh"
22 #include "fastjet/CDFJetCluPlugin.hh"
23 #include "fastjet/D0RunIIConePlugin.hh"
30 double pTfirstJet(
const Event& event,
int nJetMin,
double Rparam) {
32 double yPartonMax = 4.;
35 fastjet::Strategy strategy = fastjet::Best;
36 fastjet::RecombinationScheme recombScheme = fastjet::E_scheme;
37 fastjet::JetDefinition *jetDef = NULL;
39 if(event[3].colType() != 0 || event[4].colType() != 0)
40 jetDef =
new fastjet::JetDefinition(fastjet::kt_algorithm, Rparam,
41 recombScheme, strategy);
44 jetDef =
new fastjet::JetDefinition(fastjet::ee_kt_algorithm,
45 recombScheme, strategy);
47 std::vector <fastjet::PseudoJet> fjInputs;
52 for (
int i = 0; i <
event.size(); ++i) {
54 if ( !event[i].isFinal()
55 ||
event[i].isLepton()
56 ||
event[i].id() == 23
57 || abs(event[i].
id()) == 24
58 || abs(event[i].y()) > yPartonMax)
62 fjInputs.push_back( fastjet::PseudoJet (event[i].px(),
63 event[i].py(), event[i].pz(),event[i].e() ) );
67 if (
int(fjInputs.size()) == 0) {
73 fastjet::ClusterSequence clustSeq(fjInputs, *jetDef);
75 double pTFirst = sqrt(clustSeq.exclusive_dmerge_max(nJetMin-1));
85 int main(
int argc,
char* argv[] ){
89 cerr <<
" Unexpected number of command-line arguments. \n You are"
90 <<
" expected to provide the arguments" << endl
91 <<
" 1. Input file for settings" << endl
92 <<
" 2. Name of output HepMC file" << endl
93 <<
" 3. Maximal number of additional jets"
94 <<
" (not used internally in Pythia, only used to construct the full"
95 <<
" name of lhe files with additional jets, and to label output"
96 <<
" histograms)" << endl
97 <<
" 4. Full name of the input LHE file (with path"
98 <<
" , without any _0.lhe suffix)" << endl
99 <<
" 5. Path for output histogram files" << endl
100 <<
" Program stopped. " << endl;
107 pythia.readFile(argv[1]);
108 int nEvent = pythia.mode(
"Main:numberOfEvents");
114 ToHepMC.set_store_xsec(
false);
120 int njet = atoi(argv[3]);
123 string iPath = string(argv[4]);
124 string oPath = string(argv[5]);
128 int njetCounterEstimate = njet;
129 vector<double> xsecEstimate;
131 vector<double> nTrialEstimate;
132 vector<double> nAcceptEstimate;
134 pythia.readString(
"Random:setSeed = on");
135 pythia.readString(
"Random:seed = 42390964");
137 while(njetCounterEstimate >= 0) {
148 for(
int n = 1; n <= nRun ; ++n ) {
152 bool skipInit =
false;
155 pythia.readString(
"Main:LHEFskipInit = on");
160 in <<
"_" << njetCounterEstimate <<
".lhe";
162 string LHEfile = iPath + in.str();
164 pythia.readString(
"HadronLevel:all = off");
167 pythia.init(LHEfile,skipInit);
169 for(
int iEvent=0; iEvent<nEvent; ++iEvent ){
173 if(iEvent == 0) pythia.stat();
176 if(pythia.next()) nAccept += 1.;
178 if(countEvents == nEvent*nRun-1){
179 xsecEstimate.push_back(pythia.info.sigmaGen());
180 nTrialEstimate.push_back(nTrial+1.);
181 nAcceptEstimate.push_back(nAccept+1.);
190 if( njetCounterEstimate > 0 )
191 njetCounterEstimate--;
197 cout << endl <<
"Finished estimating cross section"
200 for(
int i=0; i < int(xsecEstimate.size()); ++i)
201 cout <<
" Cross section estimate for " << njet-i <<
" jets :"
202 << scientific << setprecision(8) << xsecEstimate[i]
204 for(
int i=0; i < int(nTrialEstimate.size()); ++i)
205 cout <<
" Trial events for " << njet-i <<
" jets :"
206 << scientific << setprecision(3) << nTrialEstimate[i]
207 <<
" Accepted events for " << njet-i <<
" jets :"
208 << scientific << setprecision(3) << nAcceptEstimate[i]
213 int njetCounter = njet;
215 Hist histPTFirstSum(
"pT of first jet",100,0.,100.);
216 Hist histPTSecondSum(
"pT of second jet",100,0.,100.);
218 pythia.readString(
"Random:setSeed = on");
219 pythia.readString(
"Random:seed = 42390964");
225 while(njetCounter >= 0) {
227 cout <<
" Path to lhe files: " << iPath <<
"_*" << endl;
228 cout <<
" Output written to: " << oPath <<
"'name'.dat" << endl;
231 Hist histPTFirst(
"pT of first jet",100,0.,200.);
232 Hist histPTSecond(
"pT of second jet",100,0.,200.);
233 Hist histPTThird(
"pT of third jet",100,0.,200.);
234 Hist histPTFourth(
"pT of fourth jet",50,0.,100.);
235 Hist histPTFifth(
"pT of fifth jet",30,0.,50.);
236 Hist histPTSixth(
"pT of sixth jet",30,0.,50.);
241 int nTriedEvents = 0;
243 int nAccepEvents = 0;
247 for(
int n = 1; n <= nRun ; ++n ) {
251 bool skipInit =
false;
254 pythia.readString(
"Main:LHEFskipInit = on");
259 in <<
"_" << njetCounter <<
".lhe";
261 string LHEfile = iPath + in.str();
264 <<
"\t LHE FILE FOR + " << njetCounter
265 <<
" JET SAMPLE READ FROM " << LHEfile
268 cout <<
"Normalise with xsection " << xsecEstimate[njet-njetCounter]
271 pythia.readString(
"HadronLevel:all = on");
274 pythia.init(LHEfile,skipInit);
276 if(pythia.flag(
"Main:showChangedSettings")) {
277 pythia.settings.listChanged();
280 for(
int iEvent=0; iEvent<nEvent; ++iEvent ){
283 if(iEvent == 0) pythia.stat();
288 double weight = pythia.info.mergingWeight();
293 double pTfirst = pTfirstJet(pythia.event,1, D);
294 double pTsecnd = pTfirstJet(pythia.event,2, D);
295 double pTthird = pTfirstJet(pythia.event,3, D);
296 double pTfourt = pTfirstJet(pythia.event,4, D);
297 double pTfifth = pTfirstJet(pythia.event,5, D);
298 double pTsixth = pTfirstJet(pythia.event,6, D);
299 histPTFirst.fill( pTfirst, weight);
300 histPTSecond.fill( pTsecnd, weight);
301 histPTThird.fill( pTthird, weight);
302 histPTFourth.fill( pTfourt, weight);
303 histPTFifth.fill( pTfifth, weight);
304 histPTSixth.fill( pTsixth, weight);
312 double normhepmc = 1.* xsecEstimate[njet-njetCounter]
313 * nTrialEstimate[njet-njetCounter]
314 / nAcceptEstimate[njet-njetCounter]
315 * 1./ (double(nRun)*double(nEvent));
317 sigma += weight*normhepmc;
318 sigma2 += pow(weight*normhepmc,2);
320 hepmcevt->
weights().push_back(weight*normhepmc);
323 histPTFirstSum.fill( pTfirst, weight*normhepmc);
324 histPTSecondSum.fill( pTsecnd, weight*normhepmc);
327 ToHepMC.fill_next_event( pythia, hepmcevt );
332 pythia.info.sigmaErr()*1e9 );
336 ascii_io << hepmcevt;
342 if(nTriedEvents%10000 == 0)
343 cout << nTriedEvents << endl;
354 * pythia.info.sigmaGen()
355 * double(nTriedEvents)/double(nAccepEvents)
356 * 1./ (double(nRun)*double(nEvent));
359 histPTSecond *= norm;
361 histPTFourth *= norm;
368 suffix << njet <<
"_" << njetCounter;
371 write.open( (
char*)(oPath +
"PTjet1_" + suffix.str()).c_str());
372 histPTFirst.table(write);
375 write.open( (
char*)(oPath +
"PTjet2_" + suffix.str()).c_str());
376 histPTSecond.table(write);
379 write.open( (
char*)(oPath +
"PTjet3_" + suffix.str()).c_str());
380 histPTThird.table(write);
383 write.open( (
char*)(oPath +
"PTjet4_" + suffix.str()).c_str());
384 histPTFourth.table(write);
387 write.open( (
char*)(oPath +
"PTjet5_" + suffix.str()).c_str());
388 histPTFifth.table(write);
391 write.open( (
char*)(oPath +
"PTjet6_" + suffix.str()).c_str());
392 histPTSixth.table(write);
403 if( njetCounter > 0 )
414 stringstream suffixSum;
415 suffixSum << njet <<
"_wv.dat";
417 writeSum.open( (
char*)(oPath +
"PTjet1Sum_" + suffixSum.str()).c_str());
418 histPTFirstSum.table(writeSum);
421 writeSum.open( (
char*)(oPath +
"PTjet2Sum_" + suffixSum.str()).c_str());
422 histPTSecondSum.table(writeSum);
425 for(
int i=0; i < int(xsecEstimate.size()); ++i)
426 cout <<
" Cross section estimate for " << njet-i <<
" jets :"
427 << scientific << setprecision(8) << xsecEstimate[i]
429 for(
int i=0; i < int(nTrialEstimate.size()); ++i)
430 cout <<
" Trial events for " << njet-i <<
" jets :"
431 << scientific << setprecision(3) << nTrialEstimate[i]
432 <<
" Accepted events for " << njet-i <<
" jets :"
433 << scientific << setprecision(3) << nAcceptEstimate[i]
437 cout <<
"Histogrammed cross section for "
438 << iPath <<
" with " << njet <<
" additional jets is "
439 << scientific << setprecision(8) << sigma
440 <<
" error " << sqrt(sigma2) << endl;
void set_cross_section(double xs, double xs_err)
Set cross section and error in pb.
The GenCrossSection class stores the generated cross section.
void set_cross_section(const GenCrossSection &)
provide a pointer to the GenCrossSection container
The GenEvent class is the core of HepMC.
IO_GenEvent also deals with HeavyIon and PdfInfo.
WeightContainer & weights()
direct access to WeightContainer