Problem with open script again

I have a problem with rerunning script again. When I change something in there, then run it again error is appearing. But first running going well. root-6.18.04

root [0] .x view.c
root [1] .x view.c
/home/pack/programs/root/data/runn03/./view.c:4:10: error: redefinition of 'cond'
        TString cond = "";
/home/pack/programs/root/data/runn03/./view.c:4:10: note: previous definition is here
        TString cond = "";

Thank you. I’ve tried, but anyway it doesn’t work

root [0] .x view.c
root [1] view();
input_line_326:2:3: error: use of undeclared identifier 'view'
Error in <HandleInterpreterException>: Error evaluating expression (view()).
Execution of your code was aborted.

You probably have an unnamed macro which begins with just a “{”. Try to use “void view() {” instead.

I did it before, but there is also error due to no libraries. For it I need to type libraries like #include mylib.h etc. So I don’t know which libs I need:)

In ROOT, usually each class has its own include file, e.g. for a “TString” you need:

#include "TString.h"
void view() {
  // ...

I added some libs. Perhaps I missed something
view.c (16.2 KB)

At least:

#include "TPad.h"
#include "TStyle.h"
#include "TAxis.h"
#include "TH1.h"
#include "TH2.h"

For every pad, instead of e.g. “c1_1->cd();”, you need “c1->cd(1);”, and so on.
For every pad, instead of e.g. “c1_1->SetLogy();”, you need “gPad->SetLogy();”, and so on.
Then, for every histogram, you’d better use something like this:

TH1D *h1 = new TH1D("h1", "it is ch1 drawn;dE0[ch];number of cases", 4000, 1., 4001.);
ch.Draw("ch1>>h1", cond, "", nentries);

or that:

TH2D *hh1 = new TH2D("hh1", "it is ch1:ch4 drawn;TOF(AC2-F3);dE0", 200, 0., 4000., 200, 0., 4000.);
ch.Draw("ch1:ch4>>hh1", cond, "colz", nentries);
1 Like

How can I put a few histograms in one convas. I did like

TH1D *h1 = new TH1D("h1", "it is ch1 drawn;dE0[ch];number of cases", 4000, 1., 4001.);
ch.Draw("ch1>>h1", cond, "", nentries);

ch.Draw("ch3>>h1", cond, "", nentries);

ch.Draw("ch4>>h1", cond, "", nentries);

ch.Draw("ch5>>h1", cond, "", nentries);

You can “reuse” the histogram, e.g.:

ch.Project("h1", "ch1", cond, "", nentries);
h1->DrawCopy(""); // "" or another drawing option

You can also immediately change its title “on the flight”:

h1->DrawCopy("")->SetTitle("something?;another x;different y");
1 Like

Thank you a lot. It works, i.e. with this script it is able to reload “.x view.c” again in one workspace

TCanvas *c1 = new TCanvas("c1", "c1",125,30,1500,800);
TH1D *h1 = new TH1D("h1", "ch1;dE0;entries", 4000, 1., 4001.);
TH1D *h2 = new TH1D("h2", "ch3;dEi;entries", 4000, 1., 4001.);
//TH1D *h2 = new TH1D("h2", "ch3;dEi;entries", 3900, 101., 4001.);
TH1D *h3 = new TH1D("h3", "ch4;TOF(AC2-F3)[ch];entries", 1000, 2001., 3001.);
TH1D *h4 = new TH1D("h4", "ch5;TOF(AC1-AC2)[ch];entries", 4000, 1., 4001.);

ch.Draw("ch1>>h1", cond, "", nentries);

ch.Draw("ch3>>h2", cond, "", nentries);

ch.Draw("ch4>>h3", cond, "", nentries);

ch.Draw("ch5>>h4", cond, "", nentries);

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