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