From $ROOTSYS/tutorials/proof/ProofFriends.C

#define ProofFriends_cxx
// The class definition in ProofFriends.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 every time 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("ProofFriends.C")
// Root > T->Process("ProofFriends.C","some options")
// Root > T->Process("ProofFriends.C+")
//

#include "ProofFriends.h"
#include "TCanvas.h"
#include "TColor.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TList.h"
#include "TMath.h"
#include "TString.h"
#include "TStyle.h"

//_____________________________________________________________________________
ProofFriends::ProofFriends()
{
   // Constructor

   fXY = 0;
   fZ = 0;
   fR = 0;
   fRZ = 0;
   fPlot = kTRUE;
   fDoFriends = kTRUE;
}

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

   TNamed *out = (TNamed *) fInput->FindObject("PROOF_DONT_PLOT");
   if (out) fPlot = kFALSE;
   out = (TNamed *) fInput->FindObject("PROOF_NO_FRIENDS");
   if (out) fDoFriends = kFALSE;
}

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

   TNamed *out = (TNamed *) fInput->FindObject("PROOF_NO_FRIENDS");
   if (out) fDoFriends = kFALSE;

   // Histograms
   fXY = new TH2F("histo1", "y:x", 50, 5., 15., 50, 10., 30.);
   fZ = new TH1F("histo2", "z , sqrt(dx*dx+dy*dy) < 1", 50, 0., 5.);
   fZ->SetFillColor(kBlue);
   fOutput->Add(fXY);
   fOutput->Add(fZ);
   if (fDoFriends) {
      fR = new TH1F("histo3", "Tfrnd.r , sqrt(dx*dx+dy*dy) < 1, z < 1", 50, 5., 15.);
      fRZ = new TH2F("histo4", "Tfrnd.r:z , sqrt(dx*dx+dy*dy) < 1, z < 1", 50, 0., 1., 50, 5., 15.);
      fR->SetFillColor(kRed);
      fOutput->Add(fR);
      fOutput->Add(fRZ);
   }
}

//_____________________________________________________________________________
Bool_t ProofFriends::Process(Long64_t entry)
{
   // 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 ProofFriends::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.

   // Read x and y, fill and apply cut
   b_x->GetEntry(entry);
   b_y->GetEntry(entry);
   fXY->Fill(x, y, 1.);
   Double_t dx = x-10.;
   Double_t dy = y-20.;
   Double_t xpy = TMath::Sqrt(dx*dx + dy*dy);
   if (xpy > 1.) return kFALSE;

   // Read z, fill and apply cut
   b_z->GetEntry(entry);
   fZ->Fill(z, 1.);
   if (z > 1.) return kFALSE;

   // Read r and fill
   if (fDoFriends) {
      b_r->GetEntry(entry);
      fR->Fill(r, 1.);
      fRZ->Fill(z, r, 1.);
   }

   return kTRUE;
}

//_____________________________________________________________________________
void ProofFriends::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 ProofFriends::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.

   if (!fPlot) return;

   gStyle->SetOptStat(1110);
   // Create canvas
   TCanvas *c1 = new TCanvas("c1","Proof ProofFriends canvas",200,10,700,700);
   // Overall background
   Int_t cb = TColor::GetColor("#ccffff");
   c1->SetFillColor(cb);
   c1->SetBorderMode(0);
   // 4 pads
   c1->Divide(2, 2);

   Int_t cf = TColor::GetColor("#99cccc");
   TPad *p1 = 0;
   if ((fXY = dynamic_cast<TH2F *>(fOutput->FindObject("histo1")))) {
      p1 = (TPad *) c1->cd(1);
      p1->SetBorderMode(0);
      p1->SetFrameFillColor(cf);
      fXY->GetXaxis()->SetTitle("x");
      fXY->GetYaxis()->SetTitle("y");
      fXY->Draw("");
   }

   if ((fZ = dynamic_cast<TH1F *>(fOutput->FindObject("histo2")))) {
      p1 = (TPad *) c1->cd(2);
      p1->SetBorderMode(0);
      p1->SetFrameFillColor(cf);
      fZ->GetXaxis()->SetTitle("z");
      fZ->GetYaxis()->SetTitle("N / 0.1");
      fZ->Draw("");
   }

   if (fDoFriends) {

      if ((fR = dynamic_cast<TH1F *>(fOutput->FindObject("histo3")))) {
         p1 = (TPad *) c1->cd(3);
         p1->SetBorderMode(0);
         p1->SetFrameFillColor(cf);
         fR->GetXaxis()->SetTitle("Tfrnd.r");
         fR->GetYaxis()->SetTitle("N / 0.2");
         fR->Draw();
      }

      if ((fRZ = dynamic_cast<TH2F *>(fOutput->FindObject("histo4")))) {
         p1 = (TPad *) c1->cd(4);
         p1->SetBorderMode(0);
         p1->SetFrameFillColor(cf);
         fRZ->GetXaxis()->SetTitle("z");
         fRZ->GetXaxis()->CenterTitle(1);
         fRZ->GetXaxis()->SetTitleOffset(1.5);
         fRZ->GetYaxis()->SetTitle("Tfrnd.r");
         fRZ->GetYaxis()->CenterTitle(1);
         fRZ->GetYaxis()->SetTitleOffset(1.75);
         fRZ->GetZaxis()->SetTitle("N / 0.1 / 0.2");
         fRZ->GetZaxis()->SetTitleOffset(1.25);
         fRZ->Draw("lego");
      }

   }

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