ProofPythia.C

Go to the documentation of this file.
00001 #define ProofPythia_cxx
00002 
00003 //////////////////////////////////////////////////////////
00004 //
00005 // Example of TSelector implementation to do a Monte Carlo
00006 // generation using Pythia8.
00007 // See tutorials/proof/runProof.C, option "pythia8", for an
00008 // example of how to run this selector.
00009 //
00010 //////////////////////////////////////////////////////////
00011 
00012 #include <TCanvas.h>
00013 #include <TFrame.h>
00014 #include <TPaveText.h>
00015 #include <TFormula.h>
00016 #include <TF1.h>
00017 #include <TH1F.h>
00018 #include <TMath.h>
00019 #include <TString.h>
00020 #include <TStyle.h>
00021 #include <TSystem.h>
00022 #include <TParameter.h>
00023 #include "TClonesArray.h"
00024 #include "TParticle.h"
00025 #include "TDatabasePDG.h"
00026 
00027 #include "ProofPythia.h"
00028 #include "TPythia8.h"
00029 
00030 //_____________________________________________________________________________
00031 ProofPythia::ProofPythia()
00032 {
00033    // Constructor
00034 
00035    fHist = 0;
00036    fPt = 0;
00037    fEta = 0;
00038    fPythia = 0;
00039    fP = 0;
00040 }
00041 
00042 //_____________________________________________________________________________
00043 ProofPythia::~ProofPythia()
00044 {
00045    // Destructor
00046 
00047    SafeDelete(fPythia);
00048    SafeDelete(fP);
00049 }
00050 
00051 //_____________________________________________________________________________
00052 void ProofPythia::Begin(TTree * /*tree*/)
00053 {
00054    // The Begin() function is called at the start of the query.
00055    // When running with PROOF Begin() is only called on the client.
00056    // The tree argument is deprecated (on PROOF 0 is passed).
00057 
00058    TString option = GetOption();
00059 }
00060 
00061 //_____________________________________________________________________________
00062 void ProofPythia::SlaveBegin(TTree * /*tree*/)
00063 {
00064    // The SlaveBegin() function is called after the Begin() function.
00065    // When running with PROOF SlaveBegin() is called on each slave server.
00066    // The tree argument is deprecated (on PROOF 0 is passed).
00067 
00068    TString option = GetOption();
00069 
00070    // Histograms
00071    fTot = new TH1F("histo1", "total multiplicity", 25, 0.5, 2500.5);
00072    fHist = new TH1F("histo2", "charged multiplicity", 20, 0.5, 500.5);
00073    fPt = new TH1F("histo3", "particles pT", 100, 0., 10);
00074    fEta = new TH1F("histo4", "particles Eta", 100, -10., 10);
00075    fTot->SetFillColor(kBlue);
00076    fHist->SetFillColor(kRed);
00077    fOutput->Add(fTot);
00078    fOutput->Add(fHist);
00079    fOutput->Add(fPt);
00080    fOutput->Add(fEta);
00081 
00082    fPythia = new TPythia8();
00083    // Configure
00084    fPythia->SetName("pythia8");
00085    fPythia->ReadConfigFile("pythia8/main03.cmnd");
00086 
00087    // Initialize
00088    fPythia->Initialize( 2212, 2212, 14000.);
00089    fP = new TClonesArray("TParticle", 1000);
00090 
00091 }
00092 
00093 //_____________________________________________________________________________
00094 Bool_t ProofPythia::Process(Long64_t entry)
00095 {
00096    // Main event loop  
00097 
00098    fPythia->GenerateEvent();
00099    if (entry < 2)
00100       fPythia->EventListing();
00101    fPythia->ImportParticles(fP, "All");
00102    Int_t nTot = fPythia->GetN();
00103    fPythia->ImportParticles(fP, "All");
00104    Int_t np = fP->GetEntriesFast();
00105    // Particle loop
00106    Int_t nCharged = 0;
00107    for (Int_t ip = 0; ip < np; ip++) {
00108       TParticle* part = (TParticle*) fP->At(ip);
00109       Int_t ist = part->GetStatusCode();
00110       Int_t pdg = part->GetPdgCode();
00111       if (ist != 1) continue;
00112       Float_t charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
00113       if (charge == 0.) continue;
00114       nCharged++;
00115       Float_t eta = part->Eta();
00116       Float_t pt  = part->Pt();
00117       if (pt > 0.) fPt->Fill(pt);
00118       if ((eta > -10) && (eta < 10)) fEta->Fill(eta);
00119    }
00120    fHist->Fill(nCharged);
00121    fTot->Fill(nTot);
00122 
00123    return kTRUE;
00124 }
00125 
00126 //_____________________________________________________________________________
00127 void ProofPythia::SlaveTerminate()
00128 {
00129    // The SlaveTerminate() function is called after all entries or objects
00130    // have been processed. When running with PROOF SlaveTerminate() is called
00131    // on each slave server.
00132 }
00133 
00134 //_____________________________________________________________________________
00135 void ProofPythia::Terminate()
00136 {
00137    // The Terminate() function is the last function to be called during
00138    // a query. It always runs on the client, it can be used to present
00139    // the results graphically or save the results to file.
00140 
00141    //
00142    // Create canvas
00143    //
00144    TCanvas *c1 = new TCanvas("c1","Proof ProofPythia canvas",200,10,700,700);
00145    c1->Divide(2, 2);
00146 
00147    if ((fTot = dynamic_cast<TH1F *>(fOutput->FindObject("histo1")))) {
00148       c1->cd(1);
00149       fTot->Draw("h");
00150    }
00151 
00152    if ((fHist = dynamic_cast<TH1F *>(fOutput->FindObject("histo2")))) {
00153       c1->cd(2);
00154       fHist->Draw("h");
00155    }
00156 
00157    if ((fPt = dynamic_cast<TH1F *>(fOutput->FindObject("histo3")))) {
00158       c1->cd(3);
00159       fPt->Draw("h");
00160    }
00161 
00162    if ((fEta = dynamic_cast<TH1F *>(fOutput->FindObject("histo4")))) {
00163       c1->cd(4);
00164       fEta->Draw("h");
00165    }
00166 
00167    // Final update
00168    c1->cd();
00169    c1->Update();
00170 }

Generated on Tue Jul 5 15:44:53 2011 for ROOT_528-00b_version by  doxygen 1.5.1