Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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//_____________________________________________________________________________
20ProofEvent::ProofEvent()
21{
22 // Constructor
23
24 fEvent = 0;
25 fNtrack = -1;
26 fHisto = 0;
27 fRandom = 0;
28}
29
30//_____________________________________________________________________________
31ProofEvent::~ProofEvent()
32{
33 // Destructor
34
35 SafeDelete(fRandom);
36}
37
38//_____________________________________________________________________________
39void 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//_____________________________________________________________________________
50void 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//_____________________________________________________________________________
75Bool_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//_____________________________________________________________________________
91void ProofEvent::SlaveTerminate()
92{
93 //nothing to be done
94
95}
96
97//_____________________________________________________________________________
98void 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}
Selector for generic processing with Event.
#define SafeDelete(p)
Definition RConfig.hxx:540
bool Bool_t
Definition RtypesCore.h:63
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:230
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:241
Option_t Option_t option
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:577
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3060
Random number generator class based on M.
Definition TRandom3.h:27
Basic string class.
Definition TString.h:139
A TTree represents a columnar dataset.
Definition TTree.h:79
return c1
Definition legend1.C:41