forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TProofDraw.cxx
2222 lines (1877 loc) · 70.8 KB
/
TProofDraw.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/proofplayer:$Id$
// Author: Maarten Ballintijn, Marek Biskup 24/09/2003
/*************************************************************************
* Copyright (C) 1995-2003, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
/** \class TProofDraw
\ingroup proofkernel
Implement Tree drawing using PROOF
*/
#include "TProofDraw.h"
#include "TAttFill.h"
#include "TAttLine.h"
#include "TAttMarker.h"
#include "TCanvas.h"
#include "TClass.h"
#include "TError.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TH3F.h"
#include "TProof.h"
#include "TProofDebug.h"
#include "TStatus.h"
#include "TTreeDrawArgsParser.h"
#include "TTreeFormula.h"
#include "TTreeFormulaManager.h"
#include "TTree.h"
#include "TEventList.h"
#include "TEntryList.h"
#include "TProfile.h"
#include "TProfile2D.h"
#include "TEnv.h"
#include "TNamed.h"
#include "TGraph.h"
#include "TPolyMarker3D.h"
#include "TVirtualPad.h"
#include "THLimitsFinder.h"
#include "TView.h"
#include "TStyle.h"
#include "TDirectory.h"
#include "TROOT.h"
#include <algorithm>
using namespace std;
// Simple call to draw a canvas on the fly from applications loading
// this plug-in dynamically
extern "C" {
Int_t DrawCanvas(TObject *obj)
{
// Draw the object if deriving from a canvas
if (TCanvas* c = dynamic_cast<TCanvas *> (obj)) {
c->Draw();
return 0;
}
// Not a TCanvas
return 1;
}
}
// Simple call to parse arguments on the fly from applications loading
// this plug-in dynamically
extern "C" {
Int_t GetDrawArgs(const char *var, const char *sel, Option_t *opt,
TString &selector, TString &objname)
{
// Parse arguments with the help of TTreeDrawArgsParser
TTreeDrawArgsParser info;
info.Parse(var, sel, opt);
selector = info.GetProofSelectorName();
objname = info.GetObjectName();
// Done
return 0;
}
}
// Simple call to create destroy a 'named' canvas
extern "C" {
void FeedBackCanvas(const char *name, Bool_t create)
{
// Create or destroy canvas 'name'
if (create) {
new TCanvas(name, "FeedBack", 800,30,700,500);
} else {
TCanvas *c = (gROOT->GetListOfCanvases()) ?
(TCanvas *) gROOT->GetListOfCanvases()->FindObject(name) : 0;
if (c) delete c;
}
// Done
return;
}
}
ClassImp(TProofDraw);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TProofDraw::TProofDraw()
: fStatus(0), fManager(0), fTree(0)
{
fVar[0] = 0;
fVar[1] = 0;
fVar[2] = 0;
fVar[3] = 0;
fManager = 0;
fMultiplicity = 0;
fSelect = 0;
fObjEval = kFALSE;
fDimension = 0;
fWeight = 1.;
}
////////////////////////////////////////////////////////////////////////////////
/// Destructor.
TProofDraw::~TProofDraw()
{
ClearFormula();
}
////////////////////////////////////////////////////////////////////////////////
/// Init the tree.
void TProofDraw::Init(TTree *tree)
{
PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
fTree = tree;
CompileVariables();
}
////////////////////////////////////////////////////////////////////////////////
/// Called when a new tree is loaded.
Bool_t TProofDraw::Notify()
{
PDB(kDraw,1) Info("Notify","Enter");
if (fStatus == 0) {
if (!fOutput || (fOutput &&
!(fStatus = dynamic_cast<TStatus*>(fOutput->FindObject("PROOF_Status")))))
return kFALSE;
}
if (!fStatus->IsOk()) return kFALSE;
if (!fManager) {
fAbort = TSelector::kAbortProcess;
return kFALSE;
}
fManager->UpdateFormulaLeaves();
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Executed by the client before processing.
void TProofDraw::Begin(TTree *tree)
{
PDB(kDraw,1) Info("Begin","Enter tree = %p", tree);
TObject *os = fInput->FindObject("selection");
TObject *ov = fInput->FindObject("varexp");
if (os && ov) {
fSelection = os->GetTitle();
fInitialExp = ov->GetTitle();
fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
if (fTreeDrawArgsParser.GetObjectName() == "")
fTreeDrawArgsParser.SetObjectName("htemp");
}
PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
fTree = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Executed by each slave before processing.
void TProofDraw::SlaveBegin(TTree* /*tree*/)
{
// Get the weight
TProofDraw::FillWeight();
}
////////////////////////////////////////////////////////////////////////////////
/// Get weight from input list, if any
void TProofDraw::FillWeight()
{
Double_t ww;
if (TProof::GetParameter(fInput, "PROOF_ChainWeight", ww) == 0)
fWeight = ww;
PDB(kDraw,1) Info("FillWeight","fWeight= %f", fWeight);
}
////////////////////////////////////////////////////////////////////////////////
/// Processes a single variable from an entry.
Bool_t TProofDraw::ProcessSingle(Long64_t entry, Int_t i)
{
Double_t w;
Double_t v[4]; //[TTreeDrawArgsParser::fgMaxDimension];
if (fSelect)
w = fWeight * fSelect->EvalInstance(i);
else
w = fWeight;
PDB(kDraw,3) Info("ProcessSingle","w[%d] = %f", i, w);
if (w != 0.0) {
R__ASSERT(fDimension <= TTreeDrawArgsParser::GetMaxDimension());
for (int j = 0; j < fDimension; j++)
v[j] = fVar[j]->EvalInstance(i);
if (fDimension >= 1)
PDB(kDraw,4) Info("Process","v[0] = %f", v[0]);
DoFill(entry, w, v);
}
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Executed for each entry.
Bool_t TProofDraw::Process(Long64_t entry)
{
PDB(kDraw,3) Info("Process", "enter entry = %lld", entry);
fTree->LoadTree(entry);
Int_t ndata = fManager->GetNdata();
PDB(kDraw,3) Info("Process","ndata = %d", ndata);
for (Int_t i=0;i<ndata;i++) {
ProcessSingle(entry, i);
}
return kTRUE;
}
////////////////////////////////////////////////////////////////////////////////
/// Executed by each slave after the processing has finished,
/// before returning the results to the client.
void TProofDraw::SlaveTerminate(void)
{
PDB(kDraw,1) Info("SlaveTerminate","Enter");
}
////////////////////////////////////////////////////////////////////////////////
/// Executed by the client after getting the processing retults.
void TProofDraw::Terminate(void)
{
PDB(kDraw,1) Info("Terminate","Enter");
if (fStatus == 0) {
fStatus = dynamic_cast<TStatus*>(fOutput->FindObject("PROOF_Status"));
if (fStatus == 0) {
// did not run selector, error messages were already printed
return;
}
}
if (!fStatus->IsOk()) {
fStatus->Print();
return;
}
}
////////////////////////////////////////////////////////////////////////////////
/// Delete internal buffers.
void TProofDraw::ClearFormula()
{
ResetBit(kWarn);
for (Int_t i = 0; i < 4; i++)
SafeDelete(fVar[i]);
SafeDelete(fSelect);
fManager = 0; // This is intentional. The manager is deleted when the last formula it manages
// is deleted. This is unusual but was usefull for backward compatibility.
fMultiplicity = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Move to a canvas named <name>_canvas; create the canvas if not existing.
/// Used to avoid screwing up existing plots when non default names are used
/// for the final objects
void TProofDraw::SetCanvas(const char *objname)
{
TString name = objname;
if (!gPad) {
gROOT->MakeDefCanvas();
gPad->SetName(name);
PDB(kDraw,2) Info("SetCanvas", "created canvas %s", name.Data());
} else {
PDB(kDraw,2)
Info("SetCanvas", "using canvas %s", gPad->GetName());
}
}
////////////////////////////////////////////////////////////////////////////////
/// Set the drawing attributes from the input list
void TProofDraw::SetDrawAtt(TObject *o)
{
Int_t att = -1;
PDB(kDraw,2) Info("SetDrawAtt", "setting attributes for %s", o->GetName());
// Line Attributes
TAttLine *al = dynamic_cast<TAttLine *> (o);
if (al) {
// Line color
if (TProof::GetParameter(fInput, "PROOF_LineColor", att) == 0)
al->SetLineColor((Color_t)att);
// Line style
if (TProof::GetParameter(fInput, "PROOF_LineStyle", att) == 0)
al->SetLineStyle((Style_t)att);
// Line color
if (TProof::GetParameter(fInput, "PROOF_LineWidth", att) == 0)
al->SetLineWidth((Width_t)att);
PDB(kDraw,2) Info("SetDrawAtt", "line: c:%d, s:%d, wd:%d",
al->GetLineColor(), al->GetLineStyle(), al->GetLineWidth());
}
// Marker Attributes
TAttMarker *am = dynamic_cast<TAttMarker *> (o);
if (am) {
// Marker color
if (TProof::GetParameter(fInput, "PROOF_MarkerColor", att) == 0)
am->SetMarkerColor((Color_t)att);
// Marker size
if (TProof::GetParameter(fInput, "PROOF_MarkerSize", att) == 0) {
Info("SetDrawAtt", "att: %d", att);
Float_t msz = (Float_t)att / 1000.;
am->SetMarkerSize((Size_t)msz);
}
// Marker style
if (TProof::GetParameter(fInput, "PROOF_MarkerStyle", att) == 0)
am->SetMarkerStyle((Style_t)att);
PDB(kDraw,2) Info("SetDrawAtt", "marker: c:%d, s:%d, sz:%f",
am->GetMarkerColor(), am->GetMarkerStyle(), am->GetMarkerSize());
}
// Area Fill Attributes
TAttFill *af = dynamic_cast<TAttFill *> (o);
if (af) {
// Area fill color
if (TProof::GetParameter(fInput, "PROOF_FillColor", att) == 0)
af->SetFillColor((Color_t)att);
// Area fill style
if (TProof::GetParameter(fInput, "PROOF_FillStyle", att) == 0)
af->SetFillStyle((Style_t)att);
PDB(kDraw,2) Info("SetDrawAtt", "area: c:%d, s:%d",
af->GetFillColor(), af->GetFillStyle());
}
}
////////////////////////////////////////////////////////////////////////////////
/// Sets the error status.
void TProofDraw::SetError(const char *sub, const char *mesg)
{
if (fStatus == 0) {
if (!(fStatus = dynamic_cast<TStatus*>(fOutput->FindObject("PROOF_Status"))))
return;
}
TString m;
if (IsA())
m.Form("%s::%s: %s", IsA()->GetName(), sub, mesg);
else
m.Form("TProofDraw::%s: %s", sub, mesg);
fStatus->Add(m);
}
////////////////////////////////////////////////////////////////////////////////
/// Compiles each variable from fTreeDrawArgsParser for the tree fTree.
/// Return kFALSE if any of the variable is not compilable.
Bool_t TProofDraw::CompileVariables()
{
// Set aliases, if any
TNamed *nms = (TNamed *) fInput->FindObject("PROOF_ListOfAliases");
if (nms) {
TString names = nms->GetTitle(), n, na;
Ssiz_t from = 0;
while(names.Tokenize(n, from, ",")) {
if (!n.IsNull()) {
na.Form("alias:%s", n.Data());
TNamed *nm = (TNamed *) fInput->FindObject(na);
if (na) fTree->SetAlias(n.Data(), nm->GetTitle());
}
}
}
PDB(kDraw,2)
if (fTree->GetListOfAliases()) fTree->GetListOfAliases()->Print();
fDimension = fTreeDrawArgsParser.GetDimension();
fMultiplicity = 0;
fObjEval = kFALSE;
if (strlen(fTreeDrawArgsParser.GetSelection())) {
fSelect = new TTreeFormula("Selection", fTreeDrawArgsParser.GetSelection(), fTree);
fSelect->SetQuickLoad(kTRUE);
if (!fSelect->GetNdim()) {delete fSelect; fSelect = 0; return kFALSE; }
}
fManager = new TTreeFormulaManager();
if (fSelect) fManager->Add(fSelect);
fTree->ResetBit(TTree::kForceRead);
for (int i = 0; i < fDimension; i++) {
fVar[i] = new TTreeFormula(Form("Var%d", i),fTreeDrawArgsParser.GetVarExp(i),fTree);
fVar[i]->SetQuickLoad(kTRUE);
if (!fVar[i]->GetNdim()) {
ClearFormula();
Error("CompileVariables", "Error compiling expression");
SetError("CompileVariables", "Error compiling variables");
return kFALSE;
}
fManager->Add(fVar[i]);
}
fManager->Sync();
if (fManager->GetMultiplicity()==-1) fTree->SetBit(TTree::kForceRead);
if (fManager->GetMultiplicity()>=1) fMultiplicity = fManager->GetMultiplicity();
return kTRUE;
#if 0
// Commenting out to silence Coverity:
// but why was this made inactive?
if (fDimension==1) {
TClass *cl = fVar[0]->EvalClass();
if (cl) {
fObjEval = kTRUE;
}
}
return kTRUE;
#endif
}
ClassImp(TProofDrawHist);
////////////////////////////////////////////////////////////////////////////////
/// Initialization for 1D Histogram.
void TProofDrawHist::Begin1D(TTree *)
{
R__ASSERT(fTreeDrawArgsParser.GetDimension() == 1);
TObject* orig = fTreeDrawArgsParser.GetOriginal();
TH1* hold;
if (fTreeDrawArgsParser.GetNoParameters() == 0 && (hold = dynamic_cast<TH1*> (orig))) {
hold->Reset();
fInput->Add(hold);
} else {
delete orig;
DefVar1D();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Initialization for 2D histogram.
void TProofDrawHist::Begin2D(TTree *)
{
R__ASSERT(fTreeDrawArgsParser.GetDimension() == 2);
TObject* orig = fTreeDrawArgsParser.GetOriginal();
TH2* hold;
if (fTreeDrawArgsParser.GetNoParameters() == 0 && (hold = dynamic_cast<TH2*> (orig))) {
hold->Reset();
fInput->Add(hold);
} else {
delete orig;
DefVar2D();
}
}
////////////////////////////////////////////////////////////////////////////////
/// Initialization for 3D histogram.
void TProofDrawHist::Begin3D(TTree *)
{
R__ASSERT(fTreeDrawArgsParser.GetDimension() == 3);
TObject* orig = fTreeDrawArgsParser.GetOriginal();
TH3* hold;
if ((hold = dynamic_cast<TH3*> (orig)) && fTreeDrawArgsParser.GetNoParameters() == 0) {
hold->Reset();
fInput->Add(hold);
} else {
delete orig;
DefVar3D();
}
}
////////////////////////////////////////////////////////////////////////////////
/// See TProofDraw::Begin().
void TProofDrawHist::Begin(TTree *tree)
{
PDB(kDraw,1) Info("Begin","Enter tree = %p", tree);
TObject *os = fInput->FindObject("selection");
TObject *ov = fInput->FindObject("varexp");
if (os && ov) {
fSelection = os->GetTitle();
fInitialExp = ov->GetTitle();
fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
if (fTreeDrawArgsParser.GetObjectName() == "")
fTreeDrawArgsParser.SetObjectName("htemp");
switch (fTreeDrawArgsParser.GetDimension()) {
case 1:
Begin1D(tree);
break;
case 2:
Begin2D(tree);
break;
case 3:
Begin3D(tree);
break;
default:
Error("Begin", "Wrong dimension");
break;
}
}
PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
fTree = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Define vars for 1D Histogram.
void TProofDrawHist::DefVar1D()
{
R__ASSERT(fTreeDrawArgsParser.GetDimension() == 1);
fTreeDrawArgsParser.SetOriginal(0);
TString exp = fTreeDrawArgsParser.GetVarExp();
exp += ">>";
double binsx, minx, maxx;
if (fTreeDrawArgsParser.IsSpecified(0))
gEnv->SetValue("Hist.Binning.1D.x", fTreeDrawArgsParser.GetParameter(0));
binsx = gEnv->GetValue("Hist.Binning.1D.x",100);
minx = fTreeDrawArgsParser.GetIfSpecified(1, 0);
maxx = fTreeDrawArgsParser.GetIfSpecified(2, 0);
exp += fTreeDrawArgsParser.GetObjectName();
exp += '(';
exp += binsx;
exp += ',';
exp += minx;
exp += ',';
exp += maxx;
exp += ')';
fInitialExp = exp;
TNamed *n = dynamic_cast<TNamed*> (fInput->FindObject("varexp"));
if (n)
n->SetTitle(exp);
else
Error("DefVar1D", "Cannot find varexp on the fInput");
if (fTreeDrawArgsParser.GetNoParameters() != 3)
fInput->Add(new TNamed("PROOF_OPTIONS", "rebin"));
}
////////////////////////////////////////////////////////////////////////////////
/// Define variables for 2D histogram.
void TProofDrawHist::DefVar2D()
{
R__ASSERT(fTreeDrawArgsParser.GetDimension() == 2);
fTreeDrawArgsParser.SetOriginal(0);
TString exp = fTreeDrawArgsParser.GetVarExp();
exp += ">>";
double binsx, minx, maxx;
double binsy, miny, maxy;
if (fTreeDrawArgsParser.IsSpecified(0))
gEnv->SetValue("Hist.Binning.2D.x", fTreeDrawArgsParser.GetParameter(0));
if (fTreeDrawArgsParser.IsSpecified(3))
gEnv->SetValue("Hist.Binning.2D.y", fTreeDrawArgsParser.GetParameter(3));
binsx = gEnv->GetValue("Hist.Binning.2D.x",100);
minx = fTreeDrawArgsParser.GetIfSpecified(1, 0);
maxx = fTreeDrawArgsParser.GetIfSpecified(2, 0);
binsy = gEnv->GetValue("Hist.Binning.2D.y",100);
miny = fTreeDrawArgsParser.GetIfSpecified(4, 0);
maxy = fTreeDrawArgsParser.GetIfSpecified(5, 0);
exp += fTreeDrawArgsParser.GetObjectName();
exp += '(';
exp += binsx;
exp += ',';
exp += minx;
exp += ',';
exp += maxx;
exp += ',';
exp += binsy;
exp += ',';
exp += miny;
exp += ',';
exp += maxy;
exp += ')';
fInitialExp = exp;
TNamed *n = dynamic_cast<TNamed*> (fInput->FindObject("varexp"));
if (n)
n->SetTitle(exp);
else
Error("DefVar2D", "Cannot find varexp on the fInput");
if (fTreeDrawArgsParser.GetNoParameters() != 6)
fInput->Add(new TNamed("PROOF_OPTIONS", "rebin"));
}
////////////////////////////////////////////////////////////////////////////////
/// Define variables for 3D histogram.
void TProofDrawHist::DefVar3D()
{
R__ASSERT(fTreeDrawArgsParser.GetDimension() == 3);
fTreeDrawArgsParser.SetOriginal(0);
TString exp = fTreeDrawArgsParser.GetVarExp();
exp += ">>";
double binsx, minx, maxx;
double binsy, miny, maxy;
double binsz, minz, maxz;
if (fTreeDrawArgsParser.IsSpecified(0))
gEnv->SetValue("Hist.Binning.3D.x", fTreeDrawArgsParser.GetParameter(0));
if (fTreeDrawArgsParser.IsSpecified(3))
gEnv->SetValue("Hist.Binning.3D.y", fTreeDrawArgsParser.GetParameter(3));
if (fTreeDrawArgsParser.IsSpecified(6))
gEnv->SetValue("Hist.Binning.3D.z", fTreeDrawArgsParser.GetParameter(6));
binsx = gEnv->GetValue("Hist.Binning.3D.x",100);
minx = fTreeDrawArgsParser.GetIfSpecified(1, 0);
maxx = fTreeDrawArgsParser.GetIfSpecified(2, 0);
binsy = gEnv->GetValue("Hist.Binning.3D.y",100);
miny = fTreeDrawArgsParser.GetIfSpecified(4, 0);
maxy = fTreeDrawArgsParser.GetIfSpecified(5, 0);
binsz = gEnv->GetValue("Hist.Binning.3D.z",100);
minz = fTreeDrawArgsParser.GetIfSpecified(7, 0);
maxz = fTreeDrawArgsParser.GetIfSpecified(8, 0);
exp += fTreeDrawArgsParser.GetObjectName();
exp += '(';
exp += binsx;
exp += ',';
exp += minx;
exp += ',';
exp += maxx;
exp += ',';
exp += binsy;
exp += ',';
exp += miny;
exp += ',';
exp += maxy;
exp += ',';
exp += binsz;
exp += ',';
exp += minz;
exp += ',';
exp += maxz;
exp += ')';
fInitialExp = exp;
TNamed *n = dynamic_cast<TNamed*> (fInput->FindObject("varexp"));
if (n)
n->SetTitle(exp);
else
Error("DefVar3D", "Cannot find varexp on the fInput");
if (fTreeDrawArgsParser.GetNoParameters() != 9)
fInput->Add(new TNamed("PROOF_OPTIONS", "rebin"));
}
////////////////////////////////////////////////////////////////////////////////
/// Define variables according to arguments.
void TProofDrawHist::DefVar()
{
PDB(kDraw,1) Info("DefVar","Enter");
TObject *os = fInput->FindObject("selection");
TObject *ov = fInput->FindObject("varexp");
if (os && ov) {
fSelection = os->GetTitle();
fInitialExp = ov->GetTitle();
fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
if (fTreeDrawArgsParser.GetObjectName() == "")
fTreeDrawArgsParser.SetObjectName("htemp");
switch (fTreeDrawArgsParser.GetDimension()) {
case 1:
DefVar1D();
break;
case 2:
DefVar2D();
break;
case 3:
DefVar3D();
break;
default:
Error("DefVar", "Wrong dimension");
break;
}
}
PDB(kDraw,1) Info("DefVar","selection: %s", fSelection.Data());
PDB(kDraw,1) Info("DefVar","varexp: %s", fInitialExp.Data());
fTree = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// See TProofDraw::Init().
void TProofDrawHist::Init(TTree *tree)
{
PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
if (fTree == 0) {
if (!dynamic_cast<TH1*> (fTreeDrawArgsParser.GetOriginal())) {
fHistogram->SetLineColor(tree->GetLineColor());
fHistogram->SetLineWidth(tree->GetLineWidth());
fHistogram->SetLineStyle(tree->GetLineStyle());
fHistogram->SetFillColor(tree->GetFillColor());
fHistogram->SetFillStyle(tree->GetFillStyle());
fHistogram->SetMarkerStyle(tree->GetMarkerStyle());
fHistogram->SetMarkerColor(tree->GetMarkerColor());
fHistogram->SetMarkerSize(tree->GetMarkerSize());
}
}
fTree = tree;
CompileVariables();
}
////////////////////////////////////////////////////////////////////////////////
/// See TProofDraw::SlaveBegin().
void TProofDrawHist::SlaveBegin(TTree *tree)
{
PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
// Get the weight
TProofDraw::FillWeight();
TObject *os = fInput->FindObject("selection");
TObject *ov = fInput->FindObject("varexp");
if (os && ov) {
fSelection = os->GetTitle();
fInitialExp = ov->GetTitle();
SafeDelete(fHistogram);
fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
fDimension = fTreeDrawArgsParser.GetDimension();
TString exp = fTreeDrawArgsParser.GetExp();
const char *objname = fTreeDrawArgsParser.GetObjectName();
if (objname && strlen(objname) > 0 && strcmp(objname, "htemp")) {
TH1 *hist = dynamic_cast<TH1*> (fInput->FindObject(objname));
if (hist) {
fHistogram = (TH1 *) hist->Clone();
PDB(kDraw,1) Info("SlaveBegin","original histogram found");
} else {
PDB(kDraw,1) Info("SlaveBegin", "original object '%s' not found"
" or it is not a histogram", objname);
}
}
// Create the histogram if not found in the input list
if (!fHistogram) {
Int_t countx = 100; double minx = 0, maxx = 0;
Int_t county = 100; double miny = 0, maxy = 0;
Int_t countz = 100; double minz = 0, maxz = 0;
if (fTreeDrawArgsParser.GetNoParameters() != 0) {
countx = (Int_t) fTreeDrawArgsParser.GetIfSpecified(0, countx);
county = (Int_t) fTreeDrawArgsParser.GetIfSpecified(3, county);
countz = (Int_t) fTreeDrawArgsParser.GetIfSpecified(6, countz);
minx = fTreeDrawArgsParser.GetIfSpecified(1, minx);
maxx = fTreeDrawArgsParser.GetIfSpecified(2, maxx);
miny = fTreeDrawArgsParser.GetIfSpecified(4, miny);
maxy = fTreeDrawArgsParser.GetIfSpecified(5, maxy);
minz = fTreeDrawArgsParser.GetIfSpecified(7, minz);
maxz = fTreeDrawArgsParser.GetIfSpecified(8, maxz);
}
if (fTreeDrawArgsParser.GetNoParameters() != 3*fDimension)
Error("SlaveBegin", "Impossible - Wrong number of parameters");
if (fDimension == 1)
fHistogram = new TH1F(fTreeDrawArgsParser.GetObjectName(),
fTreeDrawArgsParser.GetObjectTitle(),
countx, minx, maxx);
else if (fDimension == 2){
fHistogram = new TH2F(fTreeDrawArgsParser.GetObjectName(),
fTreeDrawArgsParser.GetObjectTitle(),
countx, minx, maxx,
county, miny, maxy);
}
else if (fDimension == 3) {
fHistogram = new TH3F(fTreeDrawArgsParser.GetObjectName(),
fTreeDrawArgsParser.GetObjectTitle(),
countx, minx, maxx,
county, miny, maxy,
countz, minz, maxz);
} else {
Info("Begin", "Wrong dimension");
return; // FIXME: end the session
}
if (minx >= maxx)
fHistogram->SetBuffer(TH1::GetDefaultBufferSize());
if (TNamed *opt = dynamic_cast<TNamed*> (fInput->FindObject("PROOF_OPTIONS"))) {
if (strstr(opt->GetTitle(), "rebin"))
fHistogram->SetCanExtend(TH1::kAllAxes);
}
}
fHistogram->SetDirectory(0); // take ownership
fOutput->Add(fHistogram); // release ownership
}
fTree = 0;
PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
}
////////////////////////////////////////////////////////////////////////////////
/// Fills the histgram with given values.
void TProofDrawHist::DoFill(Long64_t, Double_t w, const Double_t *v)
{
if (fDimension == 1)
fHistogram->Fill(v[0], w);
else if (fDimension == 2)
((TH2F *)fHistogram)->Fill(v[1], v[0], w);
else if (fDimension == 3)
((TH3F *)fHistogram)->Fill(v[2], v[1], v[0], w);
}
////////////////////////////////////////////////////////////////////////////////
/// See TProofDraw::Terminate().
void TProofDrawHist::Terminate(void)
{
PDB(kDraw,1) Info("Terminate","Enter");
TProofDraw::Terminate();
if (!fStatus)
return;
fHistogram = (TH1F *) fOutput->FindObject(fTreeDrawArgsParser.GetObjectName());
if (fHistogram) {
SetStatus((Int_t) fHistogram->GetEntries());
TH1 *h = 0;
if ((h = dynamic_cast<TH1*> (fTreeDrawArgsParser.GetOriginal()))) {
if (!fTreeDrawArgsParser.GetAdd())
h->Reset();
TList l;
l.Add(fHistogram);
h->Merge(&l);
l.Remove(fHistogram);
fOutput->Remove(fHistogram);
delete fHistogram;
} else {
// Set the title
fHistogram->SetTitle(fTreeDrawArgsParser.GetObjectTitle());
h = fHistogram;
}
if (fTreeDrawArgsParser.GetShouldDraw()) {
// Choose the right canvas
SetCanvas(h->GetName());
// Draw
SetDrawAtt(h);
h->Draw(fOption.Data());
}
}
fHistogram = 0;
}
ClassImp(TProofDrawEventList);
////////////////////////////////////////////////////////////////////////////////
/// See TProofDraw::Init().
void TProofDrawEventList::Init(TTree *tree)
{
PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
if (fTree) { // new tree is being set
if (!fElist)
Error("Init", "Impossible - fElist cannot be 0");
fEventLists->Add(fElist);
}
fElist = new TEventList(tree->GetDirectory()->GetName(), tree->GetName());
fTree = tree;
CompileVariables();
}
////////////////////////////////////////////////////////////////////////////////
/// See TProofDraw::SlaveBegin().
void TProofDrawEventList::SlaveBegin(TTree *tree)
{
PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
// Get the weight
TProofDraw::FillWeight();
TObject *os = fInput->FindObject("selection");
TObject *ov = fInput->FindObject("varexp");
if (os && ov) {
fSelection = os->GetTitle();
fInitialExp = ov->GetTitle();
fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
SafeDelete(fEventLists);
fDimension = 0;
fTree = 0;
fEventLists = new TList();
fEventLists->SetName("PROOF_EventListsList");
fOutput->Add(fEventLists);
}
PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
}
////////////////////////////////////////////////////////////////////////////////
/// Fills the eventlist with given values.
void TProofDrawEventList::DoFill(Long64_t entry, Double_t , const Double_t *)
{
fElist->Enter(entry);
}
////////////////////////////////////////////////////////////////////////////////
/// See TProofDraw::SlaveTerminate().
void TProofDrawEventList::SlaveTerminate(void)
{
PDB(kDraw,1) Info("SlaveTerminate","Enter");
fEventLists->Add(fElist);
}
////////////////////////////////////////////////////////////////////////////////
/// See TProofDraw::Terminate().
void TProofDrawEventList::Terminate(void)
{
TProofDraw::Terminate(); // take care of fStatus
if (!fStatus)
return;
fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
TEventList *el = dynamic_cast<TEventList*> (fOutput->FindObject("PROOF_EventList"));
if (el) {
el->SetName(fInitialExp.Data()+2);
SetStatus(el->GetN());
if (TEventList* old = dynamic_cast<TEventList*> (fTreeDrawArgsParser.GetOriginal())) {
if (!fTreeDrawArgsParser.GetAdd())
old->Reset();
old->Add(el);
fOutput->Remove(el);
delete el;
}
}
else
Error("Terminate", "Cannot find output EventList");