00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TSpider.h"
00013 #include "TAttFill.h"
00014 #include "TAttText.h"
00015 #include "TAttLine.h"
00016 #include "TGraphPolargram.h"
00017 #include "TPolyLine.h"
00018 #include "TNtuple.h"
00019 #include "TTreeFormula.h"
00020 #include "TTreeFormulaManager.h"
00021 #include "TList.h"
00022 #include "TSelectorDraw.h"
00023 #include "TROOT.h"
00024 #include "TEntryList.h"
00025 #include "TLatex.h"
00026 #include "TPad.h"
00027 #include "TMath.h"
00028 #include "TCanvas.h"
00029 #include "TArc.h"
00030 #include "float.h"
00031 #include "TEnv.h"
00032
00033 ClassImp(TSpider)
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 TSpider::TSpider()
00072 {
00073
00074
00075 fDisplayAverage=kFALSE;
00076 fForceDim=kFALSE;
00077 fPolargram=NULL;
00078 fInput=NULL;
00079 fManager=NULL;
00080 fNcols=0;
00081 fNx=3;
00082 fNy=4;
00083 fPolyList=NULL;
00084 fSelect=NULL;
00085 fSelector=NULL;
00086 fTree=NULL;
00087 fMax=NULL;
00088 fMin=NULL;
00089 fAve=NULL;
00090 fCanvas=NULL;
00091 fAveragePoly=NULL;
00092 fEntry=0;
00093 fSuperposed=NULL;
00094 fShowRange=kFALSE;
00095 fAngularLabels=kFALSE;
00096 fAverageSlices=NULL;
00097 fSegmentDisplay=kFALSE;
00098 fNentries=0;
00099 fFirstEntry=0;
00100 fArraySize=0;
00101 fCurrentEntries = NULL;
00102 fFormulas = NULL;
00103 }
00104
00105
00106
00107 TSpider::TSpider(TTree* tree ,const char *varexp, const char *selection,
00108 Option_t *option, Long64_t nentries, Long64_t firstentry)
00109 : TAttFill(2,3003), TAttLine(1,1,1)
00110 {
00111
00112
00113 UInt_t ui=0;
00114
00115 fArraySize = 16;
00116 fTree=tree;
00117 fSelector= new TSelectorDraw();
00118 fFormulas= new TList();
00119 fInput= new TList();
00120 fInput->Add(new TNamed("varexp",""));
00121 fInput->Add(new TNamed("selection",""));
00122 fSelector->SetInputList(fInput);
00123 gROOT->GetListOfCleanups()->Add(this);
00124 fNx=2;
00125 fNy=2;
00126 fDisplayAverage=kFALSE;
00127 fSelect=NULL;
00128 fManager=NULL;
00129 fCanvas=NULL;
00130 fAveragePoly=NULL;
00131 fEntry=fFirstEntry;
00132 fSuperposed=NULL;
00133 fShowRange=kFALSE;
00134 fAngularLabels=kTRUE;
00135 fForceDim=kFALSE;
00136 fAverageSlices=NULL;
00137 fSegmentDisplay=kFALSE;
00138 if (firstentry < 0 || firstentry > tree->GetEstimate()) firstentry = 0;
00139 fFirstEntry = firstentry;
00140 if (nentries>0) fNentries = nentries;
00141 else fNentries = nentries = tree->GetEstimate()-firstentry;
00142
00143 fEntry = fFirstEntry;
00144
00145 fPolargram=NULL;
00146 fPolyList=NULL;
00147
00148 fTree->SetScanField(fNx*fNy);
00149 fCurrentEntries = new Long64_t[fNx*fNy];
00150 for(ui=0;ui<fNx*fNy;++ui) fCurrentEntries[ui]=0;
00151
00152 TString opt = option;
00153
00154 if (opt.Contains("average")) fDisplayAverage=kTRUE;
00155 if (opt.Contains("showrange")) fShowRange=kTRUE;
00156 if (opt.Contains("segment")) fSegmentDisplay=kTRUE;
00157
00158 fNcols=8;
00159
00160 SetVariablesExpression(varexp);
00161 SetSelectionExpression(selection);
00162 SyncFormulas();
00163 InitVariables(firstentry,nentries);
00164 }
00165
00166
00167
00168 TSpider::~TSpider()
00169 {
00170
00171
00172 delete [] fCurrentEntries;
00173 if(fPolyList){
00174 fPolyList->Delete();
00175 delete fPolyList;
00176 }
00177 if(fAverageSlices)
00178 delete [] fAverageSlices;
00179 if(fFormulas){
00180 fFormulas->Delete();
00181 delete fFormulas;
00182 }
00183 if(fSelect) delete fSelect;
00184 if(fSelector) delete fSelector;
00185 if(fInput){
00186 fInput->Delete();
00187 delete fInput;
00188 }
00189 if(fMax) delete [] fMax;
00190 if(fMin) delete [] fMin;
00191 if(fAve) delete [] fAve;
00192 if(fSuperposed){
00193 fSuperposed->Delete();
00194 delete fSuperposed;
00195 }
00196 fCanvas->cd(0);
00197 }
00198
00199
00200
00201 void TSpider::AddSuperposed(TSpider* sp)
00202 {
00203
00204
00205 if(!fSuperposed) fSuperposed=new TList();
00206 fSuperposed->Add(sp);
00207 }
00208
00209
00210
00211 void TSpider::AddVariable(const char* varexp)
00212 {
00213
00214
00215 if(!strlen(varexp)) return;
00216 TTreeFormula *fvar = new TTreeFormula("Var1",varexp,fTree);
00217 if(fvar->GetNdim() <= 0) return;
00218
00219 fFormulas->AddAfter(fFormulas->At(fNcols-1),fvar);
00220
00221 InitArrays(fNcols + 1);
00222 ++fNcols;
00223 SyncFormulas();
00224
00225 UInt_t ui=0;
00226 Long64_t notSkipped=0;
00227 Int_t tnumber=-1;
00228 Long64_t entryNumber;
00229 Long64_t entry = fFirstEntry;
00230 Int_t entriesToDisplay = fNentries;
00231 while(entriesToDisplay!=0){
00232 entryNumber = fTree->GetEntryNumber(entry);
00233 if(entryNumber < 0) break;
00234 Long64_t localEntry = fTree->LoadTree(entryNumber);
00235 if(localEntry < 0) break;
00236 if(tnumber != fTree->GetTreeNumber()) {
00237 tnumber = fTree->GetTreeNumber();
00238 if(fManager) fManager->UpdateFormulaLeaves();
00239 else {
00240 for(Int_t i=0;i<=fFormulas->LastIndex();++i)
00241 ((TTreeFormula*)fFormulas->At(i))->UpdateFormulaLeaves();
00242 }
00243 }
00244 Int_t ndata=1;
00245 if(fForceDim){
00246 if(fManager)
00247 ndata = fManager->GetNdata(kTRUE);
00248 else {
00249 for(ui=0;ui<fNcols;++ui){
00250 if(ndata<((TTreeFormula*)fFormulas->At(ui))->GetNdata())
00251 ndata = ((TTreeFormula*)fFormulas->At(ui))->GetNdata();
00252 }
00253 if(fSelect && fSelect->GetNdata() == 0)
00254 ndata = 0;
00255 }
00256 }
00257
00258 Bool_t loaded = kFALSE;
00259 Bool_t skip = kFALSE;
00260
00261 for(Int_t inst=0;inst<ndata;++inst){
00262 if(fSelect){
00263 if(fSelect->EvalInstance(inst) == 0){
00264 skip = kTRUE;
00265 ++entry;
00266 }
00267 }
00268 if (!loaded) {
00269
00270
00271 ((TTreeFormula*)fFormulas->At(fNcols-1))->EvalInstance(0);
00272 loaded = kTRUE;
00273 } else if (inst == 0) {
00274 loaded = kTRUE;
00275 }
00276 }
00277 if(!skip){
00278 fTree->LoadTree(entryNumber);
00279 TTreeFormula* var = (TTreeFormula*)fFormulas->At(fNcols-1);
00280 if(var->EvalInstance()>fMax[fNcols-1]) fMax[fNcols-1]=var->EvalInstance();
00281 if(var->EvalInstance()<fMin[fNcols-1]) fMin[fNcols-1]=var->EvalInstance();
00282 fAve[fNcols-1]+=var->EvalInstance();
00283 ++notSkipped;
00284 --entriesToDisplay;
00285 ++entry;
00286 }
00287 }
00288 fAve[fNcols-1]/=notSkipped;
00289
00290 Color_t lc;
00291 Style_t lt;
00292 Width_t lw;
00293 Color_t fc;
00294 Style_t fs;
00295
00296 if(fAverageSlices){
00297 lc = fAverageSlices[0]->GetLineColor();
00298 lt = fAverageSlices[0]->GetLineStyle();
00299 lw = fAverageSlices[0]->GetLineWidth();
00300 fc = fAverageSlices[0]->GetFillColor();
00301 fs = fAverageSlices[0]->GetFillStyle();
00302 } else {
00303 lc = fAveragePoly->GetLineColor();
00304 lt = fAveragePoly->GetLineStyle();
00305 lw = fAveragePoly->GetLineWidth();
00306 fc = fAveragePoly->GetFillColor();
00307 fs = fAveragePoly->GetFillStyle();
00308 }
00309
00310 delete fPolargram;
00311 fPolargram = NULL;
00312
00313 if(fSegmentDisplay){
00314 for(ui=0;ui<fNx*fNy;++ui) ((TList*)fPolyList->At(ui))->Delete();
00315 if (fAverageSlices) for(ui=0;ui<fNcols-1;++ui) delete fAverageSlices[ui];
00316 }
00317 fPolyList->Delete();
00318 delete fPolyList;
00319 fPolyList = NULL;
00320 delete [] fAverageSlices;
00321 fAverageSlices = NULL;
00322 delete fAveragePoly;
00323 fAveragePoly = NULL;
00324
00325 fCanvas->Clear();
00326 fCanvas->Divide(fNx,fNy);
00327 Draw("");
00328
00329 if(fAverageSlices){
00330 for(ui = 0;ui<fNcols;++ui){
00331 fAverageSlices[ui]->SetLineColor(lc);
00332 fAverageSlices[ui]->SetLineStyle(lt);
00333 fAverageSlices[ui]->SetLineWidth(lw);
00334 fAverageSlices[ui]->SetFillColor(fc);
00335 fAverageSlices[ui]->SetFillStyle(fs);
00336 }
00337 } else {
00338 fAveragePoly->SetLineColor(lc);
00339 fAveragePoly->SetLineStyle(lt);
00340 fAveragePoly->SetLineWidth(lw);
00341 fAveragePoly->SetFillColor(fc);
00342 fAveragePoly->SetFillStyle(fs);
00343 }
00344 }
00345
00346
00347
00348 void TSpider::DeleteVariable(const char* varexp)
00349 {
00350
00351
00352 Int_t var=-1;
00353 UInt_t ui=0;
00354
00355 if(fNcols == 2) return;
00356 for(ui=0; ui<fNcols;++ui){
00357 if(!strcmp(varexp,((TTreeFormula*)fFormulas->At(ui))->GetTitle())) var = ui;
00358 }
00359 if(var<0) return;
00360
00361 fFormulas->Remove(fFormulas->At(var));
00362 SyncFormulas();
00363
00364 for(ui=var+1;ui<fNcols;++ui){
00365 fMin[ui-1] = fMin[ui];
00366 fMax[ui-1] = fMax[ui];
00367 fAve[ui-1] = fAve[ui];
00368 }
00369 fMin[fNcols-1] = FLT_MAX;
00370 fMax[fNcols-1] = -FLT_MAX;
00371 fAve[fNcols-1] = 0;
00372 --fNcols;
00373
00374 Color_t lc;
00375 Style_t lt;
00376 Width_t lw;
00377 Color_t fc;
00378 Style_t fs;
00379
00380 if(fAverageSlices){
00381 lc = fAverageSlices[0]->GetLineColor();
00382 lt = fAverageSlices[0]->GetLineStyle();
00383 lw = fAverageSlices[0]->GetLineWidth();
00384 fc = fAverageSlices[0]->GetFillColor();
00385 fs = fAverageSlices[0]->GetFillStyle();
00386 } else {
00387 lc = fAveragePoly->GetLineColor();
00388 lt = fAveragePoly->GetLineStyle();
00389 lw = fAveragePoly->GetLineWidth();
00390 fc = fAveragePoly->GetFillColor();
00391 fs = fAveragePoly->GetFillStyle();
00392 }
00393
00394 delete fPolargram;
00395 fPolargram = NULL;
00396
00397 if(fSegmentDisplay){
00398 for(ui=0;ui<fNx*fNy;++ui) ((TList*)fPolyList->At(ui))->Delete();
00399 if (fAverageSlices) for(ui=0;ui<=fNcols;++ui) delete fAverageSlices[ui];
00400 }
00401 fPolyList->Delete();
00402 delete fPolyList;
00403 fPolyList = NULL;
00404 delete [] fAverageSlices;
00405 fAverageSlices = NULL;
00406 delete fAveragePoly;
00407 fAveragePoly = NULL;
00408
00409 fCanvas->Clear();
00410 fCanvas->Divide(fNx,fNy);
00411 Draw("");
00412 if(fNcols == 2) SetSegmentDisplay(kTRUE);
00413
00414 if(fAverageSlices){
00415 for(ui = 0;ui<fNcols;++ui){
00416 fAverageSlices[ui]->SetLineColor(lc);
00417 fAverageSlices[ui]->SetLineStyle(lt);
00418 fAverageSlices[ui]->SetLineWidth(lw);
00419 fAverageSlices[ui]->SetFillColor(fc);
00420 fAverageSlices[ui]->SetFillStyle(fs);
00421 }
00422 } else {
00423 fAveragePoly->SetLineColor(lc);
00424 fAveragePoly->SetLineStyle(lt);
00425 fAveragePoly->SetLineWidth(lw);
00426 fAveragePoly->SetFillColor(fc);
00427 fAveragePoly->SetFillStyle(fs);
00428 }
00429 }
00430
00431
00432
00433 Int_t TSpider::DistancetoPrimitive(Int_t px, Int_t py)
00434 {
00435
00436
00437 if(!gPad) return 9999;
00438 Double_t xx,yy,r2;
00439 xx=gPad->AbsPixeltoX(px);
00440 yy=gPad->AbsPixeltoY(py);
00441 r2 = xx*xx + yy*yy;
00442 if(r2>1 && r2<1.5)
00443 return 0;
00444 else return 9999;
00445 }
00446
00447
00448
00449 void TSpider::Draw(Option_t *options)
00450 {
00451
00452
00453 UInt_t ui=0;
00454
00455 gEnv->SetValue("Canvas.ShowEditor",1);
00456 if(!gPad && !fCanvas){
00457 fCanvas = new TCanvas("screen","Spider Plot",fNx*256,fNy*256);
00458 fCanvas->Divide(fNx,fNy);
00459 } else if(!fCanvas){
00460 fCanvas = (TCanvas*)gPad;
00461 fCanvas->Divide(fNx,fNy);
00462 }
00463 if(fPolargram) delete fPolargram;
00464 fPolargram=new TGraphPolargram("fPolargram");
00465 fPolargram->SetNdivPolar(fNcols);
00466 fPolargram->SetNdivRadial(0);
00467 fCanvas->cd();
00468 SetCurrentEntries();
00469 AppendPad(options);
00470 for(ui=0;ui<fNx*fNy;++ui){
00471 fCanvas->cd(ui+1);
00472 fPolargram->Draw("pn");
00473 fTree->LoadTree(fCurrentEntries[ui]);
00474 if(fSegmentDisplay){
00475 if(fDisplayAverage) DrawSlicesAverage("");
00476 DrawSlices("");
00477 } else {
00478 if(fDisplayAverage) DrawPolyAverage("");
00479 DrawPoly("");
00480 }
00481 AppendPad();
00482 }
00483 fCanvas->Selected(fCanvas,this,1);
00484 }
00485
00486
00487
00488 void TSpider::DrawPolyAverage(Option_t* )
00489 {
00490
00491
00492 Int_t linecolor=4;
00493 Int_t fillstyle=0;
00494 Int_t fillcolor=linecolor;
00495 Int_t linewidth=1;
00496 Int_t linestyle=1;
00497
00498 UInt_t ui=0;
00499 Double_t slice = 2*TMath::Pi()/fNcols;
00500 Double_t *x = new Double_t[fNcols+1];
00501 Double_t *y = new Double_t[fNcols+1];
00502
00503 for(ui=0;ui<fNcols;++ui){
00504 x[ui]=(fAve[ui]-fMin[ui])/(fMax[ui]-fMin[ui])*TMath::Cos(ui*slice);
00505 y[ui]=(fAve[ui]-fMin[ui])/(fMax[ui]-fMin[ui])*TMath::Sin(ui*slice);
00506 }
00507 x[fNcols]=(fAve[0]-fMin[0])/(fMax[0]-fMin[0]);
00508 y[fNcols]=0;
00509
00510 if(!fAveragePoly){
00511 fAveragePoly = new TPolyLine(fNcols+1,x,y);
00512 fAveragePoly->SetLineColor(linecolor);
00513 fAveragePoly->SetLineWidth(linewidth);
00514 fAveragePoly->SetLineStyle(linestyle);
00515 fAveragePoly->SetFillStyle(fillstyle);
00516 fAveragePoly->SetFillColor(fillcolor);
00517 }
00518 fAveragePoly->Draw();
00519 fAveragePoly->Draw("f");
00520
00521 delete [] x;
00522 delete [] y;
00523 }
00524
00525
00526
00527 void TSpider::DrawPoly(Option_t* )
00528 {
00529
00530
00531 if(!fPolyList) fPolyList = new TList();
00532 Double_t *x = new Double_t[fNcols+1];
00533 Double_t *y = new Double_t[fNcols+1];
00534
00535 Double_t slice = 2*TMath::Pi()/fNcols;
00536 for(UInt_t i=0;i<fNcols;++i){
00537 x[i]=(((TTreeFormula*)fFormulas->At(i))->EvalInstance()-fMin[i])/(fMax[i]-fMin[i])*TMath::Cos(i*slice);
00538 y[i]=(((TTreeFormula*)fFormulas->At(i))->EvalInstance()-fMin[i])/(fMax[i]-fMin[i])*TMath::Sin(i*slice);
00539 }
00540 x[fNcols]=(((TTreeFormula*)fFormulas->At(0))->EvalInstance()-fMin[0])/(fMax[0]-fMin[0]);
00541 y[fNcols]=0;
00542
00543 TPolyLine* poly= new TPolyLine(fNcols+1,x,y);
00544 poly->SetFillColor(GetFillColor());
00545 poly->SetFillStyle(GetFillStyle());
00546 poly->SetLineWidth(GetLineWidth());
00547 poly->SetLineColor(GetLineColor());
00548 poly->SetLineStyle(GetLineStyle());
00549 poly->Draw("f");
00550 poly->Draw();
00551 fPolyList->Add(poly);
00552 delete [] x;
00553 delete [] y;
00554 }
00555
00556
00557
00558 void TSpider::DrawSlices(Option_t* options)
00559 {
00560
00561
00562 UInt_t ui=0;
00563
00564 Double_t angle = 2*TMath::Pi()/fNcols;
00565 Double_t conv = 180.0/TMath::Pi();
00566
00567 if(!fPolyList) fPolyList = new TList;
00568 TList* li = new TList();
00569 for(ui=0;ui<fNcols;++ui){
00570 Double_t r = (((TTreeFormula*)fFormulas->At(ui))->EvalInstance()-fMin[ui])/(fMax[ui]-fMin[ui]);
00571 TArc* slice = new TArc(0,0,r,(ui-0.25)*angle*conv,(ui+0.25)*angle*conv);
00572 slice->SetFillColor(GetFillColor());
00573 slice->SetFillStyle(GetFillStyle());
00574 slice->SetLineWidth(GetLineWidth());
00575 slice->SetLineColor(GetLineColor());
00576 slice->SetLineStyle(GetLineStyle());
00577 li->Add(slice);
00578 slice->Draw(options);
00579 }
00580 fPolyList->Add(li);
00581 }
00582
00583
00584
00585 void TSpider::DrawSlicesAverage(Option_t* )
00586 {
00587
00588
00589 UInt_t ui=0;
00590
00591 Int_t fillstyle=3002;
00592 Int_t linecolor=4;
00593 Int_t fillcolor=linecolor;
00594 Int_t linewidth=1;
00595 Int_t linestyle=1;
00596
00597 Double_t angle = 2*TMath::Pi()/fNcols;
00598 Double_t conv = 180.0/TMath::Pi();
00599
00600 if(!fAverageSlices){
00601 fAverageSlices = new TArc*[fNcols];
00602 for(ui=0;ui<fNcols;++ui){
00603 Double_t r = (fAve[ui]-fMin[ui])/(fMax[ui]-fMin[ui]);
00604 fAverageSlices[ui] = new TArc(0,0,r,(ui-0.5)*angle*conv,(ui+0.5)*angle*conv);
00605 fAverageSlices[ui]->SetFillColor(fillcolor);
00606 fAverageSlices[ui]->SetFillStyle(fillstyle);
00607 fAverageSlices[ui]->SetLineWidth(linewidth);
00608 fAverageSlices[ui]->SetLineColor(linecolor);
00609 fAverageSlices[ui]->SetLineStyle(linestyle);
00610 }
00611 }
00612 for(ui=0;ui<fNcols;++ui) fAverageSlices[ui]->Draw();
00613 }
00614
00615
00616
00617 Style_t TSpider::GetAverageLineStyle() const
00618 {
00619
00620
00621 if(fAverageSlices) return fAverageSlices[0]->GetLineStyle();
00622 else if(fAveragePoly) return fAveragePoly->GetLineStyle();
00623 else return 0;
00624 }
00625
00626
00627
00628 Color_t TSpider::GetAverageLineColor() const
00629 {
00630
00631
00632 if(fAverageSlices) return fAverageSlices[0]->GetLineColor();
00633 else if(fAveragePoly) return fAveragePoly->GetLineColor();
00634 else return 0;
00635 }
00636
00637
00638
00639 Width_t TSpider::GetAverageLineWidth() const
00640 {
00641
00642
00643 if(fAverageSlices) return fAverageSlices[0]->GetLineWidth();
00644 else if(fAveragePoly) return fAveragePoly->GetLineWidth();
00645 else return 0;
00646 }
00647
00648
00649
00650 Color_t TSpider::GetAverageFillColor() const
00651 {
00652
00653
00654 if(fAverageSlices) return fAverageSlices[0]->GetFillColor();
00655 else if(fAveragePoly) return fAveragePoly->GetFillColor();
00656 else return 0;
00657 }
00658
00659
00660
00661 Style_t TSpider::GetAverageFillStyle() const
00662 {
00663
00664
00665 if(fAverageSlices) return fAverageSlices[0]->GetFillStyle();
00666 else if(fAveragePoly) return fAveragePoly->GetFillStyle();
00667 else return 0;
00668 }
00669
00670
00671
00672 void TSpider::ExecuteEvent(Int_t ,Int_t , Int_t )
00673 {
00674
00675
00676 gPad->SetCursor(kHand);
00677 }
00678
00679
00680
00681 Int_t TSpider::FindTextAlign(Double_t angle)
00682 {
00683
00684
00685 Double_t pi = TMath::Pi();
00686
00687 while(angle < 0 || angle > 2*pi){
00688 if(angle < 0) angle+=2*pi;
00689 if(angle > 2*pi) angle-=2*pi;
00690 }
00691 if(!fAngularLabels){
00692 if(angle > 0 && angle < pi/2) return 11;
00693 else if(angle > pi/2 && angle < pi) return 31;
00694 else if(angle > pi && angle < 3*pi/2) return 33;
00695 else if(angle > 3*pi/2 && angle < 2*pi) return 13;
00696 else if(angle == 0 || angle == 2*pi) return 12;
00697 else if(angle == pi/2) return 21;
00698 else if(angle == pi) return 32;
00699 else if(angle == 3*pi/2) return 23;
00700 else return 0;
00701 }
00702 else{
00703 if(angle >= 0 && angle < pi) return 21;
00704 else if(angle >=pi && angle <= 2*pi) return 23;
00705 else return 0;
00706 }
00707 }
00708
00709
00710
00711 Double_t TSpider::FindTextAngle(Double_t angle)
00712 {
00713
00714
00715 Double_t pi = TMath::Pi();
00716 Double_t convraddeg = 180.0/pi;
00717
00718 while(angle < 0 || angle > 2*pi){
00719 if(angle < 0) angle+=2*pi;
00720 if(angle > 2*pi) angle-=2*pi;
00721 }
00722
00723 if(angle >= 0 && angle <= pi/2) return angle*convraddeg - 90;
00724 else if(angle > pi/2 && angle <= pi) return (angle + pi)*convraddeg + 90;
00725 else if(angle > pi && angle <= 3*pi/2) return (angle - pi)*convraddeg - 90;
00726 else if(angle > 3*pi/2 && angle <= 2*pi) return angle*convraddeg + 90;
00727 else return 0;
00728 }
00729
00730
00731
00732 Long64_t TSpider::GetEntriesToProcess(Long64_t firstentry, Long64_t nentries) const
00733 {
00734
00735
00736
00737
00738 Long64_t lastentry = firstentry + nentries - 1;
00739 if (lastentry > fTree->GetEntriesFriend()-1) {
00740 lastentry = fTree->GetEntriesFriend() - 1;
00741 nentries = lastentry - firstentry + 1;
00742 }
00743
00744
00745 TEntryList *elist = fTree->GetEntryList();
00746 if (elist && elist->GetN() < nentries) nentries = elist->GetN();
00747 return nentries;
00748 }
00749
00750
00751
00752 void TSpider::GotoEntry(Long64_t e)
00753 {
00754
00755
00756 if(e<fFirstEntry || e+fTree->GetScanField()>=fFirstEntry + fNentries) return;
00757 fEntry = e;
00758 SetCurrentEntries();
00759 }
00760
00761
00762
00763 void TSpider::GotoNext()
00764 {
00765
00766
00767 if(fEntry + 2*fTree->GetScanField() -1 >= fFirstEntry + fNentries) fEntry = fFirstEntry;
00768 else fEntry=fCurrentEntries[fTree->GetScanField()-1]+1;
00769 SetCurrentEntries();
00770 }
00771
00772
00773
00774 void TSpider::GotoPrevious()
00775 {
00776
00777
00778 if(fEntry-fTree->GetScanField() < fFirstEntry) fEntry = fFirstEntry + fNentries -1 - fTree->GetScanField();
00779 else fEntry -= fTree->GetScanField();
00780 SetCurrentEntries();
00781 }
00782
00783
00784
00785 void TSpider::GotoFollowing()
00786 {
00787
00788
00789 if(fEntry + fTree->GetScanField() >= fFirstEntry + fNentries) return;
00790 ++fEntry;
00791 SetCurrentEntries();
00792 }
00793
00794
00795
00796 void TSpider::GotoPreceding()
00797 {
00798
00799
00800 if(fEntry - 1 < fFirstEntry) return;
00801 --fEntry;
00802 SetCurrentEntries();
00803 }
00804
00805
00806
00807 void TSpider::InitArrays(Int_t newsize)
00808 {
00809
00810
00811 if(newsize>fArraySize){
00812
00813 Int_t i;
00814 Int_t old = fArraySize;
00815
00816 while(fArraySize<newsize) fArraySize*=2;
00817
00818 Double_t *memmax = new Double_t[fArraySize];
00819 Double_t *memmin = new Double_t[fArraySize];
00820 Double_t *memave = new Double_t[fArraySize];
00821
00822 for(i=0;i<fArraySize;++i){
00823 if(i<old){
00824 memmax[i] = fMax[i];
00825 memmin[i] = fMin[i];
00826 memave[i] = fAve[i];
00827 } else {
00828 memmax[i] = -FLT_MAX;
00829 memmin[i] = FLT_MAX;
00830 memave[i] = 0;
00831 }
00832 }
00833
00834 delete [] fMax;
00835 delete [] fMin;
00836 delete [] fAve;
00837
00838 fMax = memmax;
00839 fMin = memmin;
00840 fAve = memave;
00841 }
00842 }
00843
00844
00845
00846 void TSpider::InitVariables(Long64_t firstentry, Long64_t nentries)
00847 {
00848
00849
00850 UInt_t ui=0;
00851 Int_t i;
00852
00853 fMax = new Double_t [fArraySize];
00854 fMin= new Double_t [fArraySize];
00855 fAve= new Double_t [fArraySize];
00856
00857 for(i=0;i<fArraySize;++i){
00858 fMax[i]= -FLT_MAX;
00859 fMin[i]= FLT_MAX;
00860 fAve[i]=0;
00861 }
00862
00863 Long64_t notSkipped=0;
00864 Int_t tnumber=-1;
00865 Long64_t entryNumber;
00866 Long64_t entry = firstentry;
00867 Int_t entriesToDisplay = nentries;
00868 while(entriesToDisplay!=0){
00869 entryNumber = fTree->GetEntryNumber(entry);
00870 if(entryNumber < 0) break;
00871 Long64_t localEntry = fTree->LoadTree(entryNumber);
00872 if(localEntry < 0) break;
00873 if(tnumber != fTree->GetTreeNumber()) {
00874 tnumber = fTree->GetTreeNumber();
00875 if(fManager) fManager->UpdateFormulaLeaves();
00876 else {
00877 for(i=0;i<=fFormulas->LastIndex();++i)
00878 ((TTreeFormula*)fFormulas->At(i))->UpdateFormulaLeaves();
00879 }
00880 }
00881 Int_t ndata=1;
00882 if(fForceDim){
00883 if(fManager)
00884 ndata = fManager->GetNdata(kTRUE);
00885 else {
00886 for(ui=0;ui<fNcols;++ui){
00887 if(ndata<((TTreeFormula*)fFormulas->At(ui))->GetNdata())
00888 ndata = ((TTreeFormula*)fFormulas->At(ui))->GetNdata();
00889 }
00890 if(fSelect && fSelect->GetNdata() == 0)
00891 ndata = 0;
00892 }
00893 }
00894 Bool_t loaded = kFALSE;
00895 Bool_t skip = kFALSE;
00896
00897 for(Int_t inst=0;inst<ndata;++inst){
00898 if(fSelect){
00899 if(fSelect->EvalInstance(inst) == 0){
00900 skip = kTRUE;
00901 ++entry;
00902 }
00903 }
00904 if (!loaded) {
00905
00906
00907 for (ui=0;ui<fNcols;ui++) {
00908 ((TTreeFormula*)fFormulas->At(ui))->EvalInstance(0);
00909 }
00910 loaded = kTRUE;
00911 } else if (inst == 0) {
00912 loaded = kTRUE;
00913 }
00914 }
00915 if(!skip){
00916 fTree->LoadTree(entryNumber);
00917 for(ui=0;ui<fNcols;++ui){
00918 Double_t inst = ((TTreeFormula*)fFormulas->At(ui))->EvalInstance();
00919 if(inst > fMax[ui]) fMax[ui] = inst;
00920 if(inst < fMin[ui]) fMin[ui] = inst;
00921 fAve[ui] += inst;
00922 }
00923 ++notSkipped;
00924 --entriesToDisplay;
00925 ++entry;
00926 }
00927 }
00928 for(ui=0;ui<fNcols;++ui) fAve[ui]/=notSkipped;
00929 }
00930
00931
00932
00933 void TSpider::Paint(Option_t* options)
00934 {
00935
00936
00937 UInt_t ui=0;
00938 TString opt = options;
00939
00940 if(opt.Contains("n")) return;
00941
00942 Double_t slice = 2*TMath::Pi()/fNcols;
00943 Double_t offset(1.0);
00944 if (!fCanvas) {
00945 if (gPad) fCanvas = gPad->GetCanvas();
00946 else return;
00947 }
00948
00949 TLatex *txt = new TLatex();
00950 for(ui=0;ui<fNx*fNy;++ui){
00951 txt->SetTextAlign(13);
00952 fCanvas->cd(ui+1);
00953 if (fCurrentEntries) {
00954 txt->PaintLatex(-1.2,1.2,0,0.08,Form("#%d",(int)fCurrentEntries[ui]));
00955 }
00956 txt->SetTextSize(0.035);
00957 for(UInt_t var=0;var<fNcols;++var){
00958 if(ui==0){
00959 txt->SetTextAlign(FindTextAlign(var*slice));
00960 offset = 1.09 + txt->GetTextSize();
00961 txt->PaintLatex(offset*TMath::Cos(var*slice),offset*TMath::Sin(var*slice),
00962 FindTextAngle(var*slice),0.035,fFormulas->At(var)->GetTitle());
00963 offset= 1.03;
00964 txt->PaintLatex(offset*TMath::Cos(var*slice),offset*TMath::Sin(var*slice),
00965 FindTextAngle(var*slice),0.035,Form("[%5.3f,%5.3f]",fMin[var],fMax[var]));
00966 }
00967 else {
00968 txt->SetTextAlign(FindTextAlign(var*slice));
00969 if(var*slice >=0 && var*slice <= TMath::Pi()) offset =1.13 + txt->GetTextSize();
00970 else offset = 1.09 + txt->GetTextSize();
00971 txt->PaintLatex(offset*TMath::Cos(var*slice),offset*TMath::Sin(var*slice),
00972 FindTextAngle(var*slice),0.035,fFormulas->At(var)->GetTitle());
00973 }
00974 }
00975 }
00976 delete txt;
00977 }
00978
00979
00980
00981 void TSpider::SetAverageLineStyle(Style_t sty)
00982 {
00983
00984
00985 UInt_t ui=0;
00986
00987 if(fAverageSlices){
00988 for(ui=0;ui<fNcols;++ui) fAverageSlices[ui]->SetLineStyle(sty);
00989 } else if(fAveragePoly) fAveragePoly->SetLineStyle(sty);
00990 }
00991
00992
00993
00994 void TSpider::SetAverageLineColor(Color_t col)
00995 {
00996
00997
00998 UInt_t ui=0;
00999
01000 if(fAverageSlices){
01001 for(ui=0;ui<fNcols;++ui) fAverageSlices[ui]->SetLineColor(col);
01002 } else if(fAveragePoly) fAveragePoly->SetLineColor(col);
01003 }
01004
01005
01006
01007 void TSpider::SetAverageLineWidth(Width_t wid)
01008 {
01009
01010
01011 UInt_t ui=0;
01012
01013 if(fAverageSlices){
01014 for(ui=0;ui<fNcols;++ui) fAverageSlices[ui]->SetLineWidth(wid);
01015 } else if(fAveragePoly) fAveragePoly->SetLineWidth(wid);
01016 }
01017
01018
01019
01020 void TSpider::SetAverageFillColor(Color_t col)
01021 {
01022
01023
01024 UInt_t ui=0;
01025
01026 if(fAverageSlices){
01027 for(ui=0;ui<fNcols;++ui) fAverageSlices[ui]->SetFillColor(col);
01028 } else if(fAveragePoly) fAveragePoly->SetFillColor(col);
01029 }
01030
01031
01032
01033 void TSpider::SetAverageFillStyle(Style_t sty)
01034 {
01035
01036
01037 UInt_t ui=0;
01038
01039 if(fAverageSlices){
01040 for(ui=0;ui<fNcols;++ui) fAverageSlices[ui]->SetFillStyle(sty);
01041 } else if(fAveragePoly) fAveragePoly->SetFillStyle(sty);
01042 }
01043
01044
01045
01046 void TSpider::SetDisplayAverage(Bool_t disp)
01047 {
01048
01049
01050 if(disp == fDisplayAverage) return;
01051
01052 UInt_t ui=0;
01053
01054 fDisplayAverage = disp;
01055 delete fAveragePoly;
01056 fAveragePoly = NULL;
01057 if(fAverageSlices){
01058 for(ui = 0;ui<fNcols;++ui) delete fAverageSlices[ui];
01059 }
01060 delete [] fAverageSlices;
01061 fAverageSlices = NULL;
01062
01063 for(ui=0;ui<fNx*fNy;++ui){
01064 fCanvas->cd(ui+1);
01065 gPad->Clear();
01066 }
01067
01068 for(ui = 0; ui < fNx*fNy; ++ui){
01069 fCanvas->cd(ui+1);
01070 fPolargram->Draw("pn");
01071 fTree->LoadTree(fCurrentEntries[ui]);
01072 if(fSegmentDisplay){
01073 if(disp) DrawSlicesAverage("");
01074 DrawSlices("");
01075 } else {
01076 if(disp) DrawPolyAverage("");
01077 DrawPoly("");
01078 }
01079 AppendPad();
01080 }
01081 fCanvas->Modified();
01082 fCanvas->Update();
01083 }
01084
01085
01086
01087 void TSpider::SetCurrentEntries()
01088 {
01089
01090
01091 Int_t i;
01092 UInt_t ui=0;
01093 Int_t tnumber=-1;
01094 Long64_t entryNumber;
01095 Long64_t entry = fEntry;
01096 Int_t entriesToDisplay = fTree->GetScanField();
01097
01098 if(!fCurrentEntries) fCurrentEntries = new Long64_t[fTree->GetScanField()];
01099
01100 while(entriesToDisplay!=0){
01101 entryNumber = fTree->GetEntryNumber(entry);
01102 if(entryNumber < 0) break;
01103 Long64_t localEntry = fTree->LoadTree(entryNumber);
01104 if(localEntry < 0) break;
01105 if(tnumber != fTree->GetTreeNumber()) {
01106 tnumber = fTree->GetTreeNumber();
01107 if(fManager) fManager->UpdateFormulaLeaves();
01108 else {
01109 for(i=0;i<=fFormulas->LastIndex();++i)
01110 ((TTreeFormula*)fFormulas->At(i))->UpdateFormulaLeaves();
01111 }
01112 }
01113 Int_t ndata=1;
01114 if(fForceDim){
01115 if(fManager)
01116 ndata = fManager->GetNdata(kTRUE);
01117 else {
01118 for(ui=0;ui<fNcols;++ui){
01119 if(ndata < ((TTreeFormula*)fFormulas->At(ui))->GetNdata())
01120 ndata = ((TTreeFormula*)fFormulas->At(ui))->GetNdata();
01121 }
01122 if(fSelect && fSelect->GetNdata() == 0)
01123 ndata = 0;
01124 }
01125 }
01126 Bool_t loaded = kFALSE;
01127 Bool_t skip = kFALSE;
01128
01129 for(Int_t inst=0;inst<ndata;++inst){
01130 if(fSelect){
01131 if(fSelect->EvalInstance(inst) == 0){
01132 skip = kTRUE;
01133 ++entry;
01134 }
01135 }
01136 if (!loaded) {
01137
01138
01139 for (ui=0;ui<fNcols;ui++) {
01140 ((TTreeFormula*)fFormulas->At(ui))->EvalInstance(0);
01141 }
01142 loaded = kTRUE;
01143 } else if (inst == 0) {
01144 loaded = kTRUE;
01145 }
01146 }
01147 if(!skip){
01148 fCurrentEntries[fTree->GetScanField()-entriesToDisplay] = entryNumber;
01149 --entriesToDisplay;
01150 ++entry;
01151 }
01152 }
01153 if(fPolyList) UpdateView();
01154 }
01155
01156
01157
01158 void TSpider::SetLineStyle(Style_t sty)
01159 {
01160
01161
01162 UInt_t ui=0;
01163
01164 TAttLine::SetLineStyle(sty);
01165 for(ui=0; ui<fNx*fNy;++ui){
01166 if(fSegmentDisplay){
01167 TList *li = (TList*)fPolyList->At(ui);
01168 for(UInt_t var=0;var<fNcols;++var) ((TArc*)li->At(var))->SetLineStyle(sty);
01169 } else ((TPolyLine*)fPolyList->At(ui))->SetLineStyle(sty);
01170 }
01171 }
01172
01173
01174
01175 void TSpider::SetLineColor(Color_t col)
01176 {
01177
01178
01179 UInt_t ui=0;
01180
01181 TAttLine::SetLineColor(col);
01182 for(ui=0; ui<fNx*fNy;++ui){
01183 if(fSegmentDisplay){
01184 TList *li = (TList*)fPolyList->At(ui);
01185 for(UInt_t var=0;var<fNcols;++var) ((TArc*)li->At(var))->SetLineColor(col);
01186 } else ((TPolyLine*)fPolyList->At(ui))->SetLineColor(col);
01187 }
01188 }
01189
01190
01191
01192 void TSpider::SetLineWidth(Width_t wid)
01193 {
01194
01195
01196 UInt_t ui=0;
01197
01198 TAttLine::SetLineWidth(wid);
01199 for(ui=0; ui<fNx*fNy;++ui){
01200 if(fSegmentDisplay){
01201 TList *li = (TList*)fPolyList->At(ui);
01202 for(UInt_t var=0;var<fNcols;++var) ((TArc*)li->At(var))->SetLineWidth(wid);
01203 } else ((TPolyLine*)fPolyList->At(ui))->SetLineWidth(wid);
01204 }
01205 }
01206
01207
01208
01209 void TSpider::SetFillColor(Color_t col)
01210 {
01211
01212
01213 UInt_t ui=0;
01214
01215 TAttFill::SetFillColor(col);
01216 for(ui=0; ui<fNx*fNy;++ui){
01217 if(fSegmentDisplay){
01218 TList *li = (TList*)fPolyList->At(ui);
01219 for(UInt_t var=0;var<fNcols;++var) ((TArc*)li->At(var))->SetFillColor(col);
01220 } else ((TPolyLine*)fPolyList->At(ui))->SetFillColor(col);
01221 }
01222 }
01223
01224
01225
01226 void TSpider::SetFillStyle(Style_t sty)
01227 {
01228
01229
01230 UInt_t ui=0;
01231
01232 TAttFill::SetFillStyle(sty);
01233 for(ui=0; ui<fNx*fNy;++ui){
01234 if(fSegmentDisplay){
01235 TList *li = (TList*)fPolyList->At(ui);
01236 for(UInt_t var=0;var<fNcols;++var) ((TArc*)li->At(var))->SetFillStyle(sty);
01237 } else ((TPolyLine*)fPolyList->At(ui))->SetFillStyle(sty);
01238 }
01239 }
01240
01241
01242
01243 void TSpider::SetNdivRadial(Int_t ndiv)
01244 {
01245
01246
01247 if(fPolargram->GetNdivRadial() == ndiv) return;
01248 fPolargram->SetNdivRadial(ndiv);
01249 }
01250
01251
01252
01253 void TSpider::SetNx(UInt_t nx)
01254 {
01255
01256
01257 if(fNx == nx || nx <= 0) return;
01258 fEntry = fCurrentEntries[0];
01259
01260 UInt_t ui=0;
01261 Color_t lc;
01262 Style_t lt;
01263 Width_t lw;
01264 Color_t fc;
01265 Style_t fs;
01266 if(fAverageSlices){
01267 lc = fAverageSlices[0]->GetLineColor();
01268 lt = fAverageSlices[0]->GetLineStyle();
01269 lw = fAverageSlices[0]->GetLineWidth();
01270 fc = fAverageSlices[0]->GetFillColor();
01271 fs = fAverageSlices[0]->GetFillStyle();
01272 } else {
01273 lc = fAveragePoly->GetLineColor();
01274 lt = fAveragePoly->GetLineStyle();
01275 lw = fAveragePoly->GetLineWidth();
01276 fc = fAveragePoly->GetFillColor();
01277 fs = fAveragePoly->GetFillStyle();
01278 }
01279
01280 if(fSegmentDisplay){
01281 for(ui=0; ui<fNx*fNy;++ui) ((TList*)fPolyList->At(ui))->Delete();
01282 }
01283 fPolyList->Delete();
01284 delete fPolyList;
01285 fPolyList = NULL;
01286 delete [] fCurrentEntries;
01287 fCurrentEntries = NULL;
01288
01289 fNx = nx;
01290
01291 fTree->SetScanField(fNx*fNy);
01292 SetCurrentEntries();
01293 fCanvas->Clear();
01294 fCanvas->Divide(fNx,fNy);
01295
01296 for(ui=0; ui < fNx*fNy;++ui){
01297 fCanvas->cd(ui+1);
01298 fPolargram->Draw("pn");
01299 fTree->LoadTree(fCurrentEntries[ui]);
01300 if(fSegmentDisplay){
01301 if(fDisplayAverage) DrawSlicesAverage("");
01302 DrawSlices("");
01303 } else {
01304 if(fDisplayAverage) DrawPolyAverage("");
01305 DrawPoly("");
01306 }
01307 AppendPad();
01308 }
01309
01310 if(fAverageSlices){
01311 for(ui = 0;ui<fNcols;++ui){
01312 fAverageSlices[ui]->SetLineColor(lc);
01313 fAverageSlices[ui]->SetLineStyle(lt);
01314 fAverageSlices[ui]->SetLineWidth(lw);
01315 fAverageSlices[ui]->SetFillColor(fc);
01316 fAverageSlices[ui]->SetFillStyle(fs);
01317 }
01318 } else {
01319 fAveragePoly->SetLineColor(lc);
01320 fAveragePoly->SetLineStyle(lt);
01321 fAveragePoly->SetLineWidth(lw);
01322 fAveragePoly->SetFillColor(fc);
01323 fAveragePoly->SetFillStyle(fs);
01324 }
01325 }
01326
01327
01328
01329 void TSpider::SetNy(UInt_t ny)
01330 {
01331
01332
01333 if(fNy == ny || ny <= 0) return;
01334 fEntry = fCurrentEntries[0];
01335
01336 UInt_t ui=0;
01337 Color_t lc;
01338 Style_t lt;
01339 Width_t lw;
01340 Color_t fc;
01341 Style_t fs;
01342 if(fAverageSlices){
01343 lc = fAverageSlices[0]->GetLineColor();
01344 lt = fAverageSlices[0]->GetLineStyle();
01345 lw = fAverageSlices[0]->GetLineWidth();
01346 fc = fAverageSlices[0]->GetFillColor();
01347 fs = fAverageSlices[0]->GetFillStyle();
01348 } else {
01349 lc = fAveragePoly->GetLineColor();
01350 lt = fAveragePoly->GetLineStyle();
01351 lw = fAveragePoly->GetLineWidth();
01352 fc = fAveragePoly->GetFillColor();
01353 fs = fAveragePoly->GetFillStyle();
01354 }
01355
01356 if(fSegmentDisplay){
01357 for(ui=0; ui<fNx*fNy;++ui) ((TList*)fPolyList->At(ui))->Delete();
01358 }
01359 fPolyList->Delete();
01360 delete fPolyList;
01361 fPolyList = NULL;
01362 delete [] fCurrentEntries;
01363 fCurrentEntries = NULL;
01364
01365 fNy = ny;
01366
01367 fTree->SetScanField(fNx*fNy);
01368 SetCurrentEntries();
01369 fCanvas->Clear();
01370 fCanvas->Divide(fNx,fNy);
01371
01372 for(ui=0; ui < fNx*fNy;++ui){
01373 fCanvas->cd(ui+1);
01374 fPolargram->Draw("pn");
01375 fTree->LoadTree(fCurrentEntries[ui]);
01376 if(fSegmentDisplay){
01377 if(fDisplayAverage) DrawSlicesAverage("");
01378 DrawSlices("");
01379 } else {
01380 if(fDisplayAverage) DrawPolyAverage("");
01381 DrawPoly("");
01382 }
01383 AppendPad();
01384 }
01385
01386 if(fAverageSlices){
01387 for(ui = 0;ui<fNcols;++ui){
01388 fAverageSlices[ui]->SetLineColor(lc);
01389 fAverageSlices[ui]->SetLineStyle(lt);
01390 fAverageSlices[ui]->SetLineWidth(lw);
01391 fAverageSlices[ui]->SetFillColor(fc);
01392 fAverageSlices[ui]->SetFillStyle(fs);
01393 }
01394 } else {
01395 fAveragePoly->SetLineColor(lc);
01396 fAveragePoly->SetLineStyle(lt);
01397 fAveragePoly->SetLineWidth(lw);
01398 fAveragePoly->SetFillColor(fc);
01399 fAveragePoly->SetFillStyle(fs);
01400 }
01401 }
01402
01403
01404
01405 void TSpider::SetSegmentDisplay(Bool_t seg)
01406 {
01407
01408
01409 if(seg == fSegmentDisplay) return;
01410
01411 UInt_t ui=0;
01412
01413 if(fSegmentDisplay){
01414 for(ui=0;ui<fNx*fNy;++ui){
01415 ((TList*)fPolyList->At(ui))->Delete();
01416 }
01417 }
01418 fPolyList->Delete();
01419
01420 Color_t lc;
01421 Style_t lt;
01422 Width_t lw;
01423 Color_t fc;
01424 Style_t fs;
01425 if(fAverageSlices){
01426 lc = fAverageSlices[0]->GetLineColor();
01427 lt = fAverageSlices[0]->GetLineStyle();
01428 lw = fAverageSlices[0]->GetLineWidth();
01429 fc = fAverageSlices[0]->GetFillColor();
01430 fs = fAverageSlices[0]->GetFillStyle();
01431 } else {
01432 lc = fAveragePoly->GetLineColor();
01433 lt = fAveragePoly->GetLineStyle();
01434 lw = fAveragePoly->GetLineWidth();
01435 fc = fAveragePoly->GetFillColor();
01436 fs = fAveragePoly->GetFillStyle();
01437 }
01438 delete fPolyList;
01439 fPolyList = NULL;
01440 if(fAverageSlices){
01441 for(ui=0;ui<fNcols;++ui) delete fAverageSlices[ui];
01442 }
01443 delete [] fAverageSlices;
01444 fAverageSlices = NULL;
01445 delete fAveragePoly;
01446 fAveragePoly = NULL;
01447
01448 for(ui=0;ui<fNx*fNy;++ui){
01449 fCanvas->cd(ui+1);
01450 gPad->Clear();
01451 }
01452
01453 fSegmentDisplay = seg;
01454
01455 for(ui=0; ui < fNx*fNy;++ui){
01456 fCanvas->cd(ui+1);
01457 fPolargram->Draw("pn");
01458 fTree->LoadTree(fCurrentEntries[ui]);
01459 if(fSegmentDisplay){
01460 if(fDisplayAverage) DrawSlicesAverage("");
01461 DrawSlices("");
01462 } else {
01463 if(fDisplayAverage) DrawPolyAverage("");
01464 DrawPoly("");
01465 }
01466 AppendPad();
01467 }
01468
01469 if(fAverageSlices){
01470 for(ui=0;ui<fNcols;++ui){
01471 fAverageSlices[ui]->SetLineColor(lc);
01472 fAverageSlices[ui]->SetLineStyle(lt);
01473 fAverageSlices[ui]->SetLineWidth(lw);
01474 fAverageSlices[ui]->SetFillColor(fc);
01475 fAverageSlices[ui]->SetFillStyle(fs);
01476 }
01477 } else {
01478 fAveragePoly->SetLineColor(lc);
01479 fAveragePoly->SetLineStyle(lt);
01480 fAveragePoly->SetLineWidth(lw);
01481 fAveragePoly->SetFillColor(fc);
01482 fAveragePoly->SetFillStyle(fs);
01483 }
01484
01485 fCanvas->Modified();
01486 fCanvas->Update();
01487 }
01488
01489
01490
01491
01492
01493 void TSpider::SetSelectionExpression(const char* selection)
01494 {
01495
01496
01497 if (selection && strlen(selection)) {
01498 fSelect = new TTreeFormula("Selection",selection,fTree);
01499
01500
01501 fFormulas->Add(fSelect);
01502 }
01503 }
01504
01505
01506
01507 void TSpider::SetVariablesExpression(const char* varexp)
01508 {
01509
01510
01511 Int_t nch;
01512 fNcols=8;
01513
01514 if (!varexp) return;
01515 TObjArray *leaves = fTree->GetListOfLeaves();
01516 UInt_t nleaves = leaves->GetEntriesFast();
01517 if (nleaves < fNcols) fNcols = nleaves;
01518 nch = strlen(varexp);
01519
01520
01521 Int_t allvar = 0;
01522 std::vector<TString> cnames;
01523 if (!strcmp(varexp, "*")) { fNcols = nleaves; allvar = 1; }
01524 if (nch == 0 || allvar) {
01525 UInt_t ncs = fNcols;
01526 fNcols = 0;
01527 for (UInt_t ui=0;ui<ncs;++ui) {
01528 TLeaf *lf = (TLeaf*)leaves->At(ui);
01529 if (lf->GetBranch()->GetListOfBranches()->GetEntries() > 0) continue;
01530 cnames.push_back(lf->GetName());
01531 fNcols++;
01532 }
01533
01534 } else {
01535 fNcols = fSelector->SplitNames(varexp,cnames);
01536 }
01537
01538
01539 for (UInt_t ui=0;ui<fNcols;ui++) {
01540 fFormulas->Add(new TTreeFormula("Var1",cnames[ui].Data(),fTree));
01541 }
01542 }
01543
01544
01545
01546 void TSpider::SyncFormulas()
01547 {
01548
01549
01550 Int_t i;
01551 if (fFormulas->LastIndex()>=0) {
01552 if (fSelect) {
01553 if (fSelect->GetManager()->GetMultiplicity() > 0 ) {
01554 if(!fManager) fManager = new TTreeFormulaManager;
01555 for(i=0;i<=fFormulas->LastIndex();i++) {
01556 fManager->Add((TTreeFormula*)fFormulas->At(i));
01557 }
01558 fManager->Sync();
01559 }
01560 }
01561 for(i=0;i<=fFormulas->LastIndex();i++) {
01562 TTreeFormula *form = ((TTreeFormula*)fFormulas->At(i));
01563 switch( form->GetManager()->GetMultiplicity() ) {
01564 case 1:
01565 case 2:
01566 case -1:
01567 fForceDim = kTRUE;
01568 break;
01569 case 0:
01570 break;
01571 }
01572
01573 }
01574 }
01575 }
01576
01577
01578
01579 void TSpider::UpdateView()
01580 {
01581
01582
01583 Double_t slice = 2*TMath::Pi()/fNcols;
01584
01585 Double_t x,y,r;
01586
01587 for(UInt_t pad=1;pad <= fNx*fNy;++pad){
01588 fTree->LoadTree(fCurrentEntries[pad-1]);
01589 for(UInt_t i=0;i<fNcols;++i){
01590 r = (((TTreeFormula*)fFormulas->At(i))->EvalInstance()-fMin[i])/(fMax[i]-fMin[i]);
01591 x=r*TMath::Cos(i*slice);
01592 y=r*TMath::Sin(i*slice);
01593 if(!fSegmentDisplay) ((TPolyLine*)fPolyList->At(pad-1))->SetPoint(i,x,y);
01594 else {
01595 ((TArc*)((TList*)fPolyList->At(pad-1))->At(i))->SetR1(r);
01596 ((TArc*)((TList*)fPolyList->At(pad-1))->At(i))->SetR2(r);
01597 }
01598 }
01599 x=(((TTreeFormula*)fFormulas->At(0))->EvalInstance()-fMin[0])/(fMax[0]-fMin[0]);
01600 y=0;
01601 if(!fSegmentDisplay) ((TPolyLine*)fPolyList->At(pad-1))->SetPoint(fNcols,x,y);
01602 }
01603 }