ROOT logo
#define ProofSimple_cxx
// The class definition in ProofSimple.h has been generated automatically
// by the ROOT utility TTree::MakeSelector(). This class is derived
// from the ROOT class TSelector. For more information on the TSelector
// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.

// The following methods are defined in this file:
//    Begin():        called everytime a loop on the tree starts,
//                    a convenient place to create your histograms.
//    SlaveBegin():   called after Begin(), when on PROOF called only on the
//                    slave servers.
//    Process():      called for each event, in this function you decide what
//                    to read and fill your histograms.
//    SlaveTerminate: called at the end of the loop on the tree, when on PROOF
//                    called only on the slave servers.
//    Terminate():    called at the end of the loop on the tree,
//                    a convenient place to draw/fit your histograms.
//
// To use this file, try the following session on your Tree T:
//
// Root > T->Process("ProofSimple.C")
// Root > T->Process("ProofSimple.C","some options")
// Root > T->Process("ProofSimple.C+")
//

#include "ProofSimple.h"
#include <TCanvas.h>
#include <TFrame.h>
#include <TPaveText.h>
#include <TFormula.h>
#include <TF1.h>
#include <TH1F.h>
#include <TMath.h>
#include <TRandom3.h>
#include <TString.h>
#include <TStyle.h>
#include <TSystem.h>
#include <TParameter.h>

//_____________________________________________________________________________
ProofSimple::ProofSimple()
{
   // Constructor

   fNhist = -1;
   fHist = 0;
   fRandom = 0;
}

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

   if (fRandom) delete fRandom;
}

//_____________________________________________________________________________
void ProofSimple::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();

   // Histos array
   fNhist = 100;
   if (fInput->FindObject("ProofSimple_NHist")) {
      TParameter<Long_t> *p =
         dynamic_cast<TParameter<Long_t>*>(fInput->FindObject("ProofSimple_NHist"));
      fNhist = (p) ? (Int_t) p->GetVal() : fNhist;
   }
   fHist = new TH1F*[fNhist];
}

//_____________________________________________________________________________
void ProofSimple::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();

   // Histos array
   fNhist = 100;
   if (fInput->FindObject("ProofSimple_NHist")) {
      TParameter<Long_t> *p =
         dynamic_cast<TParameter<Long_t>*>(fInput->FindObject("ProofSimple_NHist"));
      fNhist = (p) ? (Int_t) p->GetVal() : fNhist;
   }
   fHist = new TH1F*[fNhist];

   // Create the histogram
   for (Int_t i=0; i < fNhist; i++) {
      fHist[i] = new TH1F(Form("h%d",i), Form("h%d",i), 100, -3., 3.);
      fHist[i]->SetFillColor(kRed);
      fOutput->Add(fHist[i]);
   }

   // Set random seed
   fRandom = new TRandom3(0);
}

//_____________________________________________________________________________
Bool_t ProofSimple::Process(Long64_t)
{
   // The Process() function is called for each entry in the tree (or possibly
   // keyed object in the case of PROOF) to be processed. The entry argument
   // specifies which entry in the currently loaded tree is to be processed.
   // It can be passed to either ProofSimple::GetEntry() or TBranch::GetEntry()
   // to read either all or the required parts of the data. When processing
   // keyed objects with PROOF, the object is already loaded and is available
   // via the fObject pointer.
   //
   // This function should contain the "body" of the analysis. It can contain
   // simple or elaborate selection criteria, run algorithms on the data
   // of the event and typically fill histograms.
   //
   // The processing can be stopped by calling Abort().
   //
   // Use fStatus to set the return value of TTree::Process().
   //
   // The return value is currently not used.

   for (Int_t i=0; i < fNhist; i++) {
      if (fRandom && fHist[i]) {
         Double_t x = fRandom->Gaus(0.,1.);
         fHist[i]->Fill(x);
      }
   }

   return kTRUE;
}

//_____________________________________________________________________________
void ProofSimple::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 ProofSimple::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 a canvas, with 100 pads
   //
   TCanvas *c1 = new TCanvas("c1","Proof ProofSimple canvas",200,10,700,700);
   Int_t nside = (Int_t)TMath::Sqrt((Float_t)fNhist);
   nside = (nside*nside < fNhist) ? nside+1 : nside;
   c1->Divide(nside,nside,0,0);

   for (Int_t i=0; i < fNhist; i++) {
      fHist[i] = dynamic_cast<TH1F *>(fOutput->FindObject(Form("h%d",i)));
      c1->cd(i+1);
      if (fHist[i])
         fHist[i]->Draw();
   }

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