//*-- Author :    Damir Buskulic   22/11/00

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// VNtuplePlayer                                                        //
//                                                                      //
// A VNtuple is an ntuple containing slow monitoring data               //
// The player will allow one to draw some plots related to this         //
// VNtuple.                                                             //
// The vntuple player is loaded only when needed by the system, it is   //
// not linked at compile time with the program                          //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "VNtuplePlayer.h"
#include "TH1.h"
#include "TString.h"
#include "TPad.h"
#include "TROOT.h"
#include "TTree.h"
#include "TMath.h"
#include "TGraph.h"
#include "VSPlot.h"

ClassImp(VNtuplePlayer)

//______________________________________________________________________________
  VNtuplePlayer::VNtuplePlayer()
{
//*-*-*-*-*-*-*-*-*-*-*Default MeatDB player constructor*-*-*-*-*-*-*-*-*-*
//*-*                  =================================
   mNtuple         = 0;
}

//______________________________________________________________________________
 Int_t VNtuplePlayer::DrawGraph(const char *varexp0, const char *selection, Option_t *option,Int_t nentries, Int_t firstentry)
{
//*-*-*-*-*-*-*-*-*-*-*Draw expression varexp for specified entries-*-*-*-*-*
//*-*                  ===========================================
//
// This method differs from the "Draw" method in that it draws a graph of the
// selected variables, not a histogram. The options and comments are
// nevertheless the same and one should refer to TTree::Draw()
// This method should not be used for a graph that has more than approx 10^6
// points, because it fills quite rapidly the memory.
// The options available are the same as the ones in TGraph::Draw, except
// that a "T" option has been added, which sets the X axis to time mode
// display. This is only used in conjunction with the "A" mode.

   Double_t xmin,xmax,ymin,ymax,oldymin, oldymax;
   Double_t* vx, *vy, *vz;
   Int_t np,nch,i;
   TH1F* hr;
   Int_t nvar;
 
   TString opt = option;
   opt.ToUpper();
   if (opt.IsNull()) opt = "AP";

//*-*- Create a default canvas if none exists
   if (!gPad && !opt.Contains("goff")) {
   	if (!gROOT->GetMakeDefCanvas()) return -1;
   	(gROOT->GetMakeDefCanvas())();
   }

// Selects the entries   
   Int_t oldestimate = mNtuple->GetEstimate();
   if (mNtuple->GetEntries() < 1000000) mNtuple->SetEstimate(mNtuple->GetEntries());
   else mNtuple->SetEstimate(1000000);
   mNtuple->Draw(varexp0, selection, "samegoff", nentries, firstentry);

// Calculates the number of variables in "selection", filled by "Draw"
   nch = strlen(varexp0);
   if (nch == 0) nvar = 0;
   else {
      nvar  = 1;
      for (i=0;i<nch;i++)  if (varexp0[i] == ':') nvar++;
   }
   
   if (nvar<2) {
      Warning("DrawGraph","Need at least two variables to make a graph");
      mNtuple->SetEstimate(oldestimate);
      return -1;
   }
// Tests if the selected rows really exist
   if (!(mNtuple->GetVar1()) && nvar>0) {
      Warning("DrawGraph","Variable doesn't exist");
      mNtuple->SetEstimate(oldestimate);
      return -1;
   } else if (!(mNtuple->GetVar2()) && nvar>1) {
      Warning("DrawGraph","Variable doesn't exist");
      mNtuple->SetEstimate(oldestimate);
      return -1;
   } else if (!(mNtuple->GetVar3()) && nvar>2) {
      Warning("DrawGraph","Variable doesn't exist");
      mNtuple->SetEstimate(oldestimate);
      return -1;
   } 
   vx = mNtuple->GetV1();
   vy = mNtuple->GetV2();
   if (nvar>2) vz = mNtuple->GetV3();
      
   np = mNtuple->GetSelectedRows();

   hr = (TH1F*)(gPad->GetListOfPrimitives()->FindObject("hframe"));

// Gets min/max
   if (np) {
      xmin = vx[TMath::LocMin(np,vx)];
      xmax = vx[TMath::LocMax(np,vx)];
      ymin = vy[TMath::LocMin(np,vy)];
      ymax = vy[TMath::LocMax(np,vy)];
      ymin = ymin-(ymax-ymin)*0.1;
      ymax = ymax+(ymax-ymin)*0.1;
   } else {
      if (hr) {
         xmin = hr->GetXaxis()->GetXmin();
         xmax = hr->GetXaxis()->GetXmax();
         ymin = hr->GetMinimum();
         ymax = hr->GetMaximum();
      } else {
         xmin = 0;
         xmax = 1;
         ymin = -1;
         ymax = 1;
      }
   }
   
// Draw a frame to define the range if option contains "A"
   if (opt.Contains("A")) {
      hr = gPad->DrawFrame(xmin,ymin,xmax,ymax);
      hr->SetBins(1000,xmin,xmax);
      while (opt.Index("A") != kNPOS) opt.Remove(opt.Index("A"),1);
   } else {
      if (hr) {
         oldymin = hr->GetMinimum();
         oldymax = hr->GetMaximum();
         if (oldymin > ymin) hr->SetMinimum(ymin);
         if (oldymax < ymax) hr->SetMaximum(ymax);
      }
   }
   if (opt.Contains("T") && hr) {
      hr->GetXaxis()->SetTimeDisplay(1);
      while (opt.Index("T") != kNPOS) opt.Remove(opt.Index("T"),1);
   }

// Draws the graph
   if (np) {     // There is something to draw !
      TGraph *gr = new TGraph(np,vx,vy);
      gr->SetBit(kCanDelete);
      gr->Draw(opt.Data());
   }
   mNtuple->SetEstimate(oldestimate);
   return 0;
}

