+
+
+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 *tempArray = new Double_t[entries];
+
+ Double_t count = 0.5;
+ Double_t *vrun = new Double_t[entries];
+ Int_t icount=0;
+ //
+ tempArray[index[0]] = count;
+ vrun[0] = graph->GetX()[index[0]];
+ for(Int_t i=1;i<entries;i++){
+ if(graph->GetX()[index[i]]==graph->GetX()[index[i-1]])
+ tempArray[index[i]] = count;
+ else if(graph->GetX()[index[i]]!=graph->GetX()[index[i-1]]){
+ count++;
+ icount++;
+ tempArray[index[i]] = count;
+ vrun[icount]=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,tempArray,graph->GetY());
+ graphNew->GetXaxis()->Set(newNbins,newBins);
+
+ Char_t xName[50];
+ for(Int_t i=0;i<count;i++){
+ snprintf(xName,50,"%d",Int_t(vrun[i]));
+ graphNew->GetXaxis()->SetBinLabel(i+1,xName);
+ }
+ graphNew->GetHistogram()->SetTitle("");
+
+ delete [] tempArray;
+ delete [] index;
+ delete [] newBins;
+ delete [] vrun;
+ return graphNew;
+}
+