I have a related question and I am not sure if it deserves an independent question so just asking here:
We can create root macros that can be compiled and executables can be produced, for example consider a program named macro.cpp:
int main(int argc, char *argv[])
{
//code body utilizing the arguments argv[] etc
// we open a root file containing tree named TreeName and containing a leaf named var1 here and
//fill some histograms
TH1F *hist = new TH1F("hist","hist",nbin,a,b);
for (Long64_t jentry=0; jentry<nentries; jentry++)
{
//blah blah
hist->Fill(some_variable);
}
return 0;
}
We can compile it
g++ macro.cpp `root-config --glibs --cflags` -o macro
Then we can run this from the terminal as:
./macro arg1 arg2 etc
this method works perfectly, but I was wondering if it was possible to avoid that for
loop over the tree and the fill
method hist->Fill()
, instead we use the direct filling method
TreeName->Draw("var1>>hist",Form("var1 > %g",x));
keeping everything else the same?
Therefore the final program should look something like this:
int main(int argc, char *argv[])
{
TString FileName;
FileName.Form("%s", argv[1]); //rootfile through argument
double cut1 = atof(argov[2]); //cut on one of the variable var1 in the tree
TFile *file = TFile::Open(FileName);
TH1F *hist = new TH1F("hist","hist",nbin,a,b);
TreeName->Draw("var1>>hist",Form("var1 > %g",cut1));
return 0;
}
After compiling I run:
./macro example.root someNumber
If this can be done, what should be the syntax?
Thanks a lot.