Multiple TGraph in a single TCanvas

Hello everyone,

I’m newbie with ROOT and i will thank you so much in advance for your replies!
So, I have this problem…I’m writing a macro in which several .root file have been
added to a chain filling an array like that:
var [nevents][#_of_entries_at_each_events] (let’s say [1870][64])

I’m trying to create a canvas splitted like (2,8) so I esxpet to have 16 graphs in it,
8 for each columns. I tied to navigate through the web finding a solution and also
in ROOT User guide (actually the Multigraph class) but with no success.
What I have done so far is that:

{
TCanvas *b = new TCanvas("SiPM sensors", "SiPM Sensors", 1400, 800);
b->Divide(2,8);
TChain *chain = new TChain("thk");
chain.Add("file1.root");
chain.Add("file2.root");
...
...
...
Int_t nevent = thk->GetEntries();
cout << "# of event = " << nevent << endl;
Float_t SiPM_data[nevent][64];
Float_t sipm_data[64];
Float_t mean_sipm_matrix[nevent];
Float_t list1[nevent];
Float_t CPU_packet_time_float[nevent];
Int_t mean_sipm_matrix_int[nevent];
thk->SetBranchAddress("sipm_data", &sipm_data);
Int_t cpu_packet_time;
Int_t CPU_packet_time[nevent];
thk->SetBranchAddress("cpu_packet_time", &cpu_packet_time);
Float_t sum_sipm;
thk->GetEntry(0);
Int_t cpu_packet_time_first;
cpu_packet_time_first=cpu_packet_time;
thk->GetEntry(nevent-1);
Int_t cpu_packet_time_last;
cpu_packet_time_last=cpu_packet_time;


for (Int_t i=0; i<nevent; i++) {
	thk->GetEntry(i); 
	CPU_packet_time[i]=cpu_packet_time[i];
	for (Int_t j=0;j<64;j++) {
		SiPM_data[i][j]=sipm_data[j];
	//cout << "at time " << cpu_packet_time[i] << " sipm matrix shows " << SiPM_data[i][j] << endl;
	}
}


for (Int_t ii=0; ii<nevent; ii++) {
	thk->GetEntry(ii); 
	sum_sipm=0;
	for (Int_t jj=0;jj<64;jj++) {
		sum_sipm = SiPM_data[ii][jj] + sum_sipm;	
	}
	mean_sipm_matrix[ii]= sum_sipm/64;
	//cout << "mean at " << CPU_packet_time[ii] << " is " << mean_sipm_matrix[ii] << endl;	
}


for (Int_t jj=0; jj<nevent; jj++) {
	mean_sipm_matrix_int[jj]=(Int_t) mean_sipm_matrix[jj];
	CPU_packet_time_float[jj]=(Float_t) CPU_packet_time[jj];
}

TGraph* gr_b[8];
TMultiGraph mg = new TMultiGraph();

for (k=0; k<16; k++) {

for (Int_t kk=0; kk<nevent; kk++) {
		list1[kk]=SiPM_data[kk][k];
				
	}
        gr_b[k] = new TGraph(nevent,CPU_packet_time_float,list1);
	if (k<8) {
                      b->cd(1,k+1);
                    }
        else {
                      b->cd(2,k-7);
               }
	gr_b[k]->GetXaxis()->SetTitle("time [unix]");
	gr_b[k]->GetYaxis()->SetTitle("count");
	gr_b[k]->Draw("A*");
	mg->Add(gr_b[k]);
}
mg->Draw(“A*”);
b->SaveAS("light_curve_first8pixels.pdf");
}

I’m having this error:

Error: Can't call TMultiGraph::TMultiGraph((class TMultiGraph*)0x149b3f0) in current scope macro_sipm_single.c:158:
Possible candidates are...
(in TMultiGraph)
/home/giorgio/root/lib/libHist.so  -1:-1   0 protected: TMultiGraph TMultiGraph::TMultiGraph(const TMultiGraph&);
/home/giorgio/root/lib/libHist.so  -1:-1   0 public: TMultiGraph TMultiGraph::TMultiGraph(void);
/home/giorgio/root/lib/libHist.so  -1:-1   0 public: TMultiGraph TMultiGraph::TMultiGraph(const char* name,const char* title);
*** Interpreter error recovered ***

Any suggestion? WHat I’m missing? Thank you!


Please read tips for efficient and successful posting and posting code

ROOT Version: ROOT 5.34/36
Platform: Not Provided
Compiler: CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010


TMultiGraph *mg = ...

Oh yes, you’re right Wile, thank you!
After the change I’ve got this:

Error: Can’t call TCanvas::cd(1,k+1) in current scope macro_sipm_single.c:166:
Possible candidates are…
(in TCanvas)
/home/giorgio/root/lib/libGpad.so -1:-1 0 public: virtual TVirtualPad* TCanvas::cd(Int_t subpadnumber=0);
(in TPad)
/home/giorgio/root/lib/libGpad.so -1:-1 0 public: virtual TVirtualPad* TPad::cd(Int_t subpadnumber=0); //MENU
public: virtual TVirtualPad* TVirtualPad::cd(Int_t subpadnumber=0)=0;
*** Interpreter error recovered ***

maybe there is a better way to do that, any idea or suggestion?

You probably always want: b->cd(k+1); // k = 0, ..., 15

Ok, now i solved almost everything like that:

TGraph* gr_b[16];
TMultiGraph* mg = new TMultiGraph();
for (k=0; k<16; k++) {
for (Int_t kk=0; kk<nevent; kk++) {
list1[kk]=SiPM_data[kk][k];
}
gr_b[k] = new TGraph(nevent,CPU_packet_time_float,list1);
b->cd(k+1);
gr_b[k]->GetXaxis()->SetTitle(“time [unix]”);
gr_b[k]->GetYaxis()->SetTitle(“count”);
gr_b[k]->Draw(“A*”);
mg->Add(gr_b[k]);
}
b->SaveAs(“light_curve_1.pdf”);

Thank you very much Wile!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.