Hi Reinhardt, On Mon, 18 Mar 2002 12:17:22 +0000 (GMT) Reinhardt Chamonal <chamonal@ph.ed.ac.uk> wrote concerning "[ROOT] Using a declared variable in a root command line": > Hi the experts, > > First that's going be a very very basic question. I had a look at > various examples around but I am stuck and frustrated. (I am started > at Root) What I would like to do is a little simple script to take a > number and then plot the histogram corresponding to this number Here > is what I do: > > #include <iostream.h> > > int show(Int_t nb) { > gROOT->Reset(); > c1 = new TCanvas("mapmt","MAPMTs",10,40,800,600); > TFile f("r99.root"); > //TFile *f = new TFILE("r99.root"); > gPad->SetLogy(); > TH1F *boundary = new TH1F("boundary","Channel Signal",500,-0.5,250.5); > h10->Draw("norm>>+boundary","pdid==0 && pixid==nb"); > c1->Update(); > //return 0; > > } > > so calling show(2) should draw the histogram cooresponding to > pixid=2 when calling h10->Draw("norm>>+boundary","pdid==0 && > pixid==nb"); where I put my variable nb. Erh, no it shouldn't. The two characters, `n' & `b' in your string has nothing to do with the function argument `nb'. The proper way to do this is: int show(Int_t nb) { gROOT->Reset(); c1 = new TCanvas("mapmt","MAPMTs",10,40,800,600); TFile f("r99.root"); gPad->SetLogy(); TH1F *boundary = new TH1F("boundary","Channel Signal",500,-0.5,250.5); h10->Draw("norm>>+boundary", Form("pdid==0 && pixid==%d", nb)); c1->Update(); return 0; } Hence, inserting the value stored in `nb' into the string. > It obviously doesn't like it certainly because of the "". What is > the correct declaration in this case ? Has nothing to do with declarations, but everything to do how you pass values into a string. Yours, Christian Holm Christensen ------------------------------------------- Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91 DK-2200 Copenhagen N Cell: (+45) 28 82 16 23 Denmark Office: (+45) 353 25 305 Email: cholm@nbi.dk Web: www.nbi.dk/~cholm
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:46 MET