//______________________________________________________________________________
 Int_t VNtuplePlayer::DrawSeries(const char *varexp0, const char *selection, Option_t *option,Int_t nentries, Int_t firstentry)
{
//*-*-*-*-*-*-*-*-*-*-*Draw expression varexp for specified entries-*-*-*-*-*
//*-*                  ===========================================
//
// This method differs from the "Draw" method in that it draws a  time series
// graph of the selected variable, not a histogram.
// The options and comments are nevertheless the same and one should refer
// to TTree::Draw()
// This method should not be used for a series that has more than approx 10^6
// points, because it fills quite rapidly the memory.
// The options available are the same as the ones in VSPlot::Draw.

   Double_t xmin,xmax;
   Double_t* vx, *vy;
   Int_t np,nch,i;
   Int_t nvar;
 
   TString opt = option;
   opt.ToUpper();

//*-*- Create a default canvas if none exists
   if (!gPad && !opt.Contains("goff")) {
   	if (!gROOT->GetMakeDefCanvas()) return -1;
   	(gROOT->GetMakeDefCanvas())();
   }

   // Calculates the number of variables in "selection", filled by "Draw"
   nch = strlen(varexp0);
   if (nch == 0) nvar = 0;
   else {
      nvar  = 1;
      for (i=0;i<nch;i++)  if (varexp0[i] == ':') nvar++;
   }
   
   if (nvar>1 || nvar==0) {
      Warning("DrawSeries","A time series needs one and only one variable");
      return -1;
   }
   
   char* varexp = new char[nch+4];
   strcpy(varexp,"t:");
   strcat(varexp,varexp0);

// Selects the entries   
   Int_t oldestimate = mNtuple->GetEstimate();
   if (mNtuple->GetEntries() < 1000000) mNtuple->SetEstimate(mNtuple->GetEntries());
   else mNtuple->SetEstimate(1000000);
   mNtuple->Draw(varexp, selection, "samegoff", nentries, firstentry);

   delete varexp;
// Tests if the selected rows really exist
   if (!(mNtuple->GetVar1())) {
      Warning("DrawSeries","Variable time is not present in this VNtuple");
      mNtuple->SetEstimate(oldestimate);
      return -1;
   } else if (!(mNtuple->GetVar2())) {
      Warning("DrawSeries","Variable doesn't exist");
      mNtuple->SetEstimate(oldestimate);
      return -1;
   }
   vx = mNtuple->GetV1();
   vy = mNtuple->GetV2();
   np = mNtuple->GetSelectedRows();

// Gets min/max
   if (np) {
      xmin = vx[TMath::LocMin(np,vx)];
      xmax = vx[TMath::LocMax(np,vx)];
   }
   
// Draws the series
   if (np) {     // There is something to draw !
      Double_t step = mNtuple->GetStep();
      int nsteps = (int)((xmax-xmin)/step)+1;
      char* titlevs = new char[strlen(varexp0)+1];
      strcpy(titlevs,varexp0);
      VSPlot* vsp = new VSPlot(titlevs,titlevs,nsteps,xmin-step/2,xmax+step/2,gVM);
      vsp->SetGPSStart(mNtuple->GetGPSStart().GetSec(),mNtuple->GetGPSStart().GetNsec());
      vsp->SetStep(step);
      vsp->SetLocalTime(mNtuple->GetLocalTime());
      vsp->SetLeapS(mNtuple->GetLeapS());
      for (i=0;i<np;i++) {
         int istep = (int)((vx[i] + step/2 - xmin)/step);
         vsp->SetBinContent(istep+1,vy[i]);
      }
      vsp->Draw(option);
      delete[] titlevs;
   }
   mNtuple->SetEstimate(oldestimate);
   return 0;
}


- ROOT page - VEGA page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to , or contact with any questions or problems regarding ROOT or VEGA.