From $ROOTSYS/tutorials/proof/ProofPythia.C

#define ProofPythia_cxx

//////////////////////////////////////////////////////////
//
// Example of TSelector implementation to do a Monte Carlo
// generation using Pythia8.
// See tutorials/proof/runProof.C, option "pythia8", for an
// example of how to run this selector.
//
//////////////////////////////////////////////////////////

#include <TCanvas.h>
#include <TFrame.h>
#include <TPaveText.h>
#include <TFormula.h>
#include <TF1.h>
#include <TH1F.h>
#include <TMath.h>
#include <TString.h>
#include <TStyle.h>
#include <TSystem.h>
#include <TParameter.h>
#include "TClonesArray.h"
#include "TParticle.h"
#include "TDatabasePDG.h"

#include "ProofPythia.h"
#include "TPythia8.h"

//_____________________________________________________________________________
ProofPythia::ProofPythia()
{
   // Constructor

   fHist = 0;
   fPt = 0;
   fEta = 0;
   fPythia = 0;
   fP = 0;
}

//_____________________________________________________________________________
ProofPythia::~ProofPythia()
{
   // Destructor

   SafeDelete(fPythia);
   SafeDelete(fP);
}

//_____________________________________________________________________________
void ProofPythia::Begin(TTree * /*tree*/)
{
   // The Begin() function is called at the start of the query.
   // When running with PROOF Begin() is only called on the client.
   // The tree argument is deprecated (on PROOF 0 is passed).

   TString option = GetOption();
   Info("Begin", "starting a simple exercise with process option: %s", option.Data());
}

//_____________________________________________________________________________
void ProofPythia::SlaveBegin(TTree * /*tree*/)
{
   // The SlaveBegin() function is called after the Begin() function.
   // When running with PROOF SlaveBegin() is called on each slave server.
   // The tree argument is deprecated (on PROOF 0 is passed).

   TString option = GetOption();

   // Histograms
   fTot = new TH1F("histo1", "total multiplicity", 25, 0.5, 2500.5);
   fHist = new TH1F("histo2", "charged multiplicity", 20, 0.5, 500.5);
   fPt = new TH1F("histo3", "particles pT", 100, 0., 10);
   fEta = new TH1F("histo4", "particles Eta", 100, -10., 10);
   fTot->SetFillColor(kBlue);
   fHist->SetFillColor(kRed);
   fOutput->Add(fTot);
   fOutput->Add(fHist);
   fOutput->Add(fPt);
   fOutput->Add(fEta);

   fPythia = new TPythia8();
   // Configure
   fPythia->SetName("pythia8");
   fPythia->ReadConfigFile("pythia8/main03.cmnd");

   // Initialize
   fPythia->Initialize( 2212, 2212, 14000.);
   fP = new TClonesArray("TParticle", 1000);

}

//_____________________________________________________________________________
Bool_t ProofPythia::Process(Long64_t entry)
{
   // Main event loop

   fPythia->GenerateEvent();
   if (entry < 2)
      fPythia->EventListing();
   fPythia->ImportParticles(fP, "All");
   Int_t nTot = fPythia->GetN();
   fPythia->ImportParticles(fP, "All");
   Int_t np = fP->GetEntriesFast();
   // Particle loop
   Int_t nCharged = 0;
   for (Int_t ip = 0; ip < np; ip++) {
      TParticle* part = (TParticle*) fP->At(ip);
      Int_t ist = part->GetStatusCode();
      Int_t pdg = part->GetPdgCode();
      if (ist != 1) continue;
      Float_t charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
      if (charge == 0.) continue;
      nCharged++;
      Float_t eta = part->Eta();
      Float_t pt  = part->Pt();
      if (pt > 0.) fPt->Fill(pt);
      if ((eta > -10) && (eta < 10)) fEta->Fill(eta);
   }
   fHist->Fill(nCharged);
   fTot->Fill(nTot);

   return kTRUE;
}

//_____________________________________________________________________________
void ProofPythia::SlaveTerminate()
{
   // The SlaveTerminate() function is called after all entries or objects
   // have been processed. When running with PROOF SlaveTerminate() is called
   // on each slave server.
}

