#include <iostream>
#include "Pythia8/Pythia.h"
#include "TFile.h"
#include "TTree.h"

using namespace std;
using namespace Pythia8;

int main(){

  Pythia8::Pythia pythia;

  pythia.readString("Beams:idA = 2212");   // proton
  pythia.readString("Beams:idB = 2212");   // proton
  pythia.readString("Beams:eCM = 14.0e3"); // center of mass energy
  pythia.readString("SoftQCD:all = on");   // soft QCD physics
  pythia.readString("HardQCD:all = on");   // hard QCD physics
  pythia.init();

  // root obejects
  TFile *rootFile = new TFile("deneme2.root","recreate");
  TTree *rootTree = new TTree("values","values");

  int nevents = 1000, id, entries, event;
  double m, px, py, pz, p;

  rootTree->Branch("event",  &event,  "event/I");
  rootTree->Branch("entries",&entries,"entries/I");
  rootTree->Branch("id",     &id,     "id/I");
  rootTree->Branch("m",      &m,      "m/D");
  rootTree->Branch("px",     &px,     "px/D");
  rootTree->Branch("py",     &py,     "py/D");
  rootTree->Branch("pz",     &pz,     "pz/D");
  rootTree->Branch("p",      &p,      "p/D");

  for(int i=0; i<nevents; i++)
  {
    if (!pythia.next()) continue;

    entries = pythia.event.size();
    event = i;
    cout << "Event # = " << i << " " << " size = " << entries << endl;

    for(int j=0; j<entries; j++)
    {
       id = pythia.event[j].id();
       m  = pythia.event[j].m();
       px = pythia.event[j].px();
       py = pythia.event[j].py();
       pz = pythia.event[j].pz();
       p  = sqrt(px*px+py*py+pz*pz);

      rootTree->Fill();
    }
  }

  rootFile->Write();
  rootFile->Close();

  return 0;
}
