//*-- Modified :  v0r51 22/11/00  by  Damir Buskulic
//*-- Modified :  v0r49 21/06/00  by  Damir Buskulic
//*-- Author :    Damir Buskulic   23/09/99

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// VNtuple                                                              //
//                                                                      //
// A standard simple ntuple with some drawing options suitable for      //
// GW analysis                                                          //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "VNtuple.h"

ClassImp(VNtuple)

//______________________________________________________________________________
VNtuple::VNtuple(): TNtuple()
{
//*-*-*-*-*-*Default constructor for Ntuple*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*        ==============================
   mStep = 0;
   mGPSStart.SetSec(0);
   mGPSStart.SetNsec(0);
   mLeapS = 0;
   mLocalTime = 0;
   mPlayer = 0;
}

//______________________________________________________________________________
VNtuple::VNtuple(const char *name, const char *title, const char *varlist, Int_t bufsize)
       :TNtuple(name,title,varlist,bufsize)
{
//*-*-*-*-*-*-*-*-*-*-*-*-*Create a VNtuple*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
//*-*                      ================
//       The parameter varlist describes the list of the ntuple variables
//       separated by a colon:
//         example:  "x:y:z:energy"
//       For each variable in the list a separate branch is created.
//
//       Use TTree to create branches with variables of different data types.
//*-*

   mStep = 0;
   mGPSStart.SetSec(0);
   mGPSStart.SetNsec(0);
   mLeapS = 0;
   mLocalTime = 0;
   mPlayer = 0;

// Check that the first variable is named "t"
   if (strcmp(GetListOfBranches()->At(0)->GetName(),"t")) {
      Warning("VNTuple","First variable must be named "t"");
      return;
   }
}

//______________________________________________________________________________
VNtuple::VNtuple(const char *name,const char *title, const char *varlist, const char* asciifilename, Int_t bufsize)
       :TNtuple(name,title,varlist,bufsize)
{
//*-*-*-*-*-*-*-*-*-*-* Create a VNtuple from a text file -*-*-*-*-*-*-*-*
//*-*                   =================================
//
//       Use a formated text file as input to a VNTuple. The text file
//       should have the format :
//
// Time1 valueA1 valueB1 valueC1 ...
// Time2 valueA2 valueB2 valueC2 ...
// etc...
//       
//       The first value is the time at which the subsequent values were taken
//       The separator may be one or more spaces or one or more tabs
//       The parameter varlist describes the list of the ntuple variables
//       separated by a colon:
//         example:  "t:x:y:z:energy" THE FIRST PARAMETER MUST BE "t"
//       The order of the parameters corresponds to the order of the
//       columns in the text file.
//       For each variable in the list a separate branch is created.
//
//       Use TTree to create branches with variables of different data types.
//*-*

   double time, timin;
   float value[300];
   FILE*  asciifile;
   int i, numvar, curok, lreadline;
   
// Find the number of columns from the list of variables
   numvar = GetNvar();
   if (numvar<2) {
      Warning("VNTuple","At least time + one variable must be selected, nothing read");
      return;
   }

// Check that the first variable is named "t"
   if (strcmp(GetListOfBranches()->At(0)->GetName(),"t")) {
      Warning("VNTuple","First variable must be named "t", nothing read");
      return;
   }
   
// The step is determined from the ascii file
   Double_t loweststep = 100000000000.;
   Double_t oldstarttime = 0.;
   
// opens the ascii file and reads data from it
   asciifile = fopen(asciifilename,"r");
   if (!asciifile) return;
   
// reads the first line to get the number of columns
   char* readline = new char[4000];      
   char* curread;
   curread = readline;
   
   int okreadfile;
   for (i=0;i<300;i++) value[i]=0;

// reads all the columns of the first line
   okreadfile = 1;
   if (fgets(readline,4000,asciifile)) {
      sscanf(curread,"%lf",&time);
//   step through the next values
      curok =1;
      lreadline = strlen(readline);
      while (curok) {
//      skip the value
         while((*curread==' ' || *curread=='t') && *curread!=0) curread++;
         while(*curread!=' ' && *curread!='t' && *curread!=0) curread++;
         while((*curread==' ' || *curread=='t') && *curread!=0) curread++;
//      read the next one if not the end of line
         if (curread>=readline+strlen(readline)) curok=0;
         else {
            sscanf(curread,"%f",&value[okreadfile]);
            okreadfile++;
         }
      }
      okreadfile--;
   } else {
      okreadfile = 0;
   }
// The first value is time, with respect to the first read time
   timin=time;
   value[0] = 0;
   
   while (okreadfile>1) {
      Fill(value);  // Fill the ntuple with the values

//   See if the time step between values is the lowest one. There must be at least
//   some order in the values to make it work.
      double currentstep = time - oldstarttime;
      if (currentstep < loweststep) loweststep = currentstep;
      oldstarttime = time;

      okreadfile = 1;
      curread = readline;
      if (fgets(readline,4000,asciifile)) {
         sscanf(curread,"%lf",&time);
         value[0] = time - timin;  
//      step through the next values
         curok =1;
         lreadline = strlen(readline);
         while (curok) {
//         skip the value
            while((*curread==' ' || *curread=='t') && *curread!=0) curread++;
            while(*curread!=' ' && *curread!='t' && *curread!=0) curread++;
            while((*curread==' ' || *curread=='t') && *curread!=0) curread++;
//         read the next one if not the end of line
            if (curread>=readline+strlen(readline)) curok=0;
            else {
               sscanf(curread,"%f",&value[okreadfile]);
               okreadfile++;
            }
         }
         okreadfile--;
      } else {
         okreadfile = 0;
      }
   }
   
// Sets the start time and step
   mGPSStart.SetTimeD(timin);
   mStep = loweststep;
   mPlayer = 0;
   
   delete [] readline;
}

