10 #include "Pythia8/Pythia.h"
11 #include "Pythia8/Pythia8ToHepMC.h"
14 #include "HepMC/GenEvent.h"
15 #include "HepMC/IO_GenEvent.h"
17 #include "HepMC/Units.h"
19 using namespace Pythia8;
25 int main(
int argc,
char* argv[] ){
29 cerr <<
" Unexpected number of command-line arguments ("<<argc<<
"). \n"
30 <<
" You are expected to provide the arguments" << endl
31 <<
" 1. Input file for settings" << endl
32 <<
" 2. Name of the input LHE file (with path), up to the '_tree'"
33 <<
" or '_powheg' identifiers" << endl
34 <<
" 3. Output hepmc file name" << endl
35 <<
" Program stopped. " << endl;
45 pythia.readFile(argv[1]);
52 ToHepMC.set_print_inconsistency(
false);
53 ToHepMC.set_free_parton_warnings(
false);
55 ToHepMC.set_store_pdf(
false);
56 ToHepMC.set_store_proc(
false);
57 ToHepMC.set_store_xsec(
false);
61 string iPath = string(argv[2]);
64 int nEvent = pythia.mode(
"Main:numberOfEvents");
66 int nMaxLO = pythia.mode(
"Merging:nJetMax");
68 int nMaxNLO = pythia.mode(
"Merging:nJetMaxNLO");
75 bool fsr = pythia.flag(
"PartonLevel:FSR");
76 bool isr = pythia.flag(
"PartonLevel:ISR");
77 bool mpi = pythia.flag(
"PartonLevel:MPI");
78 bool had = pythia.flag(
"HadronLevel:all");
79 pythia.settings.flag(
"PartonLevel:FSR",
false);
80 pythia.settings.flag(
"PartonLevel:ISR",
false);
81 pythia.settings.flag(
"HadronLevel:all",
false);
82 pythia.settings.flag(
"PartonLevel:MPI",
false);
85 pythia.settings.flag(
"Merging:doXSectionEstimate",
true);
86 pythia.settings.flag(
"Merging:doNL3Tree",
true);
88 int njetcounterLO = nMaxLO;
89 string iPathTree = iPath +
"_tree";
91 vector<double> xsecLO;
92 vector<double> nSelectedLO;
93 vector<double> nAcceptLO;
95 cout << endl << endl << endl;
96 cout <<
"Start estimating nl3 tree level cross section" << endl;
98 while(njetcounterLO >= 0){
102 in <<
"_" << njetcounterLO <<
".lhe";
104 if(access( (iPathTree+in.str()+
".gz").c_str(), F_OK) != -1) in <<
".gz";
106 string LHEfile = iPathTree + in.str();
108 LHAupLHEF lhareader((
char*)(LHEfile).c_str());
109 pythia.settings.mode(
"Merging:nRequested", njetcounterLO);
110 pythia.settings.word(
"Beams:LHEF", LHEfile);
111 pythia.init(&lhareader);
114 for(
int iEvent=0; iEvent<nEvent; ++iEvent ){
116 if( !pythia.next() ) {
117 if( pythia.info.atEndOfFile() ){
127 xsecLO.push_back(pythia.info.sigmaGen());
128 nSelectedLO.push_back(pythia.info.nSelected());
129 nAcceptLO.push_back(pythia.info.nAccepted());
132 if( njetcounterLO > 0 )
142 cout << endl << endl << endl;
143 cout <<
"Start estimating nl3 virtual corrections cross section" << endl;
145 pythia.settings.flag(
"Merging:doNL3Tree",
false);
146 pythia.settings.flag(
"Merging:doNL3Loop",
true);
148 int njetcounterNLO = nMaxNLO;
149 string iPathLoop= iPath +
"_powheg";
151 vector<double> xsecNLO;
152 vector<double> nSelectedNLO;
153 vector<double> nAcceptNLO;
154 vector<int> strategyNLO;
156 while(njetcounterNLO >= 0){
160 in <<
"_" << njetcounterNLO <<
".lhe";
162 if(access( (iPathLoop+in.str()+
".gz").c_str(), F_OK) != -1) in <<
".gz";
164 string LHEfile = iPathLoop + in.str();
166 LHAupLHEF lhareader((
char*)(LHEfile).c_str());
167 pythia.settings.mode(
"Merging:nRequested", njetcounterNLO);
168 pythia.settings.word(
"Beams:LHEF", LHEfile);
169 pythia.init(&lhareader);
172 for(
int iEvent=0; iEvent<nEvent; ++iEvent ){
174 if( !pythia.next() ) {
175 if( pythia.info.atEndOfFile() ){
185 xsecNLO.push_back(pythia.info.sigmaGen());
186 nSelectedNLO.push_back(pythia.info.nSelected());
187 nAcceptNLO.push_back(pythia.info.nAccepted());
188 strategyNLO.push_back(pythia.info.lhaStrategy());
191 if( njetcounterNLO > 0 )
199 int sizeLO = int(xsecLO.size());
200 int sizeNLO = int(xsecNLO.size());
205 if (
false ) k1 = k2 = k0 = xsecNLO.back() / xsecLO.back();
207 if (
true ) k0 = k1 = k2 = 1.;
209 cout <<
" K-Factors :" << endl;
210 cout <<
"k0 = " << k0 << endl;
211 cout <<
"k1 = " << k1 << endl;
212 cout <<
"k2 = " << k2 << endl;
215 pythia.settings.flag(
"Merging:doXSectionEstimate",
false);
218 pythia.settings.flag(
"PartonLevel:FSR",fsr);
219 pythia.settings.flag(
"PartonLevel:ISR",isr);
220 pythia.settings.flag(
"HadronLevel:all",had);
221 pythia.settings.flag(
"PartonLevel:MPI",mpi);
227 double sigmaTemp = 0.;
228 vector<double> sampleXStree;
229 vector<double> sampleXSvirt;
230 vector<double> sampleXSsubtTree;
232 double sigmaTotal = 0.;
233 double errorTotal = 0.;
236 pythia.settings.flag(
"Merging:doNL3Tree",
true);
237 pythia.settings.flag(
"Merging:doNL3Loop",
false);
238 pythia.settings.flag(
"Merging:doNL3Subt",
false);
239 pythia.settings.mode(
"Merging:nRecluster",0);
240 pythia.settings.mode(
"Merging:nRequested", -1);
242 njetcounterLO = nMaxLO;
243 iPathTree = iPath +
"_tree";
245 while(njetcounterLO >= 0){
248 pythia.settings.parm(
"Merging:kFactor0j", k0);
249 pythia.settings.parm(
"Merging:kFactor1j", k1);
250 pythia.settings.parm(
"Merging:kFactor2j", k2);
254 in <<
"_" << njetcounterLO <<
".lhe";
256 if(access( (iPathTree+in.str()+
".gz").c_str(), F_OK) != -1) in <<
".gz";
258 string LHEfile = iPathTree + in.str();
260 cout << endl << endl << endl
261 <<
"Start tree level treatment for " << njetcounterLO <<
" jets"
264 LHAupLHEF lhareader((
char*)(LHEfile).c_str());
265 pythia.settings.mode(
"Merging:nRequested", njetcounterLO);
266 pythia.settings.word(
"Beams:LHEF", LHEfile);
267 pythia.init(&lhareader);
270 int iNow = sizeLO-1-njetcounterLO;
273 for(
int iEvent=0; iEvent<nEvent; ++iEvent ){
276 if( !pythia.next() ) {
277 if( pythia.info.atEndOfFile() )
break;
282 double weightNLO = pythia.info.mergingWeightNLO();
283 double evtweight = pythia.info.weight();
284 weightNLO *= evtweight;
286 if ( weightNLO == 0. )
continue;
291 double normhepmc = xsecLO[iNow] / nAcceptLO[iNow];
293 if( abs(pythia.info.lhaStrategy()) == 4 )
294 normhepmc = 1. / (1e9*nSelectedLO[iNow]);
296 hepmcevt->
weights().push_back(weightNLO*normhepmc);
298 ToHepMC.fill_next_event( pythia, hepmcevt );
300 sigmaTotal += weightNLO*normhepmc;
301 sigmaTemp += weightNLO*normhepmc;
302 errorTotal += pow2(weightNLO*normhepmc);
308 ascii_io << hepmcevt;
316 sampleXStree.push_back(sigmaTemp);
320 if( njetcounterLO > 0 )
330 cout << endl << endl << endl;
331 cout <<
"Start nl3 virtual corrections part" << endl;
334 pythia.settings.flag(
"Merging:doNL3Tree",
false);
335 pythia.settings.flag(
"Merging:doNL3Loop",
true);
336 pythia.settings.flag(
"Merging:doNL3Subt",
false);
337 pythia.settings.mode(
"Merging:nRecluster",0);
339 njetcounterNLO = nMaxNLO;
340 iPathLoop = iPath +
"_powheg";
342 while(njetcounterNLO >= 0){
346 in <<
"_" << njetcounterNLO <<
".lhe";
348 if(access( (iPathLoop+in.str()+
".gz").c_str(), F_OK) != -1) in <<
".gz";
350 string LHEfile = iPathLoop + in.str();
352 cout << endl << endl << endl
353 <<
"Start loop level treatment for " << njetcounterNLO <<
" jets"
356 LHAupLHEF lhareader((
char*)(LHEfile).c_str());
357 pythia.settings.mode(
"Merging:nRequested", njetcounterNLO);
358 pythia.settings.word(
"Beams:LHEF", LHEfile);
359 pythia.init(&lhareader);
362 int iNow = sizeNLO-1-njetcounterNLO;
365 for(
int iEvent=0; iEvent<nEvent; ++iEvent ){
368 if( !pythia.next() ) {
369 if( pythia.info.atEndOfFile() )
break;
374 double weightNLO = pythia.info.mergingWeightNLO();
375 double evtweight = pythia.info.weight();
376 weightNLO *= evtweight;
378 if ( weightNLO == 0. )
continue;
383 double normhepmc = xsecNLO[iNow] / nAcceptNLO[iNow];
385 if( abs(pythia.info.lhaStrategy()) == 4 )
386 normhepmc = 1. / (1e9*nSelectedNLO[iNow]);
388 hepmcevt->
weights().push_back(weightNLO*normhepmc);
390 ToHepMC.fill_next_event( pythia, hepmcevt );
392 sigmaTotal += weightNLO*normhepmc;
393 sigmaTemp += weightNLO*normhepmc;
394 errorTotal += pow2(weightNLO*normhepmc);
400 ascii_io << hepmcevt;
408 sampleXSvirt.push_back(sigmaTemp);
412 if( njetcounterNLO > 0)
422 cout << endl << endl << endl;
423 cout <<
"Shower subtractive events" << endl;
426 pythia.settings.flag(
"Merging:doNL3Tree",
false);
427 pythia.settings.flag(
"Merging:doNL3Loop",
false);
428 pythia.settings.flag(
"Merging:doNL3Subt",
true);
429 pythia.settings.mode(
"Merging:nRecluster",1);
430 pythia.settings.mode(
"Merging:nRequested", -1);
432 int nMaxCT = nMaxNLO + 1;
433 int njetcounterCT = nMaxCT;
434 string iPathSubt = iPath +
"_tree";
436 while(njetcounterCT >= 1){
440 in <<
"_" << njetcounterCT <<
".lhe";
442 if(access( (iPathSubt+in.str()+
".gz").c_str(), F_OK) != -1) in <<
".gz";
444 string LHEfile = iPathSubt + in.str();
446 cout << endl << endl << endl
447 <<
"Start subtractive treatment for " << njetcounterCT <<
" jets"
450 LHAupLHEF lhareader((
char*)(LHEfile).c_str());
451 pythia.settings.mode(
"Merging:nRequested", njetcounterCT);
452 pythia.settings.word(
"Beams:LHEF", LHEfile);
453 pythia.init(&lhareader);
456 int iNow = sizeLO-1-njetcounterCT;
459 for(
int iEvent=0; iEvent<nEvent; ++iEvent ){
462 if( !pythia.next() ) {
463 if( pythia.info.atEndOfFile() )
break;
468 double weightNLO = pythia.info.mergingWeightNLO();
469 double evtweight = pythia.info.weight();
470 weightNLO *= evtweight;
472 if ( weightNLO == 0. )
continue;
477 double normhepmc = -1.*xsecLO[iNow] / nAcceptLO[iNow];
479 if( abs(pythia.info.lhaStrategy()) == 4 )
480 normhepmc = -1. / (1e9*nSelectedLO[iNow]);
482 hepmcevt->
weights().push_back( weightNLO*normhepmc);
484 ToHepMC.fill_next_event( pythia, hepmcevt );
486 sigmaTotal += weightNLO*normhepmc;
487 sigmaTemp += weightNLO*normhepmc;
488 errorTotal += pow2(weightNLO*normhepmc);
495 ascii_io << hepmcevt;
503 sampleXSsubtTree.push_back(sigmaTemp);
507 if( njetcounterCT > 1 )
515 cout << endl << endl;
516 cout <<
" *---------------------------------------------------*" << endl;
517 cout <<
" | |" << endl;
518 cout <<
" | Sample cross sections after NL3 merging |" << endl;
519 cout <<
" | |" << endl;
520 cout <<
" | Leading order cross sections (mb): |" << endl;
521 for (
int i = 0; i < int(sampleXStree.size()); ++i)
522 cout <<
" | " << sampleXStree.size()-1-i <<
"-jet: "
523 << setw(17) << scientific << setprecision(6)
524 << sampleXStree[i] <<
" |" << endl;
525 cout <<
" | |" << endl;
526 cout <<
" | NLO order cross sections (mb): |" << endl;
527 for (
int i = 0; i < int(sampleXSvirt.size()); ++i)
528 cout <<
" | " << sampleXSvirt.size()-1-i <<
"-jet: "
529 << setw(17) << scientific << setprecision(6)
530 << sampleXSvirt[i] <<
" |" << endl;
531 cout <<
" | |" << endl;
532 cout <<
" | Leading-order subtractive cross sections (mb): |" << endl;
533 for (
int i = 0; i < int(sampleXSsubtTree.size()); ++i)
534 cout <<
" | " << sampleXSsubtTree.size()-1-i+1 <<
"-jet: "
535 << setw(17) << scientific << setprecision(6)
536 << sampleXSsubtTree[i] <<
" |" << endl;
537 cout <<
" | |" << endl;
538 cout <<
" |---------------------------------------------------|" << endl;
539 cout <<
" |---------------------------------------------------|" << endl;
540 cout <<
" | Inclusive cross sections: |" << endl;
541 cout <<
" | |" << endl;
542 cout <<
" | NL3 merged inclusive cross section: |" << endl;
543 cout <<
" | " << setw(17) << scientific << setprecision(6)
544 << sigmaTotal <<
" +- " << setw(17) << sqrt(errorTotal) <<
" mb "
546 cout <<
" | |" << endl;
547 cout <<
" | NLO inclusive cross section: |" << endl;
548 cout <<
" | " << setw(17) << scientific << setprecision(6)
549 << xsecNLO.back() <<
" mb |" << endl;
550 cout <<
" | |" << endl;
551 cout <<
" | LO inclusive cross section: |" << endl;
552 cout <<
" | " << setw(17) << scientific << setprecision(6)
553 << xsecLO.back() <<
" mb |" << endl;
554 cout <<
" | |" << endl;
555 cout <<
" *---------------------------------------------------*" << endl;
556 cout << endl << 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