13 #include "HepMCInterface.h"
14 #include "HepMC/GenEvent.h"
15 #include "HepMC/IO_GenEvent.h"
17 #include "HepMC/Units.h"
19 using namespace Pythia8;
22 #include "fastjet/PseudoJet.hh"
23 #include "fastjet/ClusterSequence.hh"
24 #include "fastjet/CDFMidPointPlugin.hh"
25 #include "fastjet/CDFJetCluPlugin.hh"
26 #include "fastjet/D0RunIIConePlugin.hh"
33 double pTfirstJet(
const Event& event,
int nJetMin,
double Rparam) {
35 double yPartonMax = 4.;
38 fastjet::Strategy strategy = fastjet::Best;
39 fastjet::RecombinationScheme recombScheme = fastjet::E_scheme;
40 fastjet::JetDefinition *jetDef = NULL;
42 if(event[3].colType() != 0 || event[4].colType() != 0)
43 jetDef =
new fastjet::JetDefinition(fastjet::kt_algorithm, Rparam,
44 recombScheme, strategy);
47 jetDef =
new fastjet::JetDefinition(fastjet::ee_kt_algorithm,
48 recombScheme, strategy);
50 std::vector <fastjet::PseudoJet> fjInputs;
55 for (
int i = 0; i <
event.size(); ++i) {
57 if ( !event[i].isFinal()
58 ||
event[i].isLepton()
59 ||
event[i].id() == 23
60 || abs(event[i].
id()) == 24
61 || abs(event[i].y()) > yPartonMax)
65 fjInputs.push_back( fastjet::PseudoJet (event[i].px(),
66 event[i].py(), event[i].pz(),event[i].e() ) );
70 if (
int(fjInputs.size()) == 0) {
76 fastjet::ClusterSequence clustSeq(fjInputs, *jetDef);
78 double pTFirst = sqrt(clustSeq.exclusive_dmerge_max(nJetMin-1));
88 int main(
int argc,
char* argv[] ){
92 cerr <<
" Unexpected number of command-line arguments. \n You are"
93 <<
" expected to provide the arguments" << endl
94 <<
" 1. Input file for settings" << endl
95 <<
" 2. Name of output HepMC file" << endl
96 <<
" 3. Maximal number of additional jets"
97 <<
" (not used internally in Pythia, only used to construct the full"
98 <<
" name of lhe files with additional jets, and to label output"
99 <<
" histograms)" << endl
100 <<
" 4. Full name of the input LHE file (with path"
101 <<
" , without any _0.lhe suffix)" << endl
102 <<
" 5. Path for output histogram files" << endl
103 <<
" Program stopped. " << endl;
110 pythia.readFile(argv[1]);
111 int nEvent = pythia.mode(
"Main:numberOfEvents");
123 int njet = atoi(argv[3]);
126 string iPath = string(argv[4]);
127 string oPath = string(argv[5]);
131 int njetCounterEstimate = njet;
132 vector<double> xsecEstimate;
134 vector<double> nTrialEstimate;
135 vector<double> nAcceptEstimate;
137 pythia.readString(
"Random:setSeed = on");
138 pythia.readString(
"Random:seed = 42390964");
140 while(njetCounterEstimate >= 0) {
151 for(
int n = 1; n <= nRun ; ++n ) {
155 bool skipInit =
false;
158 pythia.readString(
"Main:LHEFskipInit = on");
163 in <<
"_" << njetCounterEstimate <<
".lhe";
165 string LHEfile = iPath + in.str();
167 pythia.readString(
"HadronLevel:all = off");
170 pythia.init(LHEfile,skipInit);
172 for(
int iEvent=0; iEvent<nEvent; ++iEvent ){
176 if(iEvent == 0) pythia.stat();
179 if(pythia.next()) nAccept += 1.;
181 if(countEvents == nEvent*nRun-1){
182 xsecEstimate.push_back(pythia.info.sigmaGen());
183 nTrialEstimate.push_back(nTrial+1.);
184 nAcceptEstimate.push_back(nAccept+1.);
193 if( njetCounterEstimate > 0 )
194 njetCounterEstimate--;
200 cout << endl <<
"Finished estimating cross section"
203 for(
int i=0; i < int(xsecEstimate.size()); ++i)
204 cout <<
" Cross section estimate for " << njet-i <<
" jets :"
205 << scientific << setprecision(8) << xsecEstimate[i]
207 for(
int i=0; i < int(nTrialEstimate.size()); ++i)
208 cout <<
" Trial events for " << njet-i <<
" jets :"
209 << scientific << setprecision(3) << nTrialEstimate[i]
210 <<
" Accepted events for " << njet-i <<
" jets :"
211 << scientific << setprecision(3) << nAcceptEstimate[i]
216 int njetCounter = njet;
218 Hist histPTFirstSum(
"pT of first jet",100,0.,100.);
219 Hist histPTSecondSum(
"pT of second jet",100,0.,100.);
221 pythia.readString(
"Random:setSeed = on");
222 pythia.readString(
"Random:seed = 42390964");
228 while(njetCounter >= 0) {
230 cout <<
" Path to lhe files: " << iPath <<
"_*" << endl;
231 cout <<
" Output written to: " << oPath <<
"'name'.dat" << endl;
234 Hist histPTFirst(
"pT of first jet",100,0.,200.);
235 Hist histPTSecond(
"pT of second jet",100,0.,200.);
236 Hist histPTThird(
"pT of third jet",100,0.,200.);
237 Hist histPTFourth(
"pT of fourth jet",50,0.,100.);
238 Hist histPTFifth(
"pT of fifth jet",30,0.,50.);
239 Hist histPTSixth(
"pT of sixth jet",30,0.,50.);
244 int nTriedEvents = 0;
246 int nAccepEvents = 0;
250 for(
int n = 1; n <= nRun ; ++n ) {
254 bool skipInit =
false;
257 pythia.readString(
"Main:LHEFskipInit = on");
262 in <<
"_" << njetCounter <<
".lhe";
264 string LHEfile = iPath + in.str();
267 <<
"\t LHE FILE FOR + " << njetCounter
268 <<
" JET SAMPLE READ FROM " << LHEfile
271 cout <<
"Normalise with xsection " << xsecEstimate[njet-njetCounter]
274 pythia.readString(
"HadronLevel:all = on");
277 pythia.init(LHEfile,skipInit);
279 if(pythia.flag(
"Main:showChangedSettings")) {
280 pythia.settings.listChanged();
283 for(
int iEvent=0; iEvent<nEvent; ++iEvent ){
286 if(iEvent == 0) pythia.stat();
291 double weight = pythia.info.mergingWeight();
296 double pTfirst = pTfirstJet(pythia.event,1, D);
297 double pTsecnd = pTfirstJet(pythia.event,2, D);
298 double pTthird = pTfirstJet(pythia.event,3, D);
299 double pTfourt = pTfirstJet(pythia.event,4, D);
300 double pTfifth = pTfirstJet(pythia.event,5, D);
301 double pTsixth = pTfirstJet(pythia.event,6, D);
302 histPTFirst.fill( pTfirst, weight);
303 histPTSecond.fill( pTsecnd, weight);
304 histPTThird.fill( pTthird, weight);
305 histPTFourth.fill( pTfourt, weight);
306 histPTFifth.fill( pTfifth, weight);
307 histPTSixth.fill( pTsixth, weight);
317 double normhepmc = 1.* xsecEstimate[njet-njetCounter]
318 * nTrialEstimate[njet-njetCounter]
319 / nAcceptEstimate[njet-njetCounter]
320 * 1./ (double(nRun)*double(nEvent));
322 sigma += weight*normhepmc;
323 sigma2 += pow(weight*normhepmc,2);
325 hepmcevt->
weights().push_back(weight*normhepmc);
328 histPTFirstSum.fill( pTfirst, weight*normhepmc);
329 histPTSecondSum.fill( pTsecnd, weight*normhepmc);
334 ToHepMC.fill_next_event( pythia.event, hepmcevt );
339 pythia.info.sigmaErr()*1e9 );
343 ascii_io << hepmcevt;
349 if(nTriedEvents%10000 == 0)
350 cout << nTriedEvents << endl;
361 * pythia.info.sigmaGen()
362 * double(nTriedEvents)/double(nAccepEvents)
363 * 1./ (double(nRun)*double(nEvent));
366 histPTSecond *= norm;
368 histPTFourth *= norm;
375 suffix << njet <<
"_" << njetCounter;
378 write.open( (
char*)(oPath +
"PTjet1_" + suffix.str()).c_str());
379 histPTFirst.table(write);
382 write.open( (
char*)(oPath +
"PTjet2_" + suffix.str()).c_str());
383 histPTSecond.table(write);
386 write.open( (
char*)(oPath +
"PTjet3_" + suffix.str()).c_str());
387 histPTThird.table(write);
390 write.open( (
char*)(oPath +
"PTjet4_" + suffix.str()).c_str());
391 histPTFourth.table(write);
394 write.open( (
char*)(oPath +
"PTjet5_" + suffix.str()).c_str());
395 histPTFifth.table(write);
398 write.open( (
char*)(oPath +
"PTjet6_" + suffix.str()).c_str());
399 histPTSixth.table(write);
410 if( njetCounter > 0 )
421 stringstream suffixSum;
422 suffixSum << njet <<
"_wv.dat";
424 writeSum.open( (
char*)(oPath +
"PTjet1Sum_" + suffixSum.str()).c_str());
425 histPTFirstSum.table(writeSum);
428 writeSum.open( (
char*)(oPath +
"PTjet2Sum_" + suffixSum.str()).c_str());
429 histPTSecondSum.table(writeSum);
432 for(
int i=0; i < int(xsecEstimate.size()); ++i)
433 cout <<
" Cross section estimate for " << njet-i <<
" jets :"
434 << scientific << setprecision(8) << xsecEstimate[i]
436 for(
int i=0; i < int(nTrialEstimate.size()); ++i)
437 cout <<
" Trial events for " << njet-i <<
" jets :"
438 << scientific << setprecision(3) << nTrialEstimate[i]
439 <<
" Accepted events for " << njet-i <<
" jets :"
440 << scientific << setprecision(3) << nAcceptEstimate[i]
444 cout <<
"Histogrammed cross section for "
445 << iPath <<
" with " << njet <<
" additional jets is "
446 << scientific << setprecision(8) << sigma
447 <<
" 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