# Analysis of Pythia Events using ROOT

**URL:** <https://root-forum.cern.ch/t/analysis-of-pythia-events-using-root/44815>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [May 11, 2021, 12:54pm UTC](https://root-forum.cern.ch/t/analysis-of-pythia-events-using-root/44815 "2021-05-11T12:54:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChinmaySeth](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/chinmayseth/32/25969_2.png) [@ChinmaySeth](https://root-forum.cern.ch/u/ChinmaySeth)\
**Post date:** [May 11, 2021, 12:54pm UTC](https://root-forum.cern.ch/t/analysis-of-pythia-events-using-root/44815/1 "2021-05-11T12:54:28Z")

</div>

Hi,  
I want to generate events using Pythia and save them in Trees( as a .root file). Then I want to write a root program to read the above file as an input and perform analysis(multiplicity/eta distribution etc). Although an example program has been given with pythia I’m confused how to get relevant data from the file.

ROOT Version: 6.22.02  
Pythia Version: 8303  
Platform: Ubuntu 20.04

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 11, 2021, 12:57pm UTC](https://root-forum.cern.ch/t/analysis-of-pythia-events-using-root/44815/2 "2021-05-11T12:57:36Z")

</div>

What have you done so far ?

---

<div class="post-metadata">

**Author:** ![ChinmaySeth](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/chinmayseth/32/25969_2.png) [@ChinmaySeth](https://root-forum.cern.ch/u/ChinmaySeth)\
**Post date:** [May 11, 2021, 1:00pm UTC](https://root-forum.cern.ch/t/analysis-of-pythia-events-using-root/44815/3 "2021-05-11T13:00:49Z")

</div>

I’ve generated a root file using the example program provided with pythia,

```auto
#include "Pythia8/Pythia.h"

// ROOT, for saving Pythia events as trees in a file.
#include "TTree.h"
#include "TFile.h"

using namespace Pythia8;

int main() {

  // Beam energies, minimal Q2, number of events to generate.
  double eProton = 920.;
  double eElectron = 27.5;
  double Q2min = 25.;
  int nEvent = 100;

  
  
  Pythia pythia;
  
 

  // Set up incoming beams, for frame with unequal beam energies.
  pythia.readString("Beams:frameType = 2");
  // BeamA = proton.
  pythia.readString("Beams:idA = 2212");
  pythia.settings.parm("Beams:eA", eProton);
  // BeamB = electron.
  pythia.readString("Beams:idB = 11");
  pythia.settings.parm("Beams:eB", eElectron);

  // Set up DIS process within some phase space.
  // Neutral current (with gamma/Z interference).
  pythia.readString("WeakBosonExchange:ff2ff(t:gmZ) = on");
  // Uncomment to allow charged current.
  //pythia.readString("WeakBosonExchange:ff2ff(t:W) = on");
  // Phase-space cut: minimal Q2 of process.
  pythia.settings.parm("PhaseSpace:Q2Min", Q2min);

  // Set dipole recoil on. Necessary for DIS + shower.
  pythia.readString("SpaceShower:dipoleRecoil = on");

  // Allow emissions up to the kinematical limit,
  // since rate known to match well to matrix elements everywhere.
  pythia.readString("SpaceShower:pTmaxMatch = 2");

  // QED radiation off lepton not handled yet by the new procedure.
  pythia.readString("PDF:lepton = off");
  pythia.readString("TimeShower:QEDshowerByL = off");
  
  // Initialize.
  pythia.init();

  // Set up the ROOT TFile and TTree.
  TFile *file = TFile::Open("main00.root","recreate");
  Event *event = &pythia.event;
  
  TTree *T = new TTree("T","ev1 Tree");
  T->Branch("event",&event);
  
 // Begin event loop. Generate event; skip if generation aborted.
  for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
    if (!pythia.next()) continue;

    // Fill the pythia event into the TTree.
    // Warning: the files will rapidly become large if all events
    // are saved. In some cases it may be convenient to do some
    // processing of events and only save those that appear
    // interesting for future analyses.
    T->Fill();

  // End event loop.
  }

  // Statistics on event generation.
  pythia.stat();

  // Write tree.
  T->Print();
  T->Write();
  delete file;

  // Done.
  return 0;
}

```

Now I need to analyse the generated root file.I’m not sure if the above generated root file is suffifcient or some other branches have to be added.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [May 11, 2021, 1:15pm UTC](https://root-forum.cern.ch/t/analysis-of-pythia-events-using-root/44815/4 "2021-05-11T13:15:14Z")

</div>

> [@ChinmaySeth](#):
>
> I’m not sure if the above generated root file is suffifcient or some other branches have to be added.

That’s all depend of what you want to analyse … I guess you are the one who knows…
