A basic problem

Hi rooters,

I want to get data from Branches and after that fill & draw an histogram with this data (the data could be an array of floats), in real-time. I.e., for each event I read the array in the Branch and I fill the TH1F and draw it , for each entry.

I write this piece of code …

int Analyze_02()
{
//Reset ROOT variables
gROOT->Reset();

// method to open files -> GUI

char *iname=new char[50];

//ask for filenames
cout << “\nIntroduza o nome do ficheiro de dados:\n”;
cin >> iname;
cout << endl;
//cout << “\nO nome do ficheiro de dados introduzido foi: \n” << iname <GetListOfFiles()->FindObject(iname);
if (!fin) {
fin = new TFile(iname);
}

// verifies if the file exits or if it’s valid
TFile f(iname);
if (f.IsZombie()) {
cout << “Error opening file” <Reset();
exit(-1);
}

Analysis();

//return 0;
}

void Analysis()
{
//Aqui assumimos que o ficheiro com os dados ja’ foi aberto
//Na rotina Decode(filename) pode-se abrir um ficheiro ja’ existente.
TFile *fin=(TFile *)gFile;
if (!fin)
{
cout << endl << “Ficheiro .root inexistente! Saindo…” <Get(“DR”);
if (!t)
{
cout << endl << “TTree inexistente! Saindo…” <Print()

// get the data values of the branches in the tree DR
// with declaration of leaves type for raw data
Int_t vsn; // version
Int_t a_i;
Int_t m_i;
Int_t d_i;
Int_t h_i;
Int_t m_i;
Int_t s_i;
Float_t fThr1;
Float_t fThr2;
Float_t fThr3;
Float_t fDel1; // delay trigger
Float_t fDel2; // deltaT shower
Int_t nevmax; // Npedidos
Int_t nevents; // Nevents
Int_t irun; // run number
Int_t ievt; // event
Int_t ientry;
Int_t ntrig;
Int_t a_hit;
Int_t m_hit;
Int_t d_hit;
Int_t h_hit;
Int_t m_hit;
Int_t s_hit;
Int_t ns_hit;
Int_t tPPS;
Int_t tEvento;
Float_t fCh1[256];
Float_t fCh2[256];
Float_t fCh3[256];
Float_t fCh4[256];
Float_t fCh5[256];
Float_t fCh6[256];

// static variables
t->SetBranchAddress(“Versao”,&vsn);
t->SetBranchAddress(“Ano_inicial”,&a_i);
t->SetBranchAddress(“Mes_inicial”,&m_i);
t->SetBranchAddress(“Dia_inicial”,&d_i);
t->SetBranchAddress(“Hora_inicial”,&h_i);
t->SetBranchAddress(“Minuto_inicial”,&m_i);
t->SetBranchAddress(“Segundo_inicial”,&s_i);
t->SetBranchAddress(“Limiar_canal_1”,&fThr1);
t->SetBranchAddress(“Limiar_canal_2”,&fThr2);
t->SetBranchAddress(“Limiar_canal_3”,&fThr3);
t->SetBranchAddress(“Atraso_trigger”,&fDel1);
t->SetBranchAddress(“DeltaT_shower”,&fDel2);
t->SetBranchAddress(“Npedidos”,&nevmax);
t->SetBranchAddress(“Neventos”,&nevents);
t->SetBranchAddress(“RunNumber”,&irun);

// variables avaiable for each event
t->SetBranchAddress(“Evento”,&ievt);
t->SetBranchAddress(“Entrada”,&ientry);
t->SetBranchAddress(“NTriggers”,&ntrig);
t->SetBranchAddress(“Ano”,&a_hit);
t->SetBranchAddress(“Mes”,&m_hit);
t->SetBranchAddress(“Dia”,&d_hit);
t->SetBranchAddress(“Hora”,&h_hit);
t->SetBranchAddress(“Minuto”,&m_hit);
t->SetBranchAddress(“Segundo”,&s_hit);
t->SetBranchAddress(“ns”,&ns_hit);//tTrig
t->SetBranchAddress(“t_PPS”,&tPPS); //regPPS
t->SetBranchAddress(“t_Evento”,&tEvento);//regTrig

//Sinais dos 6 canais
t->SetBranchAddress(“Sinal1”,fCh1);
t->SetBranchAddress(“Sinal2”,fCh2);
t->SetBranchAddress(“Sinal3”,fCh3);
t->SetBranchAddress(“Sinal4”,fCh4);
t->SetBranchAddress(“Sinal5”,fCh5);
t->SetBranchAddress(“Sinal6”,fCh6);

// get entries
Int_t t_nentries=t->GetEntries();
//cout <<t_nentries>Limiar_canal_1");

TPad *pad1 = new TPad(“pad1”,“canal 1”,0.03,0.61,0.49,0.90,17);

// booking histograms
TH1F *t_hist1= new TH1F(“Param1”,“Signal of the event”,100,0.,5.);

//t->GetEntry(27);

for (Int_t i=1 ; i<10 ; i++){
for (Int_t nc=27 ; nc<32>GetEntry(np);// gets the signal
t_hist1->Reset();
for (Int_t j=0 ; j<256>-1){
t_hist1->Fill(j+0.5,fCh1[j]);}
}
//t_hist1->DrawCopy();
}

pad1->cd();
t_hist1->SetFillColor(2);
t_hist1->Draw();

}

}

Any one could help me please?

Thks,

Cheers,

JP

I’ll attach the code
Analyze_02.C (5.2 KB)

Hi,

I somehow did not understand from your post:

  • what are you trying to accomplish
  • how is it not working

It is weird that you have in your code:

Int_t np=(i-1)*6+nc; t_nbytes+=t->GetEntry(np);// gets the signal
So it looks like you look over something and then deduce the entry number in the tree (usually this is the opposite). Also you reset the histogram but never use it …

Cheers,
Philippe.

Thks for the reply,

Well simplifying I only what to do the following:

  1. open a file
  2. read a tree from the file opened
  3. read a branch from the tree (array of floats -> signal)
  4. draw the data from that branch for each event in real time

How should I do that?

I tryied many things but nothing seems to work properly.

Cheers,

JP

I think that what you want is something like:

[code] // booking histograms
TPad *pad1 = new TPad(“pad1”,“canal 1”,0.03,0.61,0.49,0.90,17);
TH1F *t_hist1= new TH1F(“Param1”,“Signal of the event”,100,0.,5.);
t_hist1->Draw();
//t->GetEntry(27);

for(something or the other) {
t_hist1->Reset();

for(something else) {

t_hist1->Fill(j+0.5,fCh1[j]);}
}
pad1->Modified();
pad1->Update();
// and maybe gSystem->ProcessEvents();
}
[/code]
Cheers,
Philippe