//_____________________________________________________________________________
void ProofPythia::Terminate()
{
   // The Terminate() function is the last function to be called during
   // a query. It always runs on the client, it can be used to present
   // the results graphically or save the results to file.

   //
   // Create canvas
   //
   TCanvas *c1 = new TCanvas("c1","Proof ProofPythia canvas",200,10,700,700);
   c1->Divide(2, 2);

   if ((fTot = dynamic_cast<TH1F *>(fOutput->FindObject("histo1")))) {
      c1->cd(1);
      fTot->Draw("h");
   }

   if ((fHist = dynamic_cast<TH1F *>(fOutput->FindObject("histo2")))) {
      c1->cd(2);
      fHist->Draw("h");
   }

   if ((fPt = dynamic_cast<TH1F *>(fOutput->FindObject("histo3")))) {
      c1->cd(3);
      fPt->Draw("h");
   }

   if ((fEta = dynamic_cast<TH1F *>(fOutput->FindObject("histo4")))) {
      c1->cd(4);
      fEta->Draw("h");
   }

   // Final update
   c1->cd();
   c1->Update();
}
 ProofPythia.C:1
 ProofPythia.C:2
 ProofPythia.C:3
 ProofPythia.C:4
 ProofPythia.C:5
 ProofPythia.C:6
 ProofPythia.C:7
 ProofPythia.C:8
 ProofPythia.C:9
 ProofPythia.C:10
 ProofPythia.C:11
 ProofPythia.C:12
 ProofPythia.C:13
 ProofPythia.C:14
 ProofPythia.C:15
 ProofPythia.C:16
 ProofPythia.C:17
 ProofPythia.C:18
 ProofPythia.C:19
 ProofPythia.C:20
 ProofPythia.C:21
 ProofPythia.C:22
 ProofPythia.C:23
 ProofPythia.C:24
 ProofPythia.C:25
 ProofPythia.C:26
 ProofPythia.C:27
 ProofPythia.C:28
 ProofPythia.C:29
 ProofPythia.C:30
 ProofPythia.C:31
 ProofPythia.C:32
 ProofPythia.C:33
 ProofPythia.C:34
 ProofPythia.C:35
 ProofPythia.C:36
 ProofPythia.C:37
 ProofPythia.C:38
 ProofPythia.C:39
 ProofPythia.C:40
 ProofPythia.C:41
 ProofPythia.C:42
 ProofPythia.C:43
 ProofPythia.C:44
 ProofPythia.C:45
 ProofPythia.C:46
 ProofPythia.C:47
 ProofPythia.C:48
 ProofPythia.C:49
 ProofPythia.C:50
 ProofPythia.C:51
 ProofPythia.C:52
 ProofPythia.C:53
 ProofPythia.C:54
 ProofPythia.C:55
 ProofPythia.C:56
 ProofPythia.C:57
 ProofPythia.C:58
 ProofPythia.C:59
 ProofPythia.C:60
 ProofPythia.C:61
 ProofPythia.C:62
 ProofPythia.C:63
 ProofPythia.C:64
 ProofPythia.C:65
 ProofPythia.C:66
 ProofPythia.C:67
 ProofPythia.C:68
 ProofPythia.C:69
 ProofPythia.C:70
 ProofPythia.C:71
 ProofPythia.C:72
 ProofPythia.C:73
 ProofPythia.C:74
 ProofPythia.C:75
 ProofPythia.C:76
 ProofPythia.C:77
 ProofPythia.C:78
 ProofPythia.C:79
 ProofPythia.C:80
 ProofPythia.C:81
 ProofPythia.C:82
 ProofPythia.C:83
 ProofPythia.C:84
 ProofPythia.C:85
 ProofPythia.C:86
 ProofPythia.C:87
 ProofPythia.C:88
 ProofPythia.C:89
 ProofPythia.C:90
 ProofPythia.C:91
 ProofPythia.C:92
 ProofPythia.C:93
 ProofPythia.C:94
 ProofPythia.C:95
 ProofPythia.C:96
 ProofPythia.C:97
 ProofPythia.C:98
 ProofPythia.C:99
 ProofPythia.C:100
 ProofPythia.C:101
 ProofPythia.C:102
 ProofPythia.C:103
 ProofPythia.C:104
 ProofPythia.C:105
 ProofPythia.C:106
 ProofPythia.C:107
 ProofPythia.C:108
 ProofPythia.C:109
 ProofPythia.C:110
 ProofPythia.C:111
 ProofPythia.C:112
 ProofPythia.C:113
 ProofPythia.C:114
 ProofPythia.C:115
 ProofPythia.C:116
 ProofPythia.C:117
 ProofPythia.C:118
 ProofPythia.C:119
 ProofPythia.C:120
 ProofPythia.C:121
 ProofPythia.C:122
 ProofPythia.C:123
 ProofPythia.C:124
 ProofPythia.C:125
 ProofPythia.C:126
 ProofPythia.C:127
 ProofPythia.C:128
 ProofPythia.C:129
 ProofPythia.C:130
 ProofPythia.C:131
 ProofPythia.C:132
 ProofPythia.C:133
 ProofPythia.C:134
 ProofPythia.C:135
 ProofPythia.C:136
 ProofPythia.C:137
 ProofPythia.C:138
 ProofPythia.C:139
 ProofPythia.C:140
 ProofPythia.C:141
 ProofPythia.C:142
 ProofPythia.C:143
 ProofPythia.C:144
 ProofPythia.C:145
 ProofPythia.C:146
 ProofPythia.C:147
 ProofPythia.C:148
 ProofPythia.C:149
 ProofPythia.C:150
 ProofPythia.C:151
 ProofPythia.C:152
 ProofPythia.C:153
 ProofPythia.C:154
 ProofPythia.C:155
 ProofPythia.C:156
 ProofPythia.C:157
 ProofPythia.C:158
 ProofPythia.C:159
 ProofPythia.C:160
 ProofPythia.C:161
 ProofPythia.C:162
 ProofPythia.C:163
 ProofPythia.C:164
 ProofPythia.C:165
 ProofPythia.C:166
 ProofPythia.C:167
 ProofPythia.C:168
 ProofPythia.C:169
 ProofPythia.C:170
 ProofPythia.C:171
 ProofPythia.C:172