Logo ROOT   6.08/07
Reference Guide
ProofFriends.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_ProofFriends
3 ///
4 /// Selector to process tree friends
5 ///
6 /// \macro_code
7 ///
8 /// \author Gerardo Ganis (gerardo.ganis@cern.ch)
9 
10 #define ProofFriends_cxx
11 
12 #include "ProofFriends.h"
13 #include "TCanvas.h"
14 #include "TColor.h"
15 #include "TH1F.h"
16 #include "TH2F.h"
17 #include "TList.h"
18 #include "TMath.h"
19 #include "TString.h"
20 #include "TStyle.h"
21 
22 //_____________________________________________________________________________
23 ProofFriends::ProofFriends()
24 {
25  // Constructor
26 
27  fXY = 0;
28  fZ = 0;
29  fR = 0;
30  fRZ = 0;
31  fPlot = kTRUE;
32  fDoFriends = kTRUE;
33 }
34 
35 //_____________________________________________________________________________
36 void ProofFriends::Begin(TTree * /*tree*/)
37 {
38  // The Begin() function is called at the start of the query.
39  // When running with PROOF Begin() is only called on the client.
40  // The tree argument is deprecated (on PROOF 0 is passed).
41 
42  TString option = GetOption();
43 
44  TNamed *out = (TNamed *) fInput->FindObject("PROOF_DONT_PLOT");
45  if (out) fPlot = kFALSE;
46  out = (TNamed *) fInput->FindObject("PROOF_NO_FRIENDS");
47  if (out) fDoFriends = kFALSE;
48 }
49 
50 //_____________________________________________________________________________
51 void ProofFriends::SlaveBegin(TTree * /*tree*/)
52 {
53  // The SlaveBegin() function is called after the Begin() function.
54  // When running with PROOF SlaveBegin() is called on each slave server.
55  // The tree argument is deprecated (on PROOF 0 is passed).
56 
57  TString option = GetOption();
58 
59  TNamed *out = (TNamed *) fInput->FindObject("PROOF_NO_FRIENDS");
60  if (out) fDoFriends = kFALSE;
61 
62  // Histograms
63  fXY = new TH2F("histo1", "y:x", 50, 5., 15., 50, 10., 30.);
64  fZ = new TH1F("histo2", "z , sqrt(dx*dx+dy*dy) < 1", 50, 0., 5.);
65  fZ->SetFillColor(kBlue);
66  fOutput->Add(fXY);
67  fOutput->Add(fZ);
68  if (fDoFriends) {
69  fR = new TH1F("histo3", "Tfrnd.r , sqrt(dx*dx+dy*dy) < 1, z < 1", 50, 5., 15.);
70  fRZ = new TH2F("histo4", "Tfrnd.r:z , sqrt(dx*dx+dy*dy) < 1, z < 1", 50, 0., 1., 50, 5., 15.);
71  fR->SetFillColor(kRed);
72  fOutput->Add(fR);
73  fOutput->Add(fRZ);
74  }
75 }
76 
77 //_____________________________________________________________________________
78 Bool_t ProofFriends::Process(Long64_t entry)
79 {
80  // The Process() function is called for each entry in the tree (or possibly
81  // keyed object in the case of PROOF) to be processed. The entry argument
82  // specifies which entry in the currently loaded tree is to be processed.
83  // It can be passed to either ProofFriends::GetEntry() or TBranch::GetEntry()
84  // to read either all or the required parts of the data. When processing
85  // keyed objects with PROOF, the object is already loaded and is available
86  // via the fObject pointer.
87  //
88  // This function should contain the "body" of the analysis. It can contain
89  // simple or elaborate selection criteria, run algorithms on the data
90  // of the event and typically fill histograms.
91  //
92  // The processing can be stopped by calling Abort().
93  //
94  // Use fStatus to set the return value of TTree::Process().
95  //
96  // The return value is currently not used.
97 
98  // Read x and y, fill and apply cut
99  b_x->GetEntry(entry);
100  b_y->GetEntry(entry);
101  fXY->Fill(x, y, 1.);
102  Double_t dx = x-10.;
103  Double_t dy = y-20.;
104  Double_t xpy = TMath::Sqrt(dx*dx + dy*dy);
105  if (xpy > 1.) return kFALSE;
106 
107  // Read z, fill and apply cut
108  b_z->GetEntry(entry);
109  fZ->Fill(z, 1.);
110  if (z > 1.) return kFALSE;
111 
112  // Read r and fill
113  if (fDoFriends) {
114  b_r->GetEntry(entry);
115  fR->Fill(r, 1.);
116  fRZ->Fill(z, r, 1.);
117  }
118 
119  return kTRUE;
120 }
121 
122 //_____________________________________________________________________________
123 void ProofFriends::SlaveTerminate()
124 {
125  // The SlaveTerminate() function is called after all entries or objects
126  // have been processed. When running with PROOF SlaveTerminate() is called
127  // on each slave server.
128 
129 }
130 
131 //_____________________________________________________________________________
132 void ProofFriends::Terminate()
133 {
134  // The Terminate() function is the last function to be called during
135  // a query. It always runs on the client, it can be used to present
136  // the results graphically or save the results to file.
137 
138  if (!fPlot) return;
139 
140  gStyle->SetOptStat(1110);
141  // Create canvas
142  TCanvas *c1 = new TCanvas("c1","Proof ProofFriends canvas",200,10,700,700);
143  // Overall background
144  Int_t cb = TColor::GetColor("#ccffff");
145  c1->SetFillColor(cb);
146  c1->SetBorderMode(0);
147  // 4 pads
148  c1->Divide(2, 2);
149 
150  Int_t cf = TColor::GetColor("#99cccc");
151  TPad *p1 = 0;
152  if ((fXY = dynamic_cast<TH2F *>(fOutput->FindObject("histo1")))) {
153  p1 = (TPad *) c1->cd(1);
154  p1->SetBorderMode(0);
155  p1->SetFrameFillColor(cf);
156  fXY->GetXaxis()->SetTitle("x");
157  fXY->GetYaxis()->SetTitle("y");
158  fXY->Draw("");
159  }
160 
161  if ((fZ = dynamic_cast<TH1F *>(fOutput->FindObject("histo2")))) {
162  p1 = (TPad *) c1->cd(2);
163  p1->SetBorderMode(0);
164  p1->SetFrameFillColor(cf);
165  fZ->GetXaxis()->SetTitle("z");
166  fZ->GetYaxis()->SetTitle("N / 0.1");
167  fZ->Draw("");
168  }
169 
170  if (fDoFriends) {
171 
172  if ((fR = dynamic_cast<TH1F *>(fOutput->FindObject("histo3")))) {
173  p1 = (TPad *) c1->cd(3);
174  p1->SetBorderMode(0);
175  p1->SetFrameFillColor(cf);
176  fR->GetXaxis()->SetTitle("Tfrnd.r");
177  fR->GetYaxis()->SetTitle("N / 0.2");
178  fR->Draw();
179  }
180 
181  if ((fRZ = dynamic_cast<TH2F *>(fOutput->FindObject("histo4")))) {
182  p1 = (TPad *) c1->cd(4);
183  p1->SetBorderMode(0);
184  p1->SetFrameFillColor(cf);
185  fRZ->GetXaxis()->SetTitle("z");
186  fRZ->GetXaxis()->CenterTitle(1);
187  fRZ->GetXaxis()->SetTitleOffset(1.5);
188  fRZ->GetYaxis()->SetTitle("Tfrnd.r");
189  fRZ->GetYaxis()->CenterTitle(1);
190  fRZ->GetYaxis()->SetTitleOffset(1.75);
191  fRZ->GetZaxis()->SetTitle("N / 0.1 / 0.2");
192  fRZ->GetZaxis()->SetTitleOffset(1.25);
193  fRZ->Draw("lego");
194  }
195 
196  }
197 
198  // Final update
199  c1->cd();
200  c1->Update();
201 }
void Begin(Int_t type)
long long Long64_t
Definition: RtypesCore.h:69
return c1
Definition: legend1.C:41
Definition: Rtypes.h:61
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:302
virtual void SetBorderMode(Short_t bordermode)
Definition: TPad.h:308
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Double_t x[n]
Definition: legend1.C:17
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition: TObject.cxx:380
TRandom2 r(17)
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
The most important graphics class in the ROOT system.
Definition: TPad.h:37
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb"...
Definition: TColor.cxx:1706
static double p1(double t, double a, double b)
The Canvas class.
Definition: TCanvas.h:41
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
Selector to process tree friends.
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1089
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition: TStyle.cxx:1257
A TTree object has a header with a name and a title.
Definition: TTree.h:98
Definition: Rtypes.h:61
void SetFrameFillColor(Color_t color=1)
Definition: TAttPad.h:75
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2183
const Bool_t kTRUE
Definition: Rtypes.h:91
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:308