//______________________________________________________________________________
 Int_t VNtuple::DrawGraph(TCut varexp, TCut selection, Option_t *option, Int_t nentries, Int_t firstentry)
{
//*-*-*-*-*-*-*-*-*-*-*Draw expression varexp for specified entries-*-*-*-*-*
//*-*                  ===========================================
//
//      This function accepts TCut objects as arguments.
//      Useful to use the string operator +
//         example:
//            ntuple.Draw("x",cut1+cut2+cut3);
//

   return VNtuple::DrawGraph(varexp.GetTitle(), selection.GetTitle(), option, nentries, firstentry);
}

//______________________________________________________________________________
 Int_t VNtuple::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.

   GetPlayer();
   if (mPlayer) return mPlayer->DrawGraph(varexp0, selection, option, nentries, firstentry);
   else return -1;
}

//______________________________________________________________________________
 Int_t VNtuple::DrawSeries(TCut varexp, TCut selection, Option_t *option, Int_t nentries, Int_t firstentry)
{
//*-*-*-*-*-*-*-*-*-*-*Draw expression varexp for specified entries-*-*-*-*-*
//*-*                  ===========================================
//
//      This function accepts TCut objects as arguments.
//      Useful to use the string operator +
//         example:
//            ntuple.DrawSeries("x",cut1+cut2+cut3);
//

   return VNtuple::DrawSeries(varexp.GetTitle(), selection.GetTitle(), option, nentries, firstentry);
}

//______________________________________________________________________________
 Int_t VNtuple::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.

   GetPlayer();
   if (mPlayer) return mPlayer->DrawSeries(varexp0, selection, option, nentries, firstentry);
   else return -1;
}

//______________________________________________________________________________
 VVirtualNtuplePlayer* VNtuple::GetPlayer()
{
   // Load the VNtuplePlayer (if not already done)
   // Pointer to player is mPlayer

   if (mPlayer) return mPlayer;
   mPlayer = VVirtualNtuplePlayer::NtuplePlayer(this);
   return mPlayer;
}
// 
// //______________________________________________________________________________
// FrVect* VNtuple::GetVect(const char *varexp0, const char *selection, Int_t nentries, Int_t firstentry)
// {
// //*-*-*-*-*-*-*-*-*-*-*Extracts expression varexp0 for specified entries-*-*-*
// //*-*                  =================================================
// //
// // Builds a new FrVect and fills it with SMS data from the VNtuple
// // This method should not be used for a series that has more than approx 10^6
// // points, because it fills quite rapidly the memory.
// 
//    Double_t xmin,xmax;
//    Double_t* vx, *vy, *vt;
//    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;
//    	(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;
//    }
//    
//    char* varexp = new char[nch+4];
//    strcpy(varexp,"t:");
//    strcat(varexp,varexp0);
// 
// // Selects the entries   
//    Int_t oldestimate = GetEstimate();
//    if (GetEntries() < 1000000) SetEstimate(GetEntries());
//    else SetEstimate(1000000);
//    TTree::Draw(varexp, selection, "samegoff", nentries, firstentry);
// 
//    delete varexp;
// // Tests if the selected rows really exist
//    if (!GetVar1()) {
//       Warning("DrawSeries","Variable time is not present in this VNtuple");
//       return;
//    } else if (!GetVar2()) {
//       Warning("DrawSeries","Variable doesn't exist");
//       return;
//    }
//    vx = GetV1();
//    vy = GetV2();
//    np = 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 !
//       int nsteps = (int)((xmax-xmin)/mStep)+1;
//       char* titlevs = new char[strlen(varexp0)+1];
//       strcpy(titlevs,varexp0);
//       VSPlot* vsp = new VSPlot(titlevs,titlevs,nsteps,xmin-mStep/2,xmax+mStep/2,gVM);
//       vsp->SetGPSStart(mGPSStart.GetSec(),mGPSStart.GetNsec());
//       vsp->SetStep(mStep);
//       for (i=0;i<np;i++) {
//          int istep = (int)((vx[i] + mStep/2 - xmin)/mStep);
//          vsp->SetBinContent(istep+1,vy[i]);
//       }
//       vsp->Draw(option);
//       delete[] titlevs;
//    }
//    SetEstimate(oldestimate);
// }


- 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.