TProofDraw.cxx

Go to the documentation of this file.
00001 // @(#)root/proofplayer:$Id: TProofDraw.cxx 36086 2010-10-05 16:15:41Z ganis $
00002 // Author: Maarten Ballintijn, Marek Biskup  24/09/2003
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2003, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // TProofDraw                                                           //
00015 //                                                                      //
00016 // Implement Tree drawing using PROOF.                                  //
00017 //                                                                      //
00018 //////////////////////////////////////////////////////////////////////////
00019 
00020 
00021 #include "TProofDraw.h"
00022 #include "TAttFill.h"
00023 #include "TAttLine.h"
00024 #include "TAttMarker.h"
00025 #include "TCanvas.h"
00026 #include "TClass.h"
00027 #include "TError.h"
00028 #include "TH1F.h"
00029 #include "TH2F.h"
00030 #include "TH3F.h"
00031 #include "TProof.h"
00032 #include "TProofDebug.h"
00033 #include "TStatus.h"
00034 #include "TTreeDrawArgsParser.h"
00035 #include "TTreeFormula.h"
00036 #include "TTreeFormulaManager.h"
00037 #include "TTree.h"
00038 #include "TEventList.h"
00039 #include "TEntryList.h"
00040 #include "TProfile.h"
00041 #include "TProfile2D.h"
00042 #include "TEnv.h"
00043 #include "TNamed.h"
00044 #include "TGraph.h"
00045 #include "TPolyMarker3D.h"
00046 #include "TVirtualPad.h"
00047 #include "THLimitsFinder.h"
00048 #include "TView.h"
00049 #include "TStyle.h"
00050 #include "TDirectory.h"
00051 #include "TROOT.h"
00052 
00053 #include <algorithm>
00054 using namespace std;
00055 
00056 
00057 // Simple call to draw a canvas on the fly from applications loading
00058 // this plug-in dynamically
00059 extern "C" {
00060    Int_t DrawCanvas(TObject *obj)
00061    {
00062       // Draw the object if deriving from a canvas
00063 
00064       if (TCanvas* c = dynamic_cast<TCanvas *> (obj)) {
00065          c->Draw();
00066          return 0;
00067       }
00068       // Not a TCanvas
00069       return 1;
00070    }
00071 }
00072 
00073 // Simple call to parse arguments on the fly from applications loading
00074 // this plug-in dynamically
00075 extern "C" {
00076    Int_t GetDrawArgs(const char *var, const char *sel, Option_t *opt,
00077                      TString &selector, TString &objname)
00078    {
00079       // Parse arguments with the help of TTreeDrawArgsParser
00080 
00081       TTreeDrawArgsParser info;
00082       info.Parse(var, sel, opt);
00083       selector = info.GetProofSelectorName();
00084       objname = info.GetObjectName();
00085 
00086       // Done
00087       return 0;
00088    }
00089 }
00090 
00091 // Simple call to create destroy a 'named' canvas
00092 extern "C" {
00093    void FeedBackCanvas(const char *name, Bool_t create)
00094    {
00095       // Create or destroy canvas 'name'
00096 
00097       if (create) {
00098          new TCanvas(name, "FeedBack", 800,30,700,500);
00099       } else {
00100          TCanvas *c = (TCanvas *) gROOT->GetListOfCanvases()->FindObject(name);
00101          if (c) delete c;
00102       }
00103       // Done
00104       return;
00105    }
00106 }
00107 
00108 ClassImp(TProofDraw)
00109 
00110 //______________________________________________________________________________
00111 TProofDraw::TProofDraw()
00112    : fStatus(0), fManager(0), fTree(0)
00113 {
00114    // Constructor.
00115 
00116    fVar[0]         = 0;
00117    fVar[1]         = 0;
00118    fVar[2]         = 0;
00119    fVar[3]         = 0;
00120    fManager        = 0;
00121    fMultiplicity   = 0;
00122    fSelect         = 0;
00123    fObjEval        = kFALSE;
00124    fDimension      = 0;
00125 }
00126 
00127 
00128 //______________________________________________________________________________
00129 TProofDraw::~TProofDraw()
00130 {
00131    // Destructor.
00132 
00133    ClearFormula();
00134 }
00135 
00136 
00137 //______________________________________________________________________________
00138 void TProofDraw::Init(TTree *tree)
00139 {
00140    // Init the tree.
00141 
00142    PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
00143    fTree = tree;
00144    CompileVariables();
00145 }
00146 
00147 
00148 //______________________________________________________________________________
00149 Bool_t TProofDraw::Notify()
00150 {
00151    // Called when a new tree is loaded.
00152 
00153    PDB(kDraw,1) Info("Notify","Enter");
00154    if (fStatus == 0) {
00155       if (!(fStatus = dynamic_cast<TStatus*>(fOutput->FindObject("PROOF_Status"))))
00156          return kFALSE;
00157    }
00158    if (!fStatus->IsOk()) return kFALSE;
00159    if (!fManager) return kFALSE;
00160    fManager->UpdateFormulaLeaves();
00161    return kTRUE;
00162 }
00163 
00164 //______________________________________________________________________________
00165 void TProofDraw::Begin(TTree *tree)
00166 {
00167    // Executed by the client before processing.
00168 
00169    PDB(kDraw,1) Info("Begin","Enter tree = %p", tree);
00170 
00171    fSelection = fInput->FindObject("selection")->GetTitle();
00172    fInitialExp = fInput->FindObject("varexp")->GetTitle();
00173    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
00174    if (fTreeDrawArgsParser.GetObjectName() == "")
00175       fTreeDrawArgsParser.SetObjectName("htemp");
00176 
00177    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
00178    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
00179    fTree = 0;
00180 }
00181 
00182 
00183 //______________________________________________________________________________
00184 void TProofDraw::SlaveBegin(TTree* /*tree*/)
00185 {
00186    // Executed by each slave before processing.
00187 }
00188 
00189 
00190 //______________________________________________________________________________
00191 Bool_t TProofDraw::ProcessSingle(Long64_t entry, Int_t i)
00192 {
00193    // Processes a single variable from an entry.
00194 
00195    Double_t w;
00196    Double_t v[4]; //[TTreeDrawArgsParser::fgMaxDimension];
00197 
00198    if (fSelect)
00199       w = fSelect->EvalInstance(i);
00200    else
00201       w = 1.0;
00202 
00203    PDB(kDraw,3) Info("ProcessSingle","w[%d] = %f", i, w);
00204 
00205    if (w != 0.0) {
00206       R__ASSERT(fDimension <= TTreeDrawArgsParser::GetMaxDimension());
00207       for (int j = 0; j < fDimension; j++)
00208          v[j] = fVar[j]->EvalInstance(i);
00209       if (fDimension >= 1)
00210          PDB(kDraw,4) Info("Process","v[0] = %f", v[0]);
00211       DoFill(entry, w, v);
00212    }
00213    return kTRUE;
00214 }
00215 
00216 
00217 //______________________________________________________________________________
00218 Bool_t TProofDraw::Process(Long64_t entry)
00219 {
00220    // Executed for each entry.
00221 
00222    PDB(kDraw,3) Info("Process", "enter entry = %lld", entry);
00223 
00224    fTree->LoadTree(entry);
00225    Int_t ndata = fManager->GetNdata();
00226 
00227    PDB(kDraw,3) Info("Process","ndata = %d", ndata);
00228 
00229    for (Int_t i=0;i<ndata;i++) {
00230       ProcessSingle(entry, i);
00231    }
00232    return kTRUE;
00233 }
00234 
00235 
00236 //______________________________________________________________________________
00237 void TProofDraw::SlaveTerminate(void)
00238 {
00239    // Executed by each slave after the processing has finished,
00240    // before returning the results to the client.
00241 
00242    PDB(kDraw,1) Info("SlaveTerminate","Enter");
00243 }
00244 
00245 
00246 //______________________________________________________________________________
00247 void TProofDraw::Terminate(void)
00248 {
00249    // Executed by the client after getting the processing retults.
00250 
00251    PDB(kDraw,1) Info("Terminate","Enter");
00252    if (fStatus == 0) {
00253       fStatus = dynamic_cast<TStatus*>(fOutput->FindObject("PROOF_Status"));
00254       if (fStatus == 0) {
00255          // did not run selector, error messages were already printed
00256          return;
00257       }
00258    }
00259 
00260    if (!fStatus->IsOk()) {
00261       fStatus->Print();
00262       return;
00263    }
00264 }
00265 
00266 
00267 //______________________________________________________________________________
00268 void TProofDraw::ClearFormula()
00269 {
00270    // Delete internal buffers.
00271 
00272    ResetBit(kWarn);
00273    for (Int_t i = 0; i < 4; i++)
00274       SafeDelete(fVar[i]);
00275    SafeDelete(fSelect);
00276    fManager = 0;  // This is intentional. The manager is deleted when the last formula it manages
00277                   // is deleted. This is unusual but was usefull for backward compatibility.
00278    fMultiplicity = 0;
00279 }
00280 
00281 //______________________________________________________________________________
00282 void TProofDraw::SetCanvas(const char *objname)
00283 {
00284    // Move to a canvas named <name>_canvas; create the canvas if not existing.
00285    // Used to avoid screwing up existing plots when non default names are used
00286    // for the final objects
00287 
00288    TString name = objname;
00289    if (!gPad) {
00290       gROOT->MakeDefCanvas();
00291       gPad->SetName(name);
00292       PDB(kDraw,2) Info("SetCanvas", "created canvas %s", name.Data());
00293    } else {
00294       PDB(kDraw,2)
00295          Info("SetCanvas", "using canvas %s", gPad->GetName());
00296    }
00297 }
00298 
00299 //______________________________________________________________________________
00300 void TProofDraw::SetDrawAtt(TObject *o)
00301 {
00302    // Set the drawing attributes from the input list
00303 
00304    Int_t att = -1;
00305    PDB(kDraw,2) Info("SetDrawAtt", "setting attributes for %s", o->GetName());
00306 
00307    // Line Attributes
00308    TAttLine *al = dynamic_cast<TAttLine *> (o);
00309    if (al) {
00310       // Line color
00311       if (TProof::GetParameter(fInput, "PROOF_LineColor", att) == 0)
00312          al->SetLineColor((Color_t)att);
00313       // Line style
00314       if (TProof::GetParameter(fInput, "PROOF_LineStyle", att) == 0)
00315          al->SetLineStyle((Style_t)att);
00316       // Line color
00317       if (TProof::GetParameter(fInput, "PROOF_LineWidth", att) == 0)
00318          al->SetLineWidth((Width_t)att);
00319       PDB(kDraw,2) Info("SetDrawAtt", "line:   c:%d, s:%d, wd:%d",
00320                                       al->GetLineColor(), al->GetLineStyle(), al->GetLineWidth());
00321    }
00322 
00323    // Marker Attributes
00324    TAttMarker *am = dynamic_cast<TAttMarker *> (o);
00325    if (am) {
00326       // Marker color
00327       if (TProof::GetParameter(fInput, "PROOF_MarkerColor", att) == 0)
00328          am->SetMarkerColor((Color_t)att);
00329       // Marker size
00330       if (TProof::GetParameter(fInput, "PROOF_MarkerSize", att) == 0) {
00331          Info("SetDrawAtt", "att: %d", att);
00332          Float_t msz = (Float_t)att / 1000.;
00333          am->SetMarkerSize((Size_t)msz);
00334       }
00335       // Marker style
00336       if (TProof::GetParameter(fInput, "PROOF_MarkerStyle", att) == 0)
00337          am->SetMarkerStyle((Style_t)att);
00338       PDB(kDraw,2) Info("SetDrawAtt", "marker: c:%d, s:%d, sz:%f",
00339                                       am->GetMarkerColor(), am->GetMarkerStyle(), am->GetMarkerSize());
00340    }
00341 
00342    // Area Fill Attributes
00343    TAttFill *af = dynamic_cast<TAttFill *> (o);
00344    if (af) {
00345       // Area fill color
00346       if (TProof::GetParameter(fInput, "PROOF_FillColor", att) == 0)
00347          af->SetFillColor((Color_t)att);
00348       // Area fill style
00349       if (TProof::GetParameter(fInput, "PROOF_FillStyle", att) == 0)
00350          af->SetFillStyle((Style_t)att);
00351       PDB(kDraw,2) Info("SetDrawAtt", "area:   c:%d, s:%d",
00352                                       af->GetFillColor(), af->GetFillStyle());
00353    }
00354 }
00355 
00356 //______________________________________________________________________________
00357 void TProofDraw::SetError(const char *sub, const char *mesg)
00358 {
00359    // Sets the error status.
00360 
00361    if (fStatus == 0) {
00362       if (!(fStatus = dynamic_cast<TStatus*>(fOutput->FindObject("PROOF_Status"))))
00363          return;
00364    }
00365 
00366    TString m;
00367    m.Form("%s::%s: %s", IsA()->GetName(), sub, mesg);
00368    fStatus->Add(m);
00369 }
00370 
00371 
00372 //______________________________________________________________________________
00373 Bool_t TProofDraw::CompileVariables()
00374 {
00375    // Compiles each variable from fTreeDrawArgsParser for the tree fTree.
00376    // Return kFALSE if any of the variable is not compilable.
00377 
00378    fDimension = fTreeDrawArgsParser.GetDimension();
00379    fMultiplicity = 0;
00380    fObjEval = kFALSE;
00381    if (strlen(fTreeDrawArgsParser.GetSelection())) {
00382       fSelect = new TTreeFormula("Selection", fTreeDrawArgsParser.GetSelection(), fTree);
00383       fSelect->SetQuickLoad(kTRUE);
00384       if (!fSelect->GetNdim()) {delete fSelect; fSelect = 0; return kFALSE; }
00385    }
00386 
00387    fManager = new TTreeFormulaManager();
00388    if (fSelect) fManager->Add(fSelect);
00389    fTree->ResetBit(TTree::kForceRead);
00390 
00391    for (int i = 0; i < fDimension; i++) {
00392       fVar[i] = new TTreeFormula(Form("Var%d", i),fTreeDrawArgsParser.GetVarExp(i),fTree);
00393       fVar[i]->SetQuickLoad(kTRUE);
00394       if (!fVar[i]->GetNdim()) {
00395          ClearFormula();
00396          Error("CompileVariables", "Error compiling expression");
00397          SetError("CompileVariables", "Error compiling variables");
00398 
00399          return kFALSE;
00400       }
00401       fManager->Add(fVar[i]);
00402    }
00403    
00404    fManager->Sync();
00405    if (fManager->GetMultiplicity()==-1) fTree->SetBit(TTree::kForceRead);
00406    if (fManager->GetMultiplicity()>=1) fMultiplicity = fManager->GetMultiplicity();
00407 
00408    return kTRUE;
00409 #if 0
00410    // Commenting out to silence Coverity:
00411    // but why was this made inactive? 
00412    if (fDimension==1) {
00413       TClass *cl = fVar[0]->EvalClass();
00414       if (cl) {
00415          fObjEval = kTRUE;
00416       }
00417    }
00418    return kTRUE;
00419 #endif
00420 }
00421 
00422 
00423 ClassImp(TProofDrawHist)
00424 
00425 
00426 //______________________________________________________________________________
00427 void TProofDrawHist::Begin1D(TTree *)
00428 {
00429    // Initialization for 1D Histogram.
00430 
00431    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 1);
00432    TObject* orig = fTreeDrawArgsParser.GetOriginal();
00433    TH1* hold;
00434    if (fTreeDrawArgsParser.GetNoParameters() == 0 && (hold = dynamic_cast<TH1*> (orig))) {
00435       TH1* hnew = (TH1*) hold->Clone();
00436       hnew->Reset();
00437       fInput->Add(hnew);
00438    } else {
00439       delete orig;
00440       DefVar1D();
00441    }
00442 }
00443 
00444 
00445 //______________________________________________________________________________
00446 void TProofDrawHist::Begin2D(TTree *)
00447 {
00448    // Initialization for 2D histogram.
00449 
00450    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 2);
00451    TObject* orig = fTreeDrawArgsParser.GetOriginal();
00452    TH2* hold;
00453    if (fTreeDrawArgsParser.GetNoParameters() == 0 && (hold = dynamic_cast<TH2*> (orig))) {
00454       TH2* hnew = (TH2*) hold->Clone();
00455       hnew->Reset();
00456       fInput->Add(hnew);
00457    } else {
00458       delete orig;
00459       DefVar2D();
00460    }
00461 }
00462 
00463 
00464 //______________________________________________________________________________
00465 void TProofDrawHist::Begin3D(TTree *)
00466 {
00467    // Initialization for 3D histogram.
00468 
00469    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 3);
00470    TObject* orig = fTreeDrawArgsParser.GetOriginal();
00471    TH3* hold;
00472    if ((hold = dynamic_cast<TH3*> (orig)) && fTreeDrawArgsParser.GetNoParameters() == 0) {
00473       TH3* hnew = (TH3*) hold->Clone();
00474       hnew->Reset();
00475       fInput->Add(hnew);
00476    } else {
00477       delete orig;
00478       DefVar3D();
00479    }
00480 }
00481 
00482 //______________________________________________________________________________
00483 void TProofDrawHist::Begin(TTree *tree)
00484 {
00485    // See TProofDraw::Begin().
00486 
00487    PDB(kDraw,1) Info("Begin","Enter tree = %p", tree);
00488 
00489    fSelection = fInput->FindObject("selection")->GetTitle();
00490    fInitialExp = fInput->FindObject("varexp")->GetTitle();
00491 
00492    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
00493    if (fTreeDrawArgsParser.GetObjectName() == "")
00494       fTreeDrawArgsParser.SetObjectName("htemp");
00495 
00496    switch (fTreeDrawArgsParser.GetDimension()) {
00497       case 1:
00498          Begin1D(tree);
00499          break;
00500       case 2:
00501          Begin2D(tree);
00502          break;
00503       case 3:
00504          Begin3D(tree);
00505          break;
00506       default:
00507          Error("Begin", "Wrong dimension");
00508          break;
00509    }
00510    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
00511    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
00512    fTree = 0;
00513 }
00514 
00515 //______________________________________________________________________________
00516 void TProofDrawHist::DefVar1D()
00517 {
00518    // Define vars for 1D Histogram.
00519 
00520    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 1);
00521 
00522    fTreeDrawArgsParser.SetOriginal(0);
00523    TString exp = fTreeDrawArgsParser.GetVarExp();
00524    exp += ">>";
00525    double binsx, minx, maxx;
00526    if (fTreeDrawArgsParser.IsSpecified(0))
00527       gEnv->SetValue("Hist.Binning.1D.x", fTreeDrawArgsParser.GetParameter(0));
00528    binsx = gEnv->GetValue("Hist.Binning.1D.x",100);
00529    minx =  fTreeDrawArgsParser.GetIfSpecified(1, 0);
00530    maxx =  fTreeDrawArgsParser.GetIfSpecified(2, 0);
00531    exp += fTreeDrawArgsParser.GetObjectName();
00532    exp += '(';
00533    exp +=      binsx;
00534    exp +=         ',';
00535    exp +=      minx;
00536    exp +=         ',';
00537    exp +=      maxx;
00538    exp += ')';
00539 
00540    fInitialExp = exp;
00541    TNamed *n = dynamic_cast<TNamed*> (fInput->FindObject("varexp"));
00542    if (n)
00543       n->SetTitle(exp);
00544    else
00545       Error("DefVar1D", "Cannot find varexp on the fInput");
00546    if (fTreeDrawArgsParser.GetNoParameters() != 3)
00547       fInput->Add(new TNamed("PROOF_OPTIONS", "rebin"));
00548 }
00549 
00550 //______________________________________________________________________________
00551 void TProofDrawHist::DefVar2D()
00552 {
00553    // Define variables for 2D histogram.
00554 
00555    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 2);
00556 
00557    fTreeDrawArgsParser.SetOriginal(0);
00558    TString exp = fTreeDrawArgsParser.GetVarExp();
00559    exp += ">>";
00560    double binsx, minx, maxx;
00561    double binsy, miny, maxy;
00562    if (fTreeDrawArgsParser.IsSpecified(0))
00563       gEnv->SetValue("Hist.Binning.2D.x", fTreeDrawArgsParser.GetParameter(0));
00564    if (fTreeDrawArgsParser.IsSpecified(3))
00565       gEnv->SetValue("Hist.Binning.2D.y", fTreeDrawArgsParser.GetParameter(3));
00566    binsx = gEnv->GetValue("Hist.Binning.2D.x",100);
00567    minx =  fTreeDrawArgsParser.GetIfSpecified(1, 0);
00568    maxx =  fTreeDrawArgsParser.GetIfSpecified(2, 0);
00569    binsy = gEnv->GetValue("Hist.Binning.2D.y",100);
00570    miny =  fTreeDrawArgsParser.GetIfSpecified(4, 0);
00571    maxy =  fTreeDrawArgsParser.GetIfSpecified(5, 0);
00572    exp += fTreeDrawArgsParser.GetObjectName();
00573    exp += '(';
00574    exp +=      binsx;
00575    exp +=         ',';
00576    exp +=      minx;
00577    exp +=         ',';
00578    exp +=      maxx;
00579    exp += ',';
00580    exp +=      binsy;
00581    exp +=         ',';
00582    exp +=      miny;
00583    exp +=         ',';
00584    exp +=      maxy;
00585    exp += ')';
00586    fInitialExp = exp;
00587    TNamed *n = dynamic_cast<TNamed*> (fInput->FindObject("varexp"));
00588    if (n)
00589       n->SetTitle(exp);
00590    else
00591       Error("DefVar2D", "Cannot find varexp on the fInput");
00592    if (fTreeDrawArgsParser.GetNoParameters() != 6)
00593       fInput->Add(new TNamed("PROOF_OPTIONS", "rebin"));
00594 }
00595 
00596 //______________________________________________________________________________
00597 void TProofDrawHist::DefVar3D()
00598 {
00599    // Define variables for 3D histogram.
00600 
00601    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 3);
00602 
00603    fTreeDrawArgsParser.SetOriginal(0);
00604    TString exp = fTreeDrawArgsParser.GetVarExp();
00605    exp += ">>";
00606    double binsx, minx, maxx;
00607    double binsy, miny, maxy;
00608    double binsz, minz, maxz;
00609    if (fTreeDrawArgsParser.IsSpecified(0))
00610       gEnv->SetValue("Hist.Binning.3D.x", fTreeDrawArgsParser.GetParameter(0));
00611    if (fTreeDrawArgsParser.IsSpecified(3))
00612       gEnv->SetValue("Hist.Binning.3D.y", fTreeDrawArgsParser.GetParameter(3));
00613    if (fTreeDrawArgsParser.IsSpecified(6))
00614       gEnv->SetValue("Hist.Binning.3D.z", fTreeDrawArgsParser.GetParameter(6));
00615    binsx = gEnv->GetValue("Hist.Binning.3D.x",100);
00616    minx =  fTreeDrawArgsParser.GetIfSpecified(1, 0);
00617    maxx =  fTreeDrawArgsParser.GetIfSpecified(2, 0);
00618    binsy = gEnv->GetValue("Hist.Binning.3D.y",100);
00619    miny =  fTreeDrawArgsParser.GetIfSpecified(4, 0);
00620    maxy =  fTreeDrawArgsParser.GetIfSpecified(5, 0);
00621    binsz = gEnv->GetValue("Hist.Binning.3D.z",100);
00622    minz =  fTreeDrawArgsParser.GetIfSpecified(7, 0);
00623    maxz =  fTreeDrawArgsParser.GetIfSpecified(8, 0);
00624    exp += fTreeDrawArgsParser.GetObjectName();
00625    exp += '(';
00626    exp +=      binsx;
00627    exp +=         ',';
00628    exp +=      minx;
00629    exp +=         ',';
00630    exp +=      maxx;
00631    exp += ',';
00632    exp +=      binsy;
00633    exp +=         ',';
00634    exp +=      miny;
00635    exp +=         ',';
00636    exp +=      maxy;
00637    exp += ',';
00638    exp +=      binsz;
00639    exp +=         ',';
00640    exp +=      minz;
00641    exp +=         ',';
00642    exp +=      maxz;
00643    exp += ')';
00644    fInitialExp = exp;
00645    TNamed *n = dynamic_cast<TNamed*> (fInput->FindObject("varexp"));
00646    if (n)
00647       n->SetTitle(exp);
00648    else
00649       Error("DefVar3D", "Cannot find varexp on the fInput");
00650    if (fTreeDrawArgsParser.GetNoParameters() != 9)
00651       fInput->Add(new TNamed("PROOF_OPTIONS", "rebin"));
00652 }
00653 
00654 //______________________________________________________________________________
00655 void TProofDrawHist::DefVar()
00656 {
00657    // Define variables according to arguments.
00658 
00659    PDB(kDraw,1) Info("DefVar","Enter");
00660 
00661    fSelection = fInput->FindObject("selection")->GetTitle();
00662    fInitialExp = fInput->FindObject("varexp")->GetTitle();
00663 
00664    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
00665    if (fTreeDrawArgsParser.GetObjectName() == "")
00666       fTreeDrawArgsParser.SetObjectName("htemp");
00667 
00668    switch (fTreeDrawArgsParser.GetDimension()) {
00669       case 1:
00670          DefVar1D();
00671          break;
00672       case 2:
00673          DefVar2D();
00674          break;
00675       case 3:
00676          DefVar3D();
00677          break;
00678       default:
00679          Error("DefVar", "Wrong dimension");
00680          break;
00681    }
00682    PDB(kDraw,1) Info("DefVar","selection: %s", fSelection.Data());
00683    PDB(kDraw,1) Info("DefVar","varexp: %s", fInitialExp.Data());
00684    fTree = 0;
00685 }
00686 
00687 //______________________________________________________________________________
00688 void TProofDrawHist::Init(TTree *tree)
00689 {
00690    // See TProofDraw::Init().
00691 
00692    PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
00693    if (fTree == 0) {
00694       if (!dynamic_cast<TH1*> (fTreeDrawArgsParser.GetOriginal())) {
00695          fHistogram->SetLineColor(tree->GetLineColor());
00696          fHistogram->SetLineWidth(tree->GetLineWidth());
00697          fHistogram->SetLineStyle(tree->GetLineStyle());
00698          fHistogram->SetFillColor(tree->GetFillColor());
00699          fHistogram->SetFillStyle(tree->GetFillStyle());
00700          fHistogram->SetMarkerStyle(tree->GetMarkerStyle());
00701          fHistogram->SetMarkerColor(tree->GetMarkerColor());
00702          fHistogram->SetMarkerSize(tree->GetMarkerSize());
00703       }
00704    }
00705    fTree = tree;
00706    CompileVariables();
00707 }
00708 
00709 
00710 //______________________________________________________________________________
00711 void TProofDrawHist::SlaveBegin(TTree *tree)
00712 {
00713    // See TProofDraw::SlaveBegin().
00714 
00715    PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
00716 
00717    fSelection = fInput->FindObject("selection")->GetTitle();
00718    fInitialExp = fInput->FindObject("varexp")->GetTitle();
00719 
00720    SafeDelete(fHistogram);
00721 
00722    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
00723    fDimension = fTreeDrawArgsParser.GetDimension();
00724    TString exp = fTreeDrawArgsParser.GetExp();
00725    const char *objname = fTreeDrawArgsParser.GetObjectName();
00726    if (objname && strlen(objname) > 0 && strcmp(objname, "htemp")) {
00727       TH1 *hist = dynamic_cast<TH1*> (fInput->FindObject(objname));
00728       if (hist) {
00729          fHistogram = (TH1 *) hist->Clone();
00730          PDB(kDraw,1) Info("SlaveBegin","original histogram found");
00731       } else {
00732          PDB(kDraw,1) Info("SlaveBegin", "original object '%s' not found"
00733                                          " or it is not a histogram", objname);
00734       }
00735    }
00736 
00737    // Create the histogram if not found in the input list
00738    if (!fHistogram) {
00739       Int_t countx = 100; double minx = 0, maxx = 0;
00740       Int_t county = 100; double miny = 0, maxy = 0;
00741       Int_t countz = 100; double minz = 0, maxz = 0;
00742       if (fTreeDrawArgsParser.GetNoParameters() != 0) {
00743          countx = (Int_t) fTreeDrawArgsParser.GetIfSpecified(0, countx);
00744          county = (Int_t) fTreeDrawArgsParser.GetIfSpecified(3, county);
00745          countz = (Int_t) fTreeDrawArgsParser.GetIfSpecified(6, countz);
00746          minx =  fTreeDrawArgsParser.GetIfSpecified(1, minx);
00747          maxx =  fTreeDrawArgsParser.GetIfSpecified(2, maxx);
00748          miny =  fTreeDrawArgsParser.GetIfSpecified(4, miny);
00749          maxy =  fTreeDrawArgsParser.GetIfSpecified(5, maxy);
00750          minz =  fTreeDrawArgsParser.GetIfSpecified(7, minz);
00751          maxz =  fTreeDrawArgsParser.GetIfSpecified(8, maxz);
00752       }
00753       if (fTreeDrawArgsParser.GetNoParameters() != 3*fDimension)
00754          Error("SlaveBegin", "Impossible - Wrong number of parameters");
00755 
00756       if (fDimension == 1)
00757          fHistogram = new TH1F(fTreeDrawArgsParser.GetObjectName(),
00758                               fTreeDrawArgsParser.GetObjectTitle(),
00759                               countx, minx, maxx);
00760       else if (fDimension == 2){
00761          fHistogram = new TH2F(fTreeDrawArgsParser.GetObjectName(),
00762                               fTreeDrawArgsParser.GetObjectTitle(),
00763                               countx, minx, maxx,
00764                               county, miny, maxy);
00765       }
00766       else if (fDimension == 3) {
00767          fHistogram = new TH3F(fTreeDrawArgsParser.GetObjectName(),
00768                               fTreeDrawArgsParser.GetObjectTitle(),
00769                               countx, minx, maxx,
00770                               county, miny, maxy,
00771                               countz, minz, maxz);
00772       } else {
00773          Info("Begin", "Wrong dimension");
00774          return;        // FIXME: end the session
00775       }
00776       if (minx >= maxx)
00777          fHistogram->SetBuffer(TH1::GetDefaultBufferSize());
00778       if (TNamed *opt = dynamic_cast<TNamed*> (fInput->FindObject("PROOF_OPTIONS"))) {
00779          if (strstr(opt->GetTitle(), "rebin"))
00780             fHistogram->SetBit(TH1::kCanRebin);
00781       }
00782    }
00783    fHistogram->SetDirectory(0);   // take ownership
00784    fOutput->Add(fHistogram);      // release ownership
00785 
00786    fTree = 0;
00787    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
00788    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
00789 }
00790 
00791 
00792 //______________________________________________________________________________
00793 void TProofDrawHist::DoFill(Long64_t, Double_t w, const Double_t *v)
00794 {
00795    // Fills the histgram with given values.
00796 
00797    if (fDimension == 1)
00798       fHistogram->Fill(v[0], w);
00799    else if (fDimension == 2)
00800       ((TH2F *)fHistogram)->Fill(v[1], v[0], w);
00801    else if (fDimension == 3)
00802       ((TH3F *)fHistogram)->Fill(v[2], v[1], v[0], w);
00803 }
00804 
00805 
00806 //______________________________________________________________________________
00807 void TProofDrawHist::Terminate(void)
00808 {
00809    // See TProofDraw::Terminate().
00810 
00811    PDB(kDraw,1) Info("Terminate","Enter");
00812    TProofDraw::Terminate();
00813    if (!fStatus)
00814       return;
00815 
00816    fHistogram = (TH1F *) fOutput->FindObject(fTreeDrawArgsParser.GetObjectName());
00817    if (fHistogram) {
00818       SetStatus((Int_t) fHistogram->GetEntries());
00819       TH1 *h = 0;
00820       if ((h = dynamic_cast<TH1*> (fTreeDrawArgsParser.GetOriginal()))) {
00821          if (!fTreeDrawArgsParser.GetAdd())
00822             h->Reset();
00823          TList l;
00824          l.Add(fHistogram);
00825          h->Merge(&l);
00826          fOutput->Remove(fHistogram);
00827          delete fHistogram;
00828       } else {
00829          // Set the title
00830          fHistogram->SetTitle(fTreeDrawArgsParser.GetObjectTitle());
00831          h = fHistogram;
00832       }
00833       if (fTreeDrawArgsParser.GetShouldDraw()) {
00834          // Choose the right canvas
00835          SetCanvas(h->GetName());
00836          // Draw
00837          SetDrawAtt(h);
00838          h->Draw(fOption.Data());
00839       }
00840    }
00841    fHistogram = 0;
00842 }
00843 
00844 ClassImp(TProofDrawEventList)
00845 
00846 //______________________________________________________________________________
00847 TProofDrawEventList::~TProofDrawEventList()
00848 {
00849    // Destructor.
00850 
00851    SafeDelete(fElist);
00852    SafeDelete(fEventLists);
00853 }
00854 
00855 
00856 //______________________________________________________________________________
00857 void TProofDrawEventList::Init(TTree *tree)
00858 {
00859    // See TProofDraw::Init().
00860 
00861    PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
00862 
00863    if (fTree) {      // new tree is being set
00864       if (!fElist)
00865          Error("Init", "Impossible - fElist cannot be 0");
00866       fEventLists->Add(fElist);
00867    }
00868    fElist = new TEventList(tree->GetDirectory()->GetName(), tree->GetName());
00869    fTree = tree;
00870    CompileVariables();
00871 }
00872 
00873 
00874 //______________________________________________________________________________
00875 void TProofDrawEventList::SlaveBegin(TTree *tree)
00876 {
00877    // See TProofDraw::SlaveBegin().
00878 
00879    PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
00880 
00881    fSelection = fInput->FindObject("selection")->GetTitle();
00882    fInitialExp = fInput->FindObject("varexp")->GetTitle();
00883 
00884    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
00885 
00886    SafeDelete(fEventLists);
00887 
00888    fDimension = 0;
00889    fTree = 0;
00890    fEventLists = new TList();
00891    fEventLists->SetName("PROOF_EventListsList");
00892    fOutput->Add(fEventLists);
00893 
00894    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
00895    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
00896 }
00897 
00898 
00899 //______________________________________________________________________________
00900 void TProofDrawEventList::DoFill(Long64_t entry, Double_t , const Double_t *)
00901 {
00902    // Fills the eventlist with given values.
00903 
00904    fElist->Enter(entry);
00905 }
00906 
00907 
00908 //______________________________________________________________________________
00909 void TProofDrawEventList::SlaveTerminate(void)
00910 {
00911    // See TProofDraw::SlaveTerminate().
00912 
00913    PDB(kDraw,1) Info("SlaveTerminate","Enter");
00914    fEventLists->Add(fElist);
00915    fEventLists = 0;
00916    fElist = 0;
00917 }
00918 
00919 
00920 //______________________________________________________________________________
00921 void TProofDrawEventList::Terminate(void)
00922 {
00923    // See TProofDraw::Terminate().
00924 
00925    TProofDraw::Terminate();   // take care of fStatus
00926    if (!fStatus)
00927       return;
00928 
00929    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
00930 
00931    TEventList *el = dynamic_cast<TEventList*> (fOutput->FindObject("PROOF_EventList"));
00932    if (el) {
00933       el->SetName(fInitialExp.Data()+2);
00934       SetStatus(el->GetN());
00935       if (TEventList* old = dynamic_cast<TEventList*> (fTreeDrawArgsParser.GetOriginal())) {
00936          if (!fTreeDrawArgsParser.GetAdd())
00937             old->Reset();
00938          old->Add(el);
00939          fOutput->Remove(el);
00940          delete el;
00941       }
00942    }
00943    else
00944       Error("Terminate", "Cannot find output EventList");
00945 
00946 }
00947 
00948 ClassImp(TProofDrawEntryList)
00949 
00950 //______________________________________________________________________________
00951 TProofDrawEntryList::~TProofDrawEntryList()
00952 {
00953    //class destructor
00954    SafeDelete(fElist);
00955 }
00956 
00957 //______________________________________________________________________________
00958 void TProofDrawEntryList::Init(TTree *tree)
00959 {
00960    // See TProofDraw::Init().
00961 
00962    PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
00963 
00964    fTree = tree;
00965    CompileVariables();
00966 }
00967 
00968 //______________________________________________________________________________
00969 void TProofDrawEntryList::SlaveBegin(TTree *tree)
00970 {
00971    // See TProofDraw::SlaveBegin().
00972 
00973    PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
00974 
00975    fSelection = fInput->FindObject("selection")->GetTitle();
00976    fInitialExp = fInput->FindObject("varexp")->GetTitle();
00977 
00978    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
00979 
00980    SafeDelete(fElist);
00981 
00982    fDimension = 0;
00983    fTree = 0;
00984    fElist = new TEntryList("PROOF_EntryList", "PROOF_EntryList");
00985    fOutput->Add(fElist);
00986 
00987    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
00988    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
00989 }
00990 
00991 //______________________________________________________________________________
00992 void TProofDrawEntryList::DoFill(Long64_t entry, Double_t , const Double_t *)
00993 {
00994    // Fills the eventlist with given values.
00995 
00996    fElist->Enter(entry);
00997 }
00998 
00999 //______________________________________________________________________________
01000 void TProofDrawEntryList::SlaveTerminate(void)
01001 {
01002    // See TProofDraw::SlaveTerminate().
01003 
01004    PDB(kDraw,1) Info("SlaveTerminate","Enter");
01005    fElist->OptimizeStorage();
01006    fElist = 0;
01007 }
01008 
01009 //______________________________________________________________________________
01010 void TProofDrawEntryList::Terminate(void)
01011 {
01012    // See TProofDraw::Terminate().
01013 
01014    TProofDraw::Terminate();   // take care of fStatus
01015    if (!fStatus)
01016       return;
01017 
01018    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01019 
01020    TEntryList *el = dynamic_cast<TEntryList*> (fOutput->FindObject("PROOF_EntryList"));
01021 
01022    if (el) {
01023       el->SetName(fInitialExp.Data()+2);
01024       SetStatus(el->GetN());
01025       if (TEntryList* old = dynamic_cast<TEntryList*> (fTreeDrawArgsParser.GetOriginal())) {
01026          if (!fTreeDrawArgsParser.GetAdd())
01027             old->Reset();
01028          old->Add(el);
01029          fOutput->Remove(el);
01030          delete el;
01031       }
01032    }
01033    else
01034       Error("Terminate", "Cannot find output EventList");
01035 
01036 }
01037 
01038 ClassImp(TProofDrawProfile)
01039 
01040 //______________________________________________________________________________
01041 void TProofDrawProfile::Init(TTree *tree)
01042 {
01043    // See TProofDraw::Init().
01044 
01045    PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
01046 
01047    if (fTree == 0) {
01048       if (!dynamic_cast<TProfile*> (fTreeDrawArgsParser.GetOriginal())) {
01049          fProfile->SetLineColor(tree->GetLineColor());
01050          fProfile->SetLineWidth(tree->GetLineWidth());
01051          fProfile->SetLineStyle(tree->GetLineStyle());
01052          fProfile->SetFillColor(tree->GetFillColor());
01053          fProfile->SetFillStyle(tree->GetFillStyle());
01054          fProfile->SetMarkerStyle(tree->GetMarkerStyle());
01055          fProfile->SetMarkerColor(tree->GetMarkerColor());
01056          fProfile->SetMarkerSize(tree->GetMarkerSize());
01057       }
01058    }
01059    fTree = tree;
01060    CompileVariables();
01061 }
01062 
01063 //______________________________________________________________________________
01064 void TProofDrawProfile::DefVar()
01065 {
01066    // Define relevant variables
01067 
01068    PDB(kDraw,1) Info("DefVar","Enter");
01069 
01070    if (fTreeDrawArgsParser.GetDimension() < 0) {
01071 
01072       // Init parser
01073       fSelection = fInput->FindObject("selection")->GetTitle();
01074       fInitialExp = fInput->FindObject("varexp")->GetTitle();
01075 
01076       fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01077    }
01078 
01079    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 2);
01080 
01081    fTreeDrawArgsParser.SetOriginal(0);
01082    TString exp = fTreeDrawArgsParser.GetVarExp();
01083    exp += ">>";
01084    double binsx, minx, maxx;
01085    if (fTreeDrawArgsParser.IsSpecified(0))
01086       gEnv->SetValue("Hist.Binning.2D.Prof", fTreeDrawArgsParser.GetParameter(0));
01087    binsx = gEnv->GetValue("Hist.Binning.2D.Prof",100);
01088    minx =  fTreeDrawArgsParser.GetIfSpecified(1, 0);
01089    maxx =  fTreeDrawArgsParser.GetIfSpecified(2, 0);
01090    if (fTreeDrawArgsParser.GetObjectName() == "")
01091       fTreeDrawArgsParser.SetObjectName("htemp");
01092    exp += fTreeDrawArgsParser.GetObjectName();
01093    exp += '(';
01094    exp +=      binsx;
01095    exp +=         ',';
01096    exp +=      minx;
01097    exp +=         ',';
01098    exp +=      maxx;
01099    exp += ')';
01100    fInitialExp = exp;
01101    TNamed *n = dynamic_cast<TNamed*> (fInput->FindObject("varexp"));
01102    if (n)
01103       n->SetTitle(exp);
01104    else
01105       Error("DefVar", "Cannot find varexp on the fInput");
01106    if (fTreeDrawArgsParser.GetNoParameters() != 3)
01107       fInput->Add(new TNamed("PROOF_OPTIONS", "rebin"));
01108 }
01109 
01110 //______________________________________________________________________________
01111 void TProofDrawProfile::Begin(TTree *tree)
01112 {
01113    // See TProofDraw::Begin().
01114 
01115    PDB(kDraw,1) Info("Begin","Enter tree = %p", tree);
01116 
01117    fSelection = fInput->FindObject("selection")->GetTitle();
01118    fInitialExp = fInput->FindObject("varexp")->GetTitle();
01119 
01120    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01121 
01122    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 2);
01123 
01124    TObject *orig = fTreeDrawArgsParser.GetOriginal();
01125    TH1* pold;
01126    if ((pold = dynamic_cast<TProfile*> (orig)) && fTreeDrawArgsParser.GetNoParameters() == 0) {
01127       TProfile* pnew = (TProfile*) pold->Clone();
01128       pnew->Reset();
01129       fInput->Add(pnew);
01130    } else {
01131       delete orig;
01132       DefVar();
01133    }
01134 
01135    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
01136    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
01137    fTree = 0;
01138 }
01139 
01140 
01141 //______________________________________________________________________________
01142 void TProofDrawProfile::SlaveBegin(TTree *tree)
01143 {
01144    // See TProofDraw::SlaveBegin().
01145 
01146    PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
01147 
01148    fSelection = fInput->FindObject("selection")->GetTitle();
01149    fInitialExp = fInput->FindObject("varexp")->GetTitle();
01150 
01151    SafeDelete(fProfile);
01152 
01153 
01154    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01155    fDimension = 2;
01156    TString exp = fTreeDrawArgsParser.GetExp();
01157 
01158    if (fTreeDrawArgsParser.GetOriginal()) {
01159       fProfile = dynamic_cast<TProfile*> (fTreeDrawArgsParser.GetOriginal());
01160       if (fProfile) {
01161          fOutput->Add(fProfile);
01162          PDB(kDraw,1) Info("SlaveBegin","Original profile histogram found");
01163          return;
01164       }
01165       else
01166          Error("SlaveBegin","Original object found but it is not a histogram");
01167    }
01168    Int_t countx = 100; double minx = 0, maxx = 0;
01169    if (fTreeDrawArgsParser.GetNoParameters() != 0) {
01170       countx = (Int_t) fTreeDrawArgsParser.GetIfSpecified(0, countx);
01171       minx =  fTreeDrawArgsParser.GetIfSpecified(1, minx);
01172       maxx =  fTreeDrawArgsParser.GetIfSpecified(2, maxx);
01173    }
01174    if (fTreeDrawArgsParser.GetNoParameters() != 3)
01175       Error("SlaveBegin", "Impossible - Wrong number of parameters");
01176    TString constructorOptions = "";
01177    if (fOption.Contains("profs"))
01178       constructorOptions = "s";
01179    else if (fOption.Contains("profi"))
01180       constructorOptions = "i";
01181    else if (fOption.Contains("profg"))
01182       constructorOptions = "g";
01183 
01184    fProfile = new TProfile(fTreeDrawArgsParser.GetObjectName(),
01185                            fTreeDrawArgsParser.GetObjectTitle(),
01186                            countx, minx, maxx,
01187                            constructorOptions);
01188    if (minx >= maxx)
01189       fProfile->SetBuffer(TH1::GetDefaultBufferSize());
01190 
01191    if (TNamed *opt = dynamic_cast<TNamed*> (fInput->FindObject("PROOF_OPTIONS"))) {
01192       if (strstr(opt->GetTitle(), "rebin"))
01193          fProfile->SetBit(TH1::kCanRebin);
01194    }
01195    fProfile->SetDirectory(0);   // take ownership
01196    fOutput->Add(fProfile);      // release ownership
01197    fTree = 0;
01198    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
01199    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
01200 }
01201 
01202 
01203 //______________________________________________________________________________
01204 void TProofDrawProfile::DoFill(Long64_t , Double_t w, const Double_t *v)
01205 {
01206    // Fills the profile histogram with the given values.
01207 
01208    fProfile->Fill(v[1], v[0], w);
01209 }
01210 
01211 
01212 //______________________________________________________________________________
01213 void TProofDrawProfile::Terminate(void)
01214 {
01215    // See TProofDraw::Terminate().
01216 
01217    PDB(kDraw,1) Info("Terminate","Enter");
01218    TProofDraw::Terminate();
01219    if (!fStatus)
01220       return;
01221 
01222    fProfile = (TProfile *) fOutput->FindObject(fTreeDrawArgsParser.GetObjectName());
01223    if (fProfile) {
01224       SetStatus((Int_t) fProfile->GetEntries());
01225       TProfile *pf = 0;
01226       if ((pf = dynamic_cast<TProfile*> (fTreeDrawArgsParser.GetOriginal()))) {
01227          if (!fTreeDrawArgsParser.GetAdd())
01228             pf->Reset();
01229          TList l;
01230          l.Add(fProfile);
01231          pf->Merge(&l);
01232          fOutput->Remove(fProfile);
01233          delete fProfile;
01234       } else {
01235          fProfile->SetTitle(fTreeDrawArgsParser.GetObjectTitle());
01236          pf = fProfile;
01237       }
01238       if (fTreeDrawArgsParser.GetShouldDraw()) {
01239          // Choose the right canvas
01240          SetCanvas(pf->GetName());
01241          // Draw
01242          SetDrawAtt(pf);
01243          pf->Draw(fOption.Data());
01244       }
01245    }
01246    fProfile = 0;
01247 }
01248 
01249 
01250 ClassImp(TProofDrawProfile2D)
01251 
01252 //______________________________________________________________________________
01253 void TProofDrawProfile2D::Init(TTree *tree)
01254 {
01255    // See TProofDraw::Init().
01256 
01257    PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
01258    if (fTree == 0) {
01259       if (!dynamic_cast<TProfile2D*> (fTreeDrawArgsParser.GetOriginal())) {
01260          fProfile->SetLineColor(tree->GetLineColor());
01261          fProfile->SetLineWidth(tree->GetLineWidth());
01262          fProfile->SetLineStyle(tree->GetLineStyle());
01263          fProfile->SetFillColor(tree->GetFillColor());
01264          fProfile->SetFillStyle(tree->GetFillStyle());
01265          fProfile->SetMarkerStyle(tree->GetMarkerStyle());
01266          fProfile->SetMarkerColor(tree->GetMarkerColor());
01267          fProfile->SetMarkerSize(tree->GetMarkerSize());
01268       }
01269    }
01270 
01271    fTree = tree;
01272    CompileVariables();
01273 }
01274 
01275 //______________________________________________________________________________
01276 void TProofDrawProfile2D::DefVar()
01277 {
01278    // Define relevant variables
01279 
01280    PDB(kDraw,1) Info("DefVar","Enter");
01281 
01282    if (fTreeDrawArgsParser.GetDimension() < 0) {
01283 
01284       // Init parser
01285       fSelection = fInput->FindObject("selection")->GetTitle();
01286       fInitialExp = fInput->FindObject("varexp")->GetTitle();
01287 
01288       fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01289    }
01290    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 3);
01291 
01292    fTreeDrawArgsParser.SetOriginal(0);
01293    TString exp = fTreeDrawArgsParser.GetVarExp();
01294    exp += ">>";
01295    double binsx, minx, maxx;
01296    double binsy, miny, maxy;
01297    if (fTreeDrawArgsParser.IsSpecified(0))
01298       gEnv->SetValue("Hist.Binning.3D.Profx", fTreeDrawArgsParser.GetParameter(0));
01299    if (fTreeDrawArgsParser.IsSpecified(3))
01300       gEnv->SetValue("Hist.Binning.3D.Profy", fTreeDrawArgsParser.GetParameter(3));
01301    binsx = gEnv->GetValue("Hist.Binning.3D.Profx",20);
01302    minx =  fTreeDrawArgsParser.GetIfSpecified(1, 0);
01303    maxx =  fTreeDrawArgsParser.GetIfSpecified(2, 0);
01304    binsy = gEnv->GetValue("Hist.Binning.3D.Profy",20);
01305    miny =  fTreeDrawArgsParser.GetIfSpecified(4, 0);
01306    maxy =  fTreeDrawArgsParser.GetIfSpecified(5, 0);
01307    if (fTreeDrawArgsParser.GetObjectName() == "")
01308       fTreeDrawArgsParser.SetObjectName("htemp");
01309    exp += fTreeDrawArgsParser.GetObjectName();
01310    exp += '(';
01311    exp +=      binsx;
01312    exp +=         ',';
01313    exp +=      minx;
01314    exp +=         ',';
01315    exp +=      maxx;
01316    exp += ',';
01317    exp +=      binsy;
01318    exp +=         ',';
01319    exp +=      miny;
01320    exp +=         ',';
01321    exp +=      maxy;
01322    exp += ')';
01323    fInitialExp = exp;
01324    TNamed *n = dynamic_cast<TNamed*> (fInput->FindObject("varexp"));
01325    if (n)
01326       n->SetTitle(exp);
01327    else
01328       Error("DefVar", "Cannot find varexp on the fInput");
01329    if (fTreeDrawArgsParser.GetNoParameters() != 6)
01330       fInput->Add(new TNamed("PROOF_OPTIONS", "rebin"));
01331 }
01332 
01333 //______________________________________________________________________________
01334 void TProofDrawProfile2D::Begin(TTree *tree)
01335 {
01336    // See TProofDraw::Begin().
01337 
01338    PDB(kDraw,1) Info("Begin","Enter tree = %p", tree);
01339 
01340    fSelection = fInput->FindObject("selection")->GetTitle();
01341    fInitialExp = fInput->FindObject("varexp")->GetTitle();
01342 
01343    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01344 
01345    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 3);
01346 
01347    TObject *orig = fTreeDrawArgsParser.GetOriginal();
01348    TProfile2D *pold;
01349    if ((pold = dynamic_cast<TProfile2D*> (orig)) && fTreeDrawArgsParser.GetNoParameters() == 0) {
01350       TProfile2D* pnew = (TProfile2D*) pold->Clone();
01351       pnew->Reset();
01352       fInput->Add(pnew);
01353    } else {
01354       delete orig;
01355       DefVar();
01356    }
01357 
01358    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
01359    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
01360 }
01361 
01362 //______________________________________________________________________________
01363 void TProofDrawProfile2D::SlaveBegin(TTree *tree)
01364 {
01365    // See TProofDraw::SlaveBegin().
01366 
01367    PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
01368 
01369    fSelection = fInput->FindObject("selection")->GetTitle();
01370    fInitialExp = fInput->FindObject("varexp")->GetTitle();
01371 
01372    SafeDelete(fProfile);
01373 
01374    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01375    fDimension = 2;
01376    TString exp = fTreeDrawArgsParser.GetExp();
01377 
01378    if (fTreeDrawArgsParser.GetOriginal()) {
01379       fProfile = dynamic_cast<TProfile2D*> (fTreeDrawArgsParser.GetOriginal());
01380       if (fProfile) {
01381          fOutput->Add(fProfile);
01382          PDB(kDraw,1) Info("SlaveBegin","Original profile histogram found");
01383          return;
01384       } else
01385          Error("SlaveBegin","Original object found but it is not a histogram");
01386    }
01387    Int_t countx = 40; double minx = 0, maxx = 0;
01388    Int_t county = 40; double miny = 0, maxy = 0;
01389    if (fTreeDrawArgsParser.GetNoParameters() != 0) {
01390       countx = (Int_t) fTreeDrawArgsParser.GetIfSpecified(0, countx);
01391       minx =  fTreeDrawArgsParser.GetIfSpecified(1, minx);
01392       maxx =  fTreeDrawArgsParser.GetIfSpecified(2, maxx);
01393       county = (Int_t) fTreeDrawArgsParser.GetIfSpecified(3, countx);
01394       miny =  fTreeDrawArgsParser.GetIfSpecified(4, minx);
01395       maxy =  fTreeDrawArgsParser.GetIfSpecified(5, maxx);
01396    }
01397    if (fTreeDrawArgsParser.GetNoParameters() != 6)
01398       Error("SlaveBegin", "Impossible - Wrong number of parameters");
01399 
01400    TString constructorOptions = "";
01401    if (fOption.Contains("profs"))
01402       constructorOptions = "s";
01403    else if (fOption.Contains("profi"))
01404       constructorOptions = "i";
01405    else if (fOption.Contains("profg"))
01406       constructorOptions = "g";
01407 
01408    fProfile = new TProfile2D(fTreeDrawArgsParser.GetObjectName(),
01409                              fTreeDrawArgsParser.GetObjectTitle(),
01410                              countx, minx, maxx,
01411                              county, miny, maxy,
01412                              constructorOptions);
01413    if (minx >= maxx)
01414       fProfile->SetBuffer(TH1::GetDefaultBufferSize());
01415 
01416    if (TNamed *opt = dynamic_cast<TNamed*> (fInput->FindObject("PROOF_OPTIONS"))) {
01417       if (strstr(opt->GetTitle(), "rebin"))
01418          fProfile->SetBit(TH1::kCanRebin);
01419    }
01420    fProfile->SetDirectory(0);   // take ownership
01421    fOutput->Add(fProfile);      // release ownership
01422    fTree = 0;
01423    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
01424    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
01425 }
01426 
01427 
01428 //______________________________________________________________________________
01429 void TProofDrawProfile2D::DoFill(Long64_t , Double_t w, const Double_t *v)
01430 {
01431    // Fills the histogram with the given values.
01432 
01433    fProfile->Fill(v[2], v[1], v[0], w);
01434 }
01435 
01436 
01437 //______________________________________________________________________________
01438 void TProofDrawProfile2D::Terminate(void)
01439 {
01440    // See TProofDraw::Terminate().
01441 
01442    PDB(kDraw,1) Info("Terminate","Enter");
01443    TProofDraw::Terminate();
01444    if (!fStatus)
01445       return;
01446 
01447    fProfile = (TProfile2D *) fOutput->FindObject(fTreeDrawArgsParser.GetObjectName());
01448    if (fProfile) {
01449       SetStatus((Int_t) fProfile->GetEntries());
01450       TProfile2D *pf = 0;
01451       if ((pf = dynamic_cast<TProfile2D*> (fTreeDrawArgsParser.GetOriginal()))) {
01452          if (!fTreeDrawArgsParser.GetAdd())
01453             pf->Reset();
01454          TList l;
01455          l.Add(fProfile);
01456          pf->Merge(&l);
01457          fOutput->Remove(fProfile);
01458          delete fProfile;
01459       } else {
01460          fProfile->SetTitle(fTreeDrawArgsParser.GetObjectTitle());
01461          pf = fProfile;
01462       }
01463       if (fTreeDrawArgsParser.GetShouldDraw()) {
01464          // Choose the right canvas
01465          SetCanvas(pf->GetName());
01466          // Draw
01467          SetDrawAtt(pf);
01468          pf->Draw(fOption.Data());
01469       }
01470    }
01471    fProfile = 0;
01472 }
01473 
01474 
01475 ClassImp(TProofDrawGraph)
01476 
01477 //______________________________________________________________________________
01478 void TProofDrawGraph::Init(TTree *tree)
01479 {
01480    // See TProofDraw::Init().
01481 
01482    PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
01483 
01484    if (fTree == 0) {
01485       R__ASSERT(fGraph);
01486       fGraph->SetMarkerStyle(tree->GetMarkerStyle());
01487       fGraph->SetMarkerColor(tree->GetMarkerColor());
01488       fGraph->SetMarkerSize(tree->GetMarkerSize());
01489       fGraph->SetLineColor(tree->GetLineColor());
01490       fGraph->SetLineStyle(tree->GetLineStyle());
01491       fGraph->SetFillColor(tree->GetFillColor());
01492       fGraph->SetFillStyle(tree->GetFillStyle());
01493    }
01494    fTree = tree;
01495    CompileVariables();
01496 }
01497 
01498 
01499 //______________________________________________________________________________
01500 void TProofDrawGraph::SlaveBegin(TTree *tree)
01501 {
01502    // See TProofDraw::SlaveBegin().
01503 
01504    PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
01505 
01506    fSelection = fInput->FindObject("selection")->GetTitle();
01507    fInitialExp = fInput->FindObject("varexp")->GetTitle();
01508    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01509 
01510    SafeDelete(fGraph);
01511    fDimension = 2;
01512 
01513    fGraph = new TGraph();
01514    fGraph->SetName("PROOF_GRAPH");
01515    fOutput->Add(fGraph);                         // release ownership
01516 
01517    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
01518    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
01519 }
01520 
01521 
01522 //______________________________________________________________________________
01523 void TProofDrawGraph::DoFill(Long64_t , Double_t , const Double_t *v)
01524 {
01525    // Fills the graph with the given values.
01526 
01527    fGraph->SetPoint(fGraph->GetN(), v[1], v[0]);
01528 }
01529 
01530 
01531 //______________________________________________________________________________
01532 void TProofDrawGraph::Terminate(void)
01533 {
01534    // See TProofDraw::Terminate().
01535 
01536    PDB(kDraw,1) Info("Terminate","Enter");
01537    TProofDraw::Terminate();
01538    if (!fStatus)
01539       return;
01540 
01541    fGraph = dynamic_cast<TGraph*> (fOutput->FindObject("PROOF_GRAPH"));
01542    if (fGraph) {
01543       SetStatus((Int_t) fGraph->GetN());
01544       TH2F* hist;
01545       TObject *orig = fTreeDrawArgsParser.GetOriginal();
01546       if ( (hist = dynamic_cast<TH2F*> (orig)) == 0 ) {
01547          delete orig;
01548          fTreeDrawArgsParser.SetOriginal(0);
01549          double binsx, minx, maxx;
01550          double binsy, miny, maxy;
01551          if (fTreeDrawArgsParser.IsSpecified(0))
01552             gEnv->SetValue("Hist.Binning.2D.x", fTreeDrawArgsParser.GetParameter(0));
01553          if (fTreeDrawArgsParser.IsSpecified(3))
01554             gEnv->SetValue("Hist.Binning.2D.y", fTreeDrawArgsParser.GetParameter(3));
01555          binsx = gEnv->GetValue("Hist.Binning.2D.x",100);
01556          minx =  fTreeDrawArgsParser.GetIfSpecified(1, 0);
01557          maxx =  fTreeDrawArgsParser.GetIfSpecified(2, 0);
01558          binsy = gEnv->GetValue("Hist.Binning.2D.y",100);
01559          miny =  fTreeDrawArgsParser.GetIfSpecified(4, 0);
01560          maxy =  fTreeDrawArgsParser.GetIfSpecified(5, 0);
01561          hist = new TH2F(fTreeDrawArgsParser.GetObjectName(), fTreeDrawArgsParser.GetObjectTitle(),
01562                         (Int_t) binsx, minx, maxx, (Int_t) binsy, miny, maxy);
01563          hist->SetBit(TH1::kNoStats);
01564          hist->SetBit(kCanDelete);
01565          if (fTreeDrawArgsParser.GetNoParameters() != 6)
01566             hist->SetBit(TH1::kCanRebin);
01567          else
01568             hist->ResetBit(TH1::kCanRebin);
01569 //         if (fTreeDrawArgsParser.GetShouldDraw())    // ?? FIXME
01570 //            hist->SetDirectory(0);
01571       } else {
01572          if (!fTreeDrawArgsParser.GetAdd())
01573             hist->Reset();
01574       }
01575       if (hist->TestBit(TH1::kCanRebin) && hist->TestBit(kCanDelete)) {
01576          Double_t* xArray = fGraph->GetX();
01577          Double_t* yArray = fGraph->GetY();
01578          Double_t xmin = *std::min_element(xArray, xArray+fGraph->GetN());
01579          Double_t xmax = *std::max_element(xArray, xArray+fGraph->GetN());
01580          Double_t ymin = *std::min_element(yArray, yArray+fGraph->GetN());
01581          Double_t ymax = *std::max_element(yArray, yArray+fGraph->GetN());
01582          THLimitsFinder::GetLimitsFinder()->FindGoodLimits(hist,xmin,xmax,ymin,ymax);
01583       }
01584       if (!hist->TestBit(kCanDelete)) {
01585          TH1 *h2c = hist->DrawCopy(fOption.Data());
01586          h2c->SetStats(kFALSE);
01587       } else {
01588          SetDrawAtt(hist);
01589          hist->Draw();
01590       }
01591       gPad->Update();
01592 
01593       fGraph->SetEditable(kFALSE);
01594       // FIXME set color, marker size, etc.
01595 
01596       if (fTreeDrawArgsParser.GetShouldDraw()) {
01597          SetDrawAtt(fGraph);
01598          if (fOption == "" || strcmp(fOption, "same") == 0)
01599             fGraph->Draw("p");
01600          else
01601             fGraph->Draw(fOption);
01602          gPad->Update();
01603       }
01604       if (!hist->TestBit(kCanDelete)) {
01605          for (int i = 0; i < fGraph->GetN(); i++) {
01606             Double_t x, y;
01607             fGraph->GetPoint(i, x, y);
01608             hist->Fill(x, y, 1);
01609          }
01610       }
01611    }
01612    fGraph = 0;
01613 }
01614 
01615 
01616 ClassImp(TProofDrawPolyMarker3D)
01617 
01618 //______________________________________________________________________________
01619 void TProofDrawPolyMarker3D::Init(TTree *tree)
01620 {
01621    // See TProofDraw::Init().
01622 
01623    PDB(kDraw,1) Info("Init","Enter tree = %p", tree);
01624 
01625    if (fTree == 0) {
01626       R__ASSERT(fPolyMarker3D);
01627       fPolyMarker3D->SetMarkerStyle(tree->GetMarkerStyle());
01628       fPolyMarker3D->SetMarkerColor(tree->GetMarkerColor());
01629       fPolyMarker3D->SetMarkerSize(tree->GetMarkerSize());
01630    }
01631    fTree = tree;
01632    CompileVariables();
01633 }
01634 
01635 //______________________________________________________________________________
01636 void TProofDrawPolyMarker3D::SlaveBegin(TTree *tree)
01637 {
01638    // See TProofDraw::SlaveBegin().
01639 
01640    PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
01641 
01642    fSelection = fInput->FindObject("selection")->GetTitle();
01643    fInitialExp = fInput->FindObject("varexp")->GetTitle();
01644    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01645    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 3);
01646 
01647    SafeDelete(fPolyMarker3D);
01648    fDimension = 3;
01649 
01650    fPolyMarker3D = new TPolyMarker3D();
01651    fOutput->Add(fPolyMarker3D);      // release ownership
01652 
01653    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
01654    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
01655 }
01656 
01657 
01658 //______________________________________________________________________________
01659 void TProofDrawPolyMarker3D::DoFill(Long64_t , Double_t , const Double_t *v)
01660 {
01661    // Fills the scatter plot with the given values.
01662 
01663    fPolyMarker3D->SetNextPoint(v[2], v[1], v[0]);
01664 }
01665 
01666 
01667 //______________________________________________________________________________
01668 void TProofDrawPolyMarker3D::Terminate(void)
01669 {
01670    // See TProofDraw::Terminate().
01671 
01672    PDB(kDraw,1) Info("Terminate","Enter");
01673    TProofDraw::Terminate();
01674    if (!fStatus)
01675       return;
01676 
01677    fPolyMarker3D = 0;
01678    TIter next(fOutput);
01679    while (TObject* o = next()) {
01680       if (dynamic_cast<TPolyMarker3D*> (o)) {
01681          fPolyMarker3D = dynamic_cast<TPolyMarker3D*> (o);
01682          break;
01683       }
01684    }
01685 
01686    Bool_t checkPrevious = kFALSE;
01687    if (fPolyMarker3D) {
01688       SetStatus((Int_t) fPolyMarker3D->Size());
01689       TH3F* hist;
01690       TObject *orig = fTreeDrawArgsParser.GetOriginal();
01691       if ( (hist = dynamic_cast<TH3F*> (orig)) == 0 ) {
01692          delete orig;
01693          fTreeDrawArgsParser.SetOriginal(0);
01694          if (fOption.Contains("same")) {
01695             // Check existing histogram
01696             hist = dynamic_cast<TH3F *> (gDirectory->Get(fTreeDrawArgsParser.GetObjectName()));
01697          }
01698          if (!hist) {
01699             double binsx, minx, maxx;
01700             double binsy, miny, maxy;
01701             double binsz, minz, maxz;
01702             if (fTreeDrawArgsParser.IsSpecified(0))
01703                gEnv->SetValue("Hist.Binning.3D.x", fTreeDrawArgsParser.GetParameter(0));
01704             if (fTreeDrawArgsParser.IsSpecified(3))
01705                gEnv->SetValue("Hist.Binning.3D.y", fTreeDrawArgsParser.GetParameter(3));
01706             if (fTreeDrawArgsParser.IsSpecified(6))
01707                gEnv->SetValue("Hist.Binning.3D.z", fTreeDrawArgsParser.GetParameter(6));
01708             binsx = gEnv->GetValue("Hist.Binning.3D.x",100);
01709             minx =  fTreeDrawArgsParser.GetIfSpecified(1, 0);
01710             maxx =  fTreeDrawArgsParser.GetIfSpecified(2, 0);
01711             binsy = gEnv->GetValue("Hist.Binning.3D.y",100);
01712             miny =  fTreeDrawArgsParser.GetIfSpecified(4, 0);
01713             maxy =  fTreeDrawArgsParser.GetIfSpecified(5, 0);
01714             binsz = gEnv->GetValue("Hist.Binning.3D.z",100);
01715             minz =  fTreeDrawArgsParser.GetIfSpecified(7, 0);
01716             maxz =  fTreeDrawArgsParser.GetIfSpecified(8, 0);
01717             hist = new TH3F(fTreeDrawArgsParser.GetObjectName(), fTreeDrawArgsParser.GetObjectTitle(),
01718                            (Int_t) binsx, minx, maxx,
01719                            (Int_t) binsy, miny, maxy,
01720                            (Int_t) binsz, minz, maxz);
01721             hist->SetBit(TH1::kNoStats);
01722             hist->SetBit(kCanDelete);
01723             if (fTreeDrawArgsParser.GetNoParameters() != 9)
01724                hist->SetBit(TH1::kCanRebin);
01725             else
01726                hist->ResetBit(TH1::kCanRebin);
01727          } else {
01728             checkPrevious = kTRUE;
01729             PDB(kDraw,2)
01730                Info("Terminate", "found histo '%s' in gDirectory",
01731                                  fTreeDrawArgsParser.GetObjectName().Data());
01732          }
01733       } else {
01734          if (!fTreeDrawArgsParser.GetAdd())
01735             hist->Reset();
01736       }
01737 
01738       // Set the ranges; take into account previous histos for 'same' runs
01739       Double_t rmin[3], rmax[3];
01740       if (hist->TestBit(TH1::kCanRebin) && hist->TestBit(kCanDelete)) {
01741          rmin[0] = rmax[0] = rmin[1] = rmax[1] = rmin[2] = rmax[2] = 0;
01742          if (fPolyMarker3D->Size() > 0) {
01743             fPolyMarker3D->GetPoint(0, rmin[0], rmin[1], rmin[2]);
01744             fPolyMarker3D->GetPoint(0, rmax[0], rmax[1], rmax[2]);
01745          }
01746          for (int i = 1; i < fPolyMarker3D->Size(); i++) {
01747             Double_t v[3];
01748             fPolyMarker3D->GetPoint(i, v[0], v[1], v[2]);
01749             for (int ii = 0; ii < 3; ii++) {
01750                if (v[ii] < rmin[ii]) rmin[ii] = v[ii];
01751                if (v[ii] > rmax[ii]) rmax[ii] = v[ii];
01752             }
01753          }
01754          // Compare with previous histo, if any
01755          if (checkPrevious) {
01756             rmin[0] = (hist->GetXaxis()->GetXmin() < rmin[0]) ? hist->GetXaxis()->GetXmin()
01757                                                               : rmin[0];
01758             rmin[1] = (hist->GetYaxis()->GetXmin() < rmin[1]) ? hist->GetYaxis()->GetXmin()
01759                                                               : rmin[1];
01760             rmin[2] = (hist->GetZaxis()->GetXmin() < rmin[2]) ? hist->GetZaxis()->GetXmin()
01761                                                               : rmin[2];
01762             rmax[0] = (hist->GetXaxis()->GetXmax() > rmax[0]) ? hist->GetXaxis()->GetXmax()
01763                                                               : rmax[0];
01764             rmax[1] = (hist->GetYaxis()->GetXmax() > rmax[1]) ? hist->GetYaxis()->GetXmax()
01765                                                               : rmax[1];
01766             rmax[2] = (hist->GetZaxis()->GetXmax() > rmax[2]) ? hist->GetZaxis()->GetXmax()
01767                                                               : rmax[2];
01768          }
01769 
01770          THLimitsFinder::GetLimitsFinder()->FindGoodLimits(hist,
01771                            rmin[0], rmax[0], rmin[1], rmax[1], rmin[2], rmax[2]);
01772       }
01773       if (fTreeDrawArgsParser.GetShouldDraw()) {
01774          if (!hist->TestBit(kCanDelete)) {
01775             TH1 *histcopy = hist->DrawCopy(fOption.Data());
01776             histcopy->SetStats(kFALSE);
01777          } else {
01778             SetDrawAtt(hist);
01779             hist->Draw(fOption);        // no draw options on purpose
01780          }
01781          gPad->Update();
01782       } else {
01783          gPad->Clear();
01784          gPad->Range(-1,-1,1,1);
01785          TView::CreateView(1,rmin,rmax);
01786       }
01787       if (fTreeDrawArgsParser.GetShouldDraw()) {
01788          SetDrawAtt(fPolyMarker3D);
01789          fPolyMarker3D->Draw(fOption);
01790       }
01791       gPad->Update();
01792       if (!hist->TestBit(kCanDelete)) {
01793          for (int i = 0; i < fPolyMarker3D->Size(); i++) {
01794             Float_t x, y, z;
01795             fPolyMarker3D->GetPoint(i, x, y, z);
01796             hist->Fill(x, y, z, 1);
01797          }
01798       }
01799    }
01800 }
01801 
01802 
01803 ClassImp(TProofDrawListOfGraphs)
01804 
01805 //______________________________________________________________________________
01806 void TProofDrawListOfGraphs::SlaveBegin(TTree *tree)
01807 {
01808    // See TProofDraw::SlaveBegin().
01809 
01810    PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
01811 
01812    fSelection = fInput->FindObject("selection")->GetTitle();
01813    fInitialExp = fInput->FindObject("varexp")->GetTitle();
01814    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01815    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 3);
01816 
01817    SafeDelete(fPoints);
01818 
01819    fDimension = 3;
01820 
01821    fPoints = new TProofVectorContainer<Point3D_t>(new std::vector<Point3D_t>);
01822    fPoints->SetName("PROOF_SCATTERPLOT");
01823    fOutput->Add(fPoints);      // release ownership (? FIXME)
01824 
01825    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
01826    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
01827 }
01828 
01829 
01830 //______________________________________________________________________________
01831 void TProofDrawListOfGraphs::DoFill(Long64_t , Double_t , const Double_t *v)
01832 {
01833    // Fills the scatter plot with the given values.
01834 
01835    fPoints->GetVector()->push_back(Point3D_t(v[2], v[1], v[0]));
01836 }
01837 
01838 
01839 //______________________________________________________________________________
01840 void TProofDrawListOfGraphs::Terminate(void)
01841 {
01842    // See TProofDraw::Terminate().
01843 
01844    PDB(kDraw,1) Info("Terminate","Enter");
01845    TProofDraw::Terminate();
01846    if (!fStatus)
01847       return;
01848 
01849    fPoints = dynamic_cast<TProofVectorContainer<Point3D_t>*>
01850                (fOutput->FindObject("PROOF_SCATTERPLOT"));
01851    if (fPoints) {
01852       std::vector<Point3D_t> *points = fPoints->GetVector();
01853       R__ASSERT(points);
01854       SetStatus((Int_t) points->size());
01855       TH2F* hist;
01856       TObject *orig = fTreeDrawArgsParser.GetOriginal();
01857       if ( (hist = dynamic_cast<TH2F*> (orig)) == 0 ) {
01858          delete orig;
01859          fTreeDrawArgsParser.SetOriginal(0);
01860          double binsx, minx, maxx;
01861          double binsy, miny, maxy;
01862          if (fTreeDrawArgsParser.IsSpecified(0))
01863             gEnv->SetValue("Hist.Binning.2D.x", fTreeDrawArgsParser.GetParameter(0));
01864          if (fTreeDrawArgsParser.IsSpecified(3))
01865             gEnv->SetValue("Hist.Binning.2D.y", fTreeDrawArgsParser.GetParameter(3));
01866          binsx = gEnv->GetValue("Hist.Binning.2D.x", 40);
01867          minx =  fTreeDrawArgsParser.GetIfSpecified(1, 0);
01868          maxx =  fTreeDrawArgsParser.GetIfSpecified(2, 0);
01869          binsy = gEnv->GetValue("Hist.Binning.2D.y", 40);
01870          miny =  fTreeDrawArgsParser.GetIfSpecified(4, 0);
01871          maxy =  fTreeDrawArgsParser.GetIfSpecified(5, 0);
01872          hist = new TH2F(fTreeDrawArgsParser.GetObjectName(), fTreeDrawArgsParser.GetObjectTitle(),
01873                         (Int_t) binsx, minx, maxx, (Int_t) binsy, miny, maxy);
01874          hist->SetBit(TH1::kNoStats);
01875          hist->SetBit(kCanDelete);
01876          if (fTreeDrawArgsParser.GetNoParameters() != 6)
01877             hist->SetBit(TH1::kCanRebin);
01878          else
01879             hist->ResetBit(TH1::kCanRebin);
01880 
01881 //         if (fTreeDrawArgsParser.GetShouldDraw())         // ?? FIXME
01882 //            hist->SetDirectory(0);
01883       }
01884       Double_t rmin[3], rmax[3];
01885 
01886       // FIXME take rmin and rmax from the old histogram
01887       rmin[0] = rmax[0] = rmin[1] = rmax[1] = rmin[2] = rmax[2] = 0;
01888       if (points->size() > 0) {
01889          rmin[0] = rmax[0] = (*points)[0].fX;
01890          rmin[1] = rmax[1] = (*points)[0].fY;
01891          rmin[2] = rmax[2] = (*points)[0].fZ;
01892 
01893          for (vector<Point3D_t>::const_iterator i = points->begin() + 1; i < points->end(); ++i) {
01894             if (rmax[0] < i->fX) rmax[0] = i->fX;
01895             if (rmax[1] < i->fY) rmax[1] = i->fY;
01896             if (rmax[2] < i->fZ) rmax[2] = i->fZ;
01897             if (rmin[0] > i->fX) rmin[0] = i->fX;
01898             if (rmin[1] > i->fY) rmin[1] = i->fY;
01899             if (rmin[2] > i->fZ) rmin[2] = i->fZ;
01900          }
01901          // in this case we don't care about user-specified limits
01902          if (hist->TestBit(TH1::kCanRebin) && hist->TestBit(kCanDelete)) {
01903             THLimitsFinder::GetLimitsFinder()->FindGoodLimits(hist,
01904                            rmin[1], rmax[1], rmin[2], rmax[2]);
01905          }
01906       }
01907 
01908       Int_t ncolors  = gStyle->GetNumberOfColors();
01909       TObjArray *grs = (TObjArray*)hist->GetListOfFunctions()->FindObject("graphs");
01910       Int_t col;
01911       TGraph *gr;
01912       if (!grs) {
01913          grs = new TObjArray(ncolors);
01914          grs->SetOwner();
01915          grs->SetName("graphs");
01916          hist->GetListOfFunctions()->Add(grs, "P");
01917          for (col=0;col<ncolors;col++) {
01918             gr = new TGraph();
01919             gr->SetMarkerColor(col);
01920 //            gr->SetMarkerStyle(fTree->GetMarkerStyle());
01921 //            gr->SetMarkerSize(fTree->GetMarkerSize());
01922             grs->AddAt(gr,col);
01923          }
01924       }
01925       // Fill the graphs acording to the color
01926       for (vector<Point3D_t>::const_iterator i = points->begin();
01927            i < points->end(); ++i) {
01928          col = Int_t((ncolors-1)*((i->fX-rmin[0])/(rmax[0]-rmin[0])));
01929          if (col < 0) col = 0;
01930          if (col > ncolors-1) col = ncolors-1;
01931          gr = (TGraph*)grs->UncheckedAt(col);
01932          if (gr) gr->SetPoint(gr->GetN(), i->fY, i->fZ);
01933       }
01934       // Remove potential empty graphs
01935       for (col=0;col<ncolors;col++) {
01936          gr = (TGraph*)grs->At(col);
01937          if (gr && gr->GetN() <= 0) grs->Remove(gr);
01938       }
01939       if (fTreeDrawArgsParser.GetShouldDraw()) {
01940          SetDrawAtt(hist);
01941          hist->Draw(fOption.Data());
01942          gPad->Update();
01943       }
01944       fOutput->Remove(fPoints);
01945       SafeDelete(fPoints);
01946    }
01947 }
01948 
01949 
01950 ClassImp(TProofDrawListOfPolyMarkers3D)
01951 
01952 
01953 //______________________________________________________________________________
01954 void TProofDrawListOfPolyMarkers3D::SlaveBegin(TTree *tree)
01955 {
01956    // See TProofDraw::SlaveBegin().
01957 
01958    PDB(kDraw,1) Info("SlaveBegin","Enter tree = %p", tree);
01959 
01960    fSelection = fInput->FindObject("selection")->GetTitle();
01961    fInitialExp = fInput->FindObject("varexp")->GetTitle();
01962    fTreeDrawArgsParser.Parse(fInitialExp, fSelection, fOption);
01963    R__ASSERT(fTreeDrawArgsParser.GetDimension() == 4);
01964 
01965    SafeDelete(fPoints);
01966 
01967    fDimension = 4;
01968 
01969    fPoints = new TProofVectorContainer<Point4D_t>(new std::vector<Point4D_t>);
01970    fPoints->SetName("PROOF_SCATTERPLOT");
01971    fOutput->Add(fPoints);      // release ownership (? FIXME)
01972 
01973    PDB(kDraw,1) Info("Begin","selection: %s", fSelection.Data());
01974    PDB(kDraw,1) Info("Begin","varexp: %s", fInitialExp.Data());
01975 }
01976 
01977 
01978 //______________________________________________________________________________
01979 void TProofDrawListOfPolyMarkers3D::DoFill(Long64_t , Double_t , const Double_t *v)
01980 {
01981    // Fills the scatter plot with the given values.
01982 
01983    fPoints->GetVector()->push_back(Point4D_t(v[3], v[2], v[1], v[0]));
01984 }
01985 
01986 
01987 
01988 //______________________________________________________________________________
01989 void TProofDrawListOfPolyMarkers3D::Terminate(void)
01990 {
01991    // See TProofDraw::Terminate().
01992 
01993    PDB(kDraw,1) Info("Terminate","Enter");
01994    TProofDraw::Terminate();
01995    if (!fStatus)
01996       return;
01997 
01998    fPoints = dynamic_cast<TProofVectorContainer<Point4D_t>*>
01999                (fOutput->FindObject("PROOF_SCATTERPLOT"));
02000    if (fPoints) {
02001       std::vector<Point4D_t> *points = fPoints->GetVector();
02002       R__ASSERT(points);
02003       SetStatus((Int_t) points->size());
02004       TH3F* hist;
02005       TObject *orig = fTreeDrawArgsParser.GetOriginal();
02006       if ( (hist = dynamic_cast<TH3F*> (orig)) == 0 || fTreeDrawArgsParser.GetNoParameters() != 0) {
02007          delete orig;
02008          fTreeDrawArgsParser.SetOriginal(0);
02009          double binsx, minx, maxx;
02010          double binsy, miny, maxy;
02011          double binsz, minz, maxz;
02012          if (fTreeDrawArgsParser.IsSpecified(0))
02013             gEnv->SetValue("Hist.Binning.3D.x", fTreeDrawArgsParser.GetParameter(0));
02014          if (fTreeDrawArgsParser.IsSpecified(3))
02015             gEnv->SetValue("Hist.Binning.3D.y", fTreeDrawArgsParser.GetParameter(3));
02016          if (fTreeDrawArgsParser.IsSpecified(6))
02017             gEnv->SetValue("Hist.Binning.3D.z", fTreeDrawArgsParser.GetParameter(3));
02018          binsx = gEnv->GetValue("Hist.Binning.3D.x", 20);
02019          minx =  fTreeDrawArgsParser.GetIfSpecified(1, 0);
02020          maxx =  fTreeDrawArgsParser.GetIfSpecified(2, 0);
02021          binsy = gEnv->GetValue("Hist.Binning.3D.y", 20);
02022          miny =  fTreeDrawArgsParser.GetIfSpecified(4, 0);
02023          maxy =  fTreeDrawArgsParser.GetIfSpecified(5, 0);
02024          binsz = gEnv->GetValue("Hist.Binning.3D.z", 20);
02025          minz =  fTreeDrawArgsParser.GetIfSpecified(7, 0);
02026          maxz =  fTreeDrawArgsParser.GetIfSpecified(8, 0);
02027          hist = new TH3F(fTreeDrawArgsParser.GetObjectName(), fTreeDrawArgsParser.GetObjectTitle(),
02028                         (Int_t) binsx, minx, maxx,
02029                         (Int_t) binsy, miny, maxy,
02030                         (Int_t) binsz, minz, maxz);
02031          hist->SetBit(TH1::kNoStats);
02032          hist->SetBit(kCanDelete);
02033          if (fTreeDrawArgsParser.GetNoParameters() != 9)
02034             hist->SetBit(TH1::kCanRebin);
02035          else
02036             hist->ResetBit(TH1::kCanRebin);
02037 
02038 //         if (fTreeDrawArgsParser.GetShouldDraw())          // ?? FIXME
02039 //            hist->SetDirectory(0);
02040       }
02041       Double_t rmin[4], rmax[4];
02042 
02043 
02044       // FIXME take rmin and rmax from the old histogram
02045       rmin[0] = rmax[0] = rmin[1] = rmax[1] = rmin[2] = rmax[2] = 0;
02046       if (points->size() > 0) {
02047          rmin[0] = rmax[0] = (*points)[0].fX;
02048          rmin[1] = rmax[1] = (*points)[0].fY;
02049          rmin[2] = rmax[2] = (*points)[0].fZ;
02050          rmin[3] = rmax[3] = (*points)[0].fT;
02051 
02052          for (vector<Point4D_t>::const_iterator i = points->begin() + 1; i < points->end(); ++i) {
02053             if (rmax[0] < i->fX) rmax[0] = i->fX;
02054             if (rmax[1] < i->fY) rmax[1] = i->fY;
02055             if (rmax[2] < i->fZ) rmax[2] = i->fZ;
02056             if (rmax[3] < i->fT) rmax[3] = i->fT;
02057             if (rmin[0] > i->fX) rmin[0] = i->fX;
02058             if (rmin[1] > i->fY) rmin[1] = i->fY;
02059             if (rmin[2] > i->fZ) rmin[2] = i->fZ;
02060             if (rmin[3] > i->fT) rmin[3] = i->fT;
02061          }
02062          // in this case we don't care about user-specified limits
02063          if (hist->TestBit(TH1::kCanRebin) && hist->TestBit(kCanDelete)) {
02064             THLimitsFinder::GetLimitsFinder()->FindGoodLimits(hist,
02065                               rmin[1], rmax[1], rmin[2], rmax[2], rmin[3], rmax[3]);
02066          }
02067       }
02068       Int_t ncolors  = gStyle->GetNumberOfColors();
02069       TObjArray *pms = (TObjArray*)hist->GetListOfFunctions()->FindObject("polymarkers");
02070       Int_t col;
02071       TPolyMarker3D *pm3d;
02072       if (!pms) {
02073          pms = new TObjArray(ncolors);
02074          pms->SetOwner();
02075          pms->SetName("polymarkers");
02076          hist->GetListOfFunctions()->Add(pms);
02077          for (col=0;col<ncolors;col++) {
02078             pm3d = new TPolyMarker3D();
02079             pm3d->SetMarkerColor(col);
02080 //            pm3d->SetMarkerStyle(fTree->GetMarkerStyle());
02081 //            pm3d->SetMarkerSize(fTree->GetMarkerSize());
02082             pms->AddAt(pm3d,col);
02083          }
02084       }
02085       for (vector<Point4D_t>::const_iterator i = points->begin();
02086             i < points->end(); ++i) {
02087          col = Int_t(i->fX);
02088          if (col < 0) col = 0;
02089          if (col > ncolors-1) col = ncolors-1;
02090          pm3d = (TPolyMarker3D*)pms->UncheckedAt(col);
02091          pm3d->SetPoint(pm3d->GetLastPoint()+1, i->fY, i->fZ, i->fT);
02092       }
02093       if (fTreeDrawArgsParser.GetShouldDraw()) {
02094          SetDrawAtt(hist);
02095          hist->Draw(fOption.Data());
02096          gPad->Update();
02097       }
02098       fOutput->Remove(fPoints);
02099       SafeDelete(fPoints);
02100    }
02101 }

Generated on Tue Jul 5 14:52:19 2011 for ROOT_528-00b_version by  doxygen 1.5.1