well it doesn’t solve my problem …

After I post I got another ideia … in attach I delivery the new code…

Can anyone tell me what I’m doing wrong …???

I have one array[256] and 10000 events … how coul’d I see each event ?
Drawing it on canvas?

Thks

Cheers

JP
Analyze_03.C (5.57 KB)
Analyze_03.C (5.57 KB)

well it doesn’t solve my problem …

After I post I got another ideia … in attach I delivery the new code…

Can anyone tell me what I’m doing wrong …???

I have one array[256] and 10000 events … how coul’d I see each event ?
Drawing it on canvas?

Thks

Cheers

JP
Analyze_03.C (5.57 KB)

You have: // get all values from branch variables -> maybe necessary to TH1F,for TTree it isn't for (Int_t b=0 ; b<=32 ; b++){ t->GetEntry(b); }Note that each call to t->GetEntry over-write the previous information. Since you do use the data in the loop this is basically strictly equivalent to simply doing:t->GetEntry(32);
I am strill extremely confused in how your data might be organized and I suspect (pardon me if I am wrong) that you might be confused too.
I strongly recommend that you re-read the Chapter on TTree in the Users’ Guide. Also you may want to go back to the original author of the code that produced your input file.

Also you said:[quote]well it doesn’t solve my problem … [/quote]Unfortunately this does not give me any clue in how your code is ‘failing’.

Cheers,
Philippe.

PS. Also never use gROOT->Reset within a function … use it only in an unamed macro or on the ROOT command line.

In fact if I use …

// get all values from branch variables -> maybe necessary to TH1F,for TTree it isn’t
for (Int_t b=0 ; b<32>GetEntry(b);
}
cout << a_i << endl;
cout << m_i << endl;

I could see the value of each branch in the tree…

The tree was builded and I want to extract the data … I give the print output of this.
tree_list.txt (10.6 KB)

Yes … but for how many entries? (I claim 1 … however your code was chopped off because it was interpreted as HTML code.)
Also You loop over 32 entries … but there are 10000 entries in your TTree.

Given your TTree information, we could provide an example … however th next question is … how do you want to represent the information?

Philippe.

PS. When pasting code you shold disable HTML for that post.

Well theoricly I have 10000 events (triggered) and I have the signals from 6 channel from 27 to 32 (each of them, as you realize by now, it’s an array[256]).

My ideia is … I have event 1 in Sinal1 for instance … and so on …

How could I read the 10000 events stored in the arrays?
In real-time … this is … with the possibility to see event by event, a range of events, all events … do you understand?

Thks

Cheers,

JP

[quote]In real-time … this is … with the possibility to see event by event, a range of events, all events … do you understand?
[/quote]With what kind of interface?

For example:

tree->Draw("Sinal1");will draw all the values for all the event for Sinal1 (I assume your trigger 27).

tree->Draw("Sinal1","","",1,0);will draw all the values for the first event for Sinal1 (I assume your trigger 27).

tree->Draw("Sinal2","","",10,20);will draw all the values for the event number 20 though 29 for Sinal2 (I assume your trigger 28).

tree->Draw("Sinal1[9]");will draw the 10th values for all the events for Sinal1 (I assume your trigger 27).

etc.

Cheers,
Philippe.

Thks for the explanation … I’ll try it later … and if I want the same options but with TH1F?

Cheers,

JP

[quote]and if I want the same options but with TH1F? [/quote]Humm … I am not sure what you mean (the code I gave you creates TH1D … but this can be easily customize (re-read the document for TTree::Draw).

Philippe.