Hello,
I’m currently working on a ROOT macro to plot a surface plot using TGraph2D.
What I want to do is put time on the X-axis, the channel number on the Y-axis, and the value of the current at a specified time and channel on the Z-axis.
So I came up with this :
#include <TMath>
#include <TGraph2D>
#include <TRandom>
#include <TStyle>
#include <TCanvas>
#include <fstream>
#include <iostream>
#include <vector>
#include <stdio>
#include <stdlib>
#include <time>
#include <string>
void graph2d()
{
TString filename;
cin >> filename;
TFile f(filename) ;
TTree *T = HVtree ;
TBranch *br ;
struct thvinfo {
int sts;
float im,vm;
time_t t;
};
thvinfo info;
time_t tfirst;
T->SetBranchAddress("offset", &tfirst );
br = HVtree->GetBranch("offset");
br->GetEntry(0);
TCanvas *c = new TCanvas("c","Current Distribution",50,50,900,700);
TGraph2D *dt = new TGraph2D();
for (int mod = 0; mod < 320; mod++){
for (int ch = 0; ch <16>SetBranchAddress( Form( "channel_%d", index ), &info);
br = HVtree->GetBranch( Form( "channel_%d", index) );
int n = br->GetEntries();
cout <<"Module" << mod <<"Channel " << ch << endl;
vector<float> Ivect;
vector<float> Tvect;
for (int k=0 ; k<n>GetEntry(k);
Tvect.push_back(difftime((info.t),tfirst));
Ivect.push_back(info.im);
}
float* Current = new float[Ivect.size()];
float* TimeAxis = new float[Ivect.size()];
for (unsigned m=0 ; m<Ivect>SetPoint(index,TimeAxis,CH,Current);
}
}
char datemp[100];
struct tm *ptm;
ptm = localtime ( &tfirst );
strftime(datemp, 100, "%Y-%m-%d %H:%M:%S", ptm);
TDatime da(datemp);
gStyle->SetTimeOffset(da.Convert());
dt->Draw("surf1");
dt->GetXaxis()->SetTimeDisplay(1);
c->Update();
}
The input ROOT file is organized by another macro like this :
HVtree ----> channel_xxx ------> t,im (which are leaves)
Now my problem : I think I store the values correctly into the floats vectors, but when I execute it I get the error :
Error: Can’t call TGraph2D::SetPoint(index,TimeAxis,CH,Current)
Maybe it’s because the 3 values are not of the same type, I must say I have no idea…
PLease someone help me !
Thank you.