calo_detail.C

Go to the documentation of this file.
00001 // @(#)root/eve:$Id:  26568 2008-12-01 20:55:50Z matevz $
00002 // Author: Alja Mrak-Tadel
00003 
00004 // Calorimeter detailed view by using TEveCaloDataVec as data-source.
00005 // Demonstrantes how to plot calorimiter data with irregular bins.
00006 
00007 void calo_detail()
00008 {
00009    gROOT->LoadMacro("calorimeters.C");
00010    TEveManager::Create();
00011 
00012    // data
00013    TEveCaloDataVec* data = MakeVecData(20);
00014    data->IncDenyDestroy(); // don't delete if zero parent
00015 
00016    // frames
00017    TEveWindowSlot* slot =
00018       TEveWindow::CreateWindowInTab(gEve->GetBrowser()->GetTabRight());
00019    TEveWindowPack* packH = slot->MakePack();
00020    packH->SetElementName("Projections");
00021    packH->SetHorizontal();
00022    packH->SetShowTitleBar(kFALSE);
00023 
00024    slot = packH->NewSlot();
00025    TEveWindowPack* pack0 = slot->MakePack();
00026    pack0->SetShowTitleBar(kFALSE);
00027    TEveWindowSlot*  slotLeftTop   = pack0->NewSlot();
00028    TEveWindowSlot* slotLeftBottom = pack0->NewSlot();
00029 
00030    slot = packH->NewSlot();
00031    TEveWindowPack* pack1 = slot->MakePack();
00032    pack1->SetShowTitleBar(kFALSE);
00033    TEveWindowSlot* slotRightTop    = pack1->NewSlot();
00034    TEveWindowSlot* slotRightBottom = pack1->NewSlot();
00035 
00036    // viewers ans scenes in second tab
00037    Float_t maxH = 300;
00038    TEveCalo3D* calo3d = MakeCalo3D(data, slotRightTop);
00039    calo3d->SetMaxTowerH(maxH);
00040 
00041    TEveCalo2D* calo2d;
00042    calo2d = MakeCalo2D(calo3d, slotLeftTop, TEveProjection::kPT_RPhi);
00043    calo2d->SetMaxTowerH(maxH);
00044    calo2d = MakeCalo2D(calo3d, slotLeftBottom, TEveProjection::kPT_RhoZ);
00045    calo2d->SetMaxTowerH(maxH);
00046 
00047    TEveCaloLego* lego = MakeCaloLego(data, slotRightBottom);
00048    lego->SetAutoRebin(kFALSE);
00049    lego->Set2DMode(TEveCaloLego::kValSizeOutline);
00050 
00051    gEve->AddElement(lego);
00052    gEve->GetDefaultGLViewer()->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
00053 
00054    gEve->GetBrowser()->GetTabRight()->SetTab(1);
00055    gEve->FullRedraw3D(kTRUE);
00056 
00057 }
00058 
00059 //______________________________________________________________________________
00060 TEveCaloDataVec* MakeVecData(Int_t ncells=0)
00061 {
00062    // Example how to fill data when bins can be iregular.
00063    // If ncells = 0 (default) whole histogram is taken,
00064    // otherwise just ncells cells around the maximum.
00065 
00066    TFile::SetCacheFileDir(".");
00067    TFile* hf = TFile::Open(histFile, "CACHEREAD");
00068    TH2F* h1 = (TH2F*)hf->Get("ecalLego");
00069    TH2F* h2 = (TH2F*)hf->Get("hcalLego");
00070 
00071    TEveCaloDataVec* data = new TEveCaloDataVec(2);
00072    data->RefSliceInfo(0).Setup("ECAL", 0.3, kRed);
00073    data->RefSliceInfo(1).Setup("HCAL", 0.1, kBlue);
00074 
00075    TAxis *ax =  h1->GetXaxis();
00076    TAxis *ay =  h1->GetYaxis();
00077 
00078    Int_t xm = 1, xM = ax->GetNbins();
00079    Int_t ym = 1, yM = ay->GetNbins();
00080    if (ncells != 0)
00081    {
00082       Int_t cx, cy, cz;
00083       h1->GetMaximumBin(cx, cy, cz);
00084       xm = TMath::Max(xm, cx-ncells);
00085       xM = TMath::Min(xM, cx+ncells);
00086       ym = TMath::Max(ym, cy-ncells);
00087       yM = TMath::Min(yM, cy+ncells);
00088    }
00089 
00090    // Take every second cell and set a random size.
00091    for(Int_t i=xm; i<=xM; i+=2)
00092    {
00093       for(Int_t j=ym; j<=yM; j+=2)
00094       {
00095          if ( (i+j) % 3)
00096          {
00097             data->AddTower(ax->GetBinLowEdge(i), ax->GetBinUpEdge(i),
00098                            ay->GetBinLowEdge(j), ay->GetBinUpEdge(j));
00099             data->FillSlice(0, h1->GetBinContent(i, j));
00100             data->FillSlice(1, h2->GetBinContent(i, j));
00101          }
00102          else
00103          {
00104             data->AddTower(ax->GetBinLowEdge(i),
00105                            2 * ax->GetBinWidth(i) + ax->GetBinLowEdge(i),
00106                            ay->GetBinLowEdge(j),
00107                            2 * ay->GetBinWidth(j) + ay->GetBinLowEdge(j));
00108             data->FillSlice(0, h2->GetBinContent(i, j));
00109             data->FillSlice(1, h2->GetBinContent(i, j));
00110          }
00111       }
00112    }
00113 
00114    data->SetEtaBins(ax);
00115    data->SetPhiBins(ay);
00116    data->DataChanged();
00117    return data;
00118 }

Generated on Tue Jul 5 15:43:50 2011 for ROOT_528-00b_version by  doxygen 1.5.1