Logo ROOT   6.12/07
Reference Guide
ProofEvent.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_ProofEvent
3 ///
4 /// Selector for generic processing with Event
5 ///
6 /// \macro_code
7 ///
8 /// \author Gerardo Ganis (gerardo.ganis@cern.ch)
9 
10 #define ProofEvent_cxx
11 
12 #include "ProofEvent.h"
13 #include "Event.h"
14 
15 #include <TCanvas.h>
16 #include <TH1F.h>
17 #include <TRandom3.h>
18 
19 //_____________________________________________________________________________
20 ProofEvent::ProofEvent()
21 {
22  // Constructor
23 
24  fEvent = 0;
25  fNtrack = -1;
26  fHisto = 0;
27  fRandom = 0;
28 }
29 
30 //_____________________________________________________________________________
31 ProofEvent::~ProofEvent()
32 {
33  // Destructor
34 
35  SafeDelete(fRandom);
36 }
37 
38 //_____________________________________________________________________________
39 void ProofEvent::Begin(TTree * /*tree*/)
40 {
41  // The Begin() function is called at the start of the query.
42  // When running with PROOF Begin() is only called on the client.
43  // The tree argument is deprecated (on PROOF 0 is passed).
44 
45  TString option = GetOption();
46  Info("Begin", "starting a simple exercise with process option: %s", option.Data());
47 }
48 
49 //_____________________________________________________________________________
50 void ProofEvent::SlaveBegin(TTree * /*tree*/)
51 {
52  // The SlaveBegin() function is called after the Begin() function.
53  // When running with PROOF SlaveBegin() is called on each slave server.
54  // The tree argument is deprecated (on PROOF 0 is passed).
55 
56  TString option = GetOption();
57  Info("SalveBegin", "starting on a slave with process option: %s", option.Data());
58 
59  // Create event
60  fEvent = new Event();
61 
62  // Create the histogram
63  fHisto = new TH1F("histo", "tracks multiplicity", 20, 0, 100);
64  fHisto->GetYaxis()->SetTitle("number of events");
65  fHisto->GetXaxis()->SetTitle("number of tracks");
66 
67  //adding histo to selector output list
68  fOutput->Add(fHisto);
69 
70  // Set random seed
71  fRandom = new TRandom3(0);
72 }
73 
74 //_____________________________________________________________________________
75 Bool_t ProofEvent::Process(Long64_t )
76 {
77 
78  // Start main loop over all events
79  // get a random parameter for connstructing event
80 
81  int i= (int)(100 * (fRandom->Rndm()));
82  fEvent->Build(i,(1+i), 2);
83  fNtrack= (fEvent->GetNtrack());
84  if ((fNtrack >= 0 )&& (fNtrack <= 100 ))
85  fHisto->Fill(fNtrack, 1);
86 
87  return kTRUE;
88 }
89 
90 //_____________________________________________________________________________
91 void ProofEvent::SlaveTerminate()
92 {
93  //nothing to be done
94 
95 }
96 
97 //_____________________________________________________________________________
98 void ProofEvent::Terminate()
99 {
100  // The Terminate() function is the last function to be called during
101  // a query. It always runs on the client, it can be used to present
102  // the results graphically or save the results to file.
103 
104  TCanvas *c1 = new TCanvas("c1","Proof ProofEvent canvas",200,10,700,700);
105  fHisto = dynamic_cast<TH1F *>(fOutput->FindObject(Form("histo")));
106  if (fHisto) {
107  fHisto->Draw("h");
108 
109  // Final update
110  c1->cd();
111  c1->Update();
112  } else {
113  Warning("Terminate", "histogram not found");
114  }
115 }
void Begin(Int_t type)
Random number generator class based on M.
Definition: TRandom3.h:27
long long Long64_t
Definition: RtypesCore.h:69
return c1
Definition: legend1.C:41
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:285
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
Basic string class.
Definition: TString.h:125
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:567
bool Bool_t
Definition: RtypesCore.h:59
#define SafeDelete(p)
Definition: RConfig.h:509
void Info(const char *location, const char *msgfmt,...)
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2969
char * Form(const char *fmt,...)
void Warning(const char *location, const char *msgfmt,...)
The Canvas class.
Definition: TCanvas.h:31
Selector for generic processing with Event.
A TTree object has a header with a name and a title.
Definition: TTree.h:70
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2248
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char * Data() const
Definition: TString.h:345