]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Adding functionality for sparse drawing
authormarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 26 Mar 2011 14:02:13 +0000 (14:02 +0000)
committermarian <marian@f7af4fe6-9843-0410-8265-dc069ae4e863>
Sat, 26 Mar 2011 14:02:13 +0000 (14:02 +0000)
STAT/TStatToolkit.cxx
STAT/TStatToolkit.h

index 36a9d08688eab3e731497c8d7be8101f8b168498..3382cb8605f6898c56b23017a058e79a108da1f1 100644 (file)
@@ -1173,3 +1173,55 @@ TString  TStatToolkit::MakeFitString(TString &input, TVectorD &param, TMatrixD &
   result+="-0.)";
   return result;
 }
+
+
+TGraph * TStatToolkit::MakeGraphSparse(TTree * tree, const char * expr, const char * cut){
+  //
+  // Make a sparse draw of the variables
+  //
+  const Int_t entries =  tree->Draw(expr,cut,"goff");
+  //  TGraph * graph = (TGraph*)gPad->GetPrimitive("Graph"); // 2D
+  TGraph * graph = new TGraph (entries, tree->GetV2(),tree->GetV1());
+  //
+  Int_t *index = new Int_t[entries];
+  TMath::Sort(entries,graph->GetX(),index,kFALSE);
+  
+  Double_t *VV = new Double_t[entries];
+
+  Double_t count = 0.5;
+  vector<Int_t> vrun;
+  VV[index[0]] = count;
+  vrun.push_back(graph->GetX()[index[0]]);
+  for(Int_t i=1;i<entries;i++){
+    if(graph->GetX()[index[i]]==graph->GetX()[index[i-1]])
+      VV[index[i]] = count; 
+    else if(graph->GetX()[index[i]]!=graph->GetX()[index[i-1]]){
+      count++;
+      VV[index[i]] = count;
+      vrun.push_back(graph->GetX()[index[i]]);
+    }
+  }
+  
+  const Int_t newNbins = int(count+0.5);
+  Double_t *newBins = new Double_t[newNbins+1];
+  for(Int_t i=0; i<=count+1;i++){
+    newBins[i] = i;
+  }
+  
+  TGraph *graphNew = new TGraph(entries,VV,graph->GetY());
+  graphNew->GetXaxis()->Set(newNbins,newBins);
+  
+  Char_t xName[50];
+  Double_t bin_unit = graphNew->GetXaxis()->GetNbins()/count;
+  for(Int_t i=0;i<count;i++){
+    snprintf(xName,50,"%d",vrun.at(i));
+    graphNew->GetXaxis()->SetBinLabel(i+1,xName);
+  }
+  graphNew->GetHistogram()->SetTitle("");
+  
+  delete [] VV;
+  delete [] index;
+  delete [] newBins;
+  return graphNew;
+}
+
index 79aedce7ac37459edd6f6fba23d14420cbf274ad..3453d67fc2cc61fb9c7e8feeeead2bca2e3e9f1d 100644 (file)
@@ -38,7 +38,10 @@ class TStatToolkit : public TObject
 
   static TGraph2D *  MakeStat2D(TH3 * his, Int_t delta0, Int_t delta1, Int_t type);
   static TGraph *  MakeStat1D(TH3 * his, Int_t delta1, Int_t type);
-
+  //
+  // Graph tools
+  //
+  static TGraph * MakeGraphSparse(TTree * tree, const char * expr="Entry", const char * cut="1");
   //
   // Fitting function
   //