ROOT logo

From $ROOTSYS/tutorials/proof/ProofEvent.C

#define ProofEvent_cxx

//////////////////////////////////////////////////////////
//
// Example of TSelector implementation to do generic
// processing with the test 'Event' structure.
// See tutorials/proof/runProof.C, option "event", for an
// example of how to run this selector.
//
//////////////////////////////////////////////////////////

#include "ProofEvent.h"
#include "Event.h"

#include <TCanvas.h>
#include <TH1F.h>
#include <TRandom3.h>

//_____________________________________________________________________________
ProofEvent::ProofEvent()
{
   // Constructor

   fEvent = 0;
   fNtrack = -1; 
   fHisto = 0;
   fRandom = 0;
}

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

   SafeDelete(fRandom);
}

//_____________________________________________________________________________
void ProofEvent::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 ProofEvent::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();
   Info("SalveBegin", "starting on a slave with process option: %s", option.Data());

   // Create event
   fEvent = new Event();

   // Create the histogram
   fHisto = new TH1F("histo", "tracks multiplicity", 20, 0, 100);
   fHisto->GetYaxis()->SetTitle("number of events");
   fHisto->GetXaxis()->SetTitle("number of tracks");

   //adding histo to selector output list
   fOutput->Add(fHisto);

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

//_____________________________________________________________________________
Bool_t ProofEvent::Process(Long64_t )
{

  // Start main loop over all events
  // get a random parameter for connstructing event

   int i= (int)(100 * (fRandom->Rndm()));
   fEvent->Build(i,(1+i), 2);
   fNtrack= (fEvent->GetNtrack());
   if ((fNtrack >= 0 )&& (fNtrack <= 100 ))
      fHisto->Fill(fNtrack, 1);

   return kTRUE;
}

//_____________________________________________________________________________
void ProofEvent::SlaveTerminate()
{
   //nothing to be done

}

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

   TCanvas *c1 = new TCanvas("c1","Proof ProofEvent canvas",200,10,700,700);
   fHisto = dynamic_cast<TH1F *>(fOutput->FindObject(Form("histo")));
   if (fHisto) {
      fHisto->Draw("h");

      // Final update
      c1->cd();
      c1->Update();
   } else {
      Warning("Terminate", "histogram not found");
   }
}
 ProofEvent.C:1
 ProofEvent.C:2
 ProofEvent.C:3
 ProofEvent.C:4
 ProofEvent.C:5
 ProofEvent.C:6
 ProofEvent.C:7
 ProofEvent.C:8
 ProofEvent.C:9
 ProofEvent.C:10
 ProofEvent.C:11
 ProofEvent.C:12
 ProofEvent.C:13
 ProofEvent.C:14
 ProofEvent.C:15
 ProofEvent.C:16
 ProofEvent.C:17
 ProofEvent.C:18
 ProofEvent.C:19
 ProofEvent.C:20
 ProofEvent.C:21
 ProofEvent.C:22
 ProofEvent.C:23
 ProofEvent.C:24
 ProofEvent.C:25
 ProofEvent.C:26
 ProofEvent.C:27
 ProofEvent.C:28
 ProofEvent.C:29
 ProofEvent.C:30
 ProofEvent.C:31
 ProofEvent.C:32
 ProofEvent.C:33
 ProofEvent.C:34
 ProofEvent.C:35
 ProofEvent.C:36
 ProofEvent.C:37
 ProofEvent.C:38
 ProofEvent.C:39
 ProofEvent.C:40
 ProofEvent.C:41
 ProofEvent.C:42
 ProofEvent.C:43
 ProofEvent.C:44
 ProofEvent.C:45
 ProofEvent.C:46
 ProofEvent.C:47
 ProofEvent.C:48
 ProofEvent.C:49
 ProofEvent.C:50
 ProofEvent.C:51
 ProofEvent.C:52
 ProofEvent.C:53
 ProofEvent.C:54
 ProofEvent.C:55
 ProofEvent.C:56
 ProofEvent.C:57
 ProofEvent.C:58
 ProofEvent.C:59
 ProofEvent.C:60
 ProofEvent.C:61
 ProofEvent.C:62
 ProofEvent.C:63
 ProofEvent.C:64
 ProofEvent.C:65
 ProofEvent.C:66
 ProofEvent.C:67
 ProofEvent.C:68
 ProofEvent.C:69
 ProofEvent.C:70
 ProofEvent.C:71
 ProofEvent.C:72
 ProofEvent.C:73
 ProofEvent.C:74
 ProofEvent.C:75
 ProofEvent.C:76
 ProofEvent.C:77
 ProofEvent.C:78
 ProofEvent.C:79
 ProofEvent.C:80
 ProofEvent.C:81
 ProofEvent.C:82
 ProofEvent.C:83
 ProofEvent.C:84
 ProofEvent.C:85
 ProofEvent.C:86
 ProofEvent.C:87
 ProofEvent.C:88
 ProofEvent.C:89
 ProofEvent.C:90
 ProofEvent.C:91
 ProofEvent.C:92
 ProofEvent.C:93
 ProofEvent.C:94
 ProofEvent.C:95
 ProofEvent.C:96
 ProofEvent.C:97
 ProofEvent.C:98
 ProofEvent.C:99
 ProofEvent.C:100
 ProofEvent.C:101
 ProofEvent.C:102
 ProofEvent.C:103
 ProofEvent.C:104
 ProofEvent.C:105
 ProofEvent.C:106
 ProofEvent.C:107
 ProofEvent.C:108
 ProofEvent.C:109
 ProofEvent.C:110
 ProofEvent.C:111
 ProofEvent.C:112
 ProofEvent.C:113
 ProofEvent.C:114
 ProofEvent.C:115
 ProofEvent.C:116