Using SetOptStat in batch mode

Hello,

I wrote a macro, that reads histograms from several ROOT files, weight them, add them and draw them to a postscript. I need all the available information the stat box can give me ; in my macro I therefore put a

gStyle->SetOptStat(222222222);

If I run the macros from cint :

root -b -l
.L BackgroundControlPlots.C
BackgroundControlPlots();

it works. I get a PS file with everything I asked the stat box to display.
If I try to automate the job by using the -q option :

root -l -b -q BackgroundControlPlots.C

I also get a PS file, but the stat box only displays the defaults variables, ie Entries, Mean and RMS. It seems like it ignores the SetOptStat command. Why is that?

I am using ROOT v 4.04/02b under scientific linux.

Thank you.

I tried to reproduce what you are describing here with the following macro, but for me it works even in batch mode. I get all the statistics drawn in th PS file.

{
   TCanvas *c1 = new TCanvas("c1", "c1",15,47,731,570);
   TFile hsimple("hsimple.root");
   gStyle->SetOptStat(221112211);
   hpxpy->Draw();
   c1->Print("c1.ps");
}

PS: hsimple.root is the file generated by $ROOTSYS/tutorials/hsimple.C

Thanks a lot for your reply. Here is the code I am using - you might get ideas, as to what I am doing wrong… Thanks again for your help.

#include "TSystem.h"
#include "TObject.h"
#include "TObjArray.h"
#include "TObjString.h"
#include "TDirectory.h"
#include "TKey.h"
#include "TIterator.h"
#include "TList.h"
#include "TString.h"
#include "TCollection.h"
#include "TStyle.h"
#include "TROOT.h"
#include "TPad.h"
#include "Riostream.h"
#include "TLegend.h"
#include "TH1.h"



TString ParseInputLine(TString& readline) {

  std::string delim = "]//";
  TString histoname;
  std::vector<std> result;
  TObjArray *tokens = readline.Tokenize(delim.c_str());
  TObject *p;
  {
    TIter iter(tokens);
    while(p = iter.Next()) {
      TObjString *item = (TObjString*)p;
      TString pbackitem = item->GetString();
      pbackitem = pbackitem.Strip(TString::kBoth);
      result.push_back(pbackitem.Data());
    }
  }
  delete tokens; 
  if(result.size() > 1) {
    histoname = result[1].data();
  }
  return histoname;
}


BackgroundControlPlots(const char *version, const char *process) {

 
  gStyle->SetOptStat(222222222);
  gROOT->ForceStyle();
  
  char* outpath = "./"; //write control plots to..
  char* path2 = ".//rootuples/"; //read rootuples from...
  char path[256];

  float Lumi = 1050.81;
  double WjjScale=1.4;
  double WbbScale=1.;
  double WccScale=1.;

  double ZjjScale=1.3;
  double ZbbScale=1.35;
  double ZccScale=1.35;

  if(process == "wjj")
    {
      // gStyle->SetOptStat(222222222);
      std::string temp;
      TString line,histname;

      TFile *wjj[6];

      char  psfile[256];
	  
      sprintf(psfile,"%s%swjj.ps",outpath,version);


      TCanvas *tempC = new TCanvas("","",600,800);
      tempC->SetFillColor(0);
      tempC->SetFillStyle(4000);
      TPostScript* PS = new TPostScript(psfile,111);
      gROOT->SetStyle("Plain");      
      PS -> NewPage();


      sprintf(path,"%s%swlepnu0lp_exclMCmu.root",path2,version);
      wjj[0] = new TFile(path);
      sprintf(path,"%s%swlepnu1lp_exclMCmu.root",path2,version);
      wjj[1] = new TFile(path);
      sprintf(path,"%s%swlepnu2lp_exclMCmu.root",path2,version);
      wjj[2] = new TFile(path);
      sprintf(path,"%s%swlepnu3lp_exclMCmu.root",path2,version);
      wjj[3] = new TFile(path);
      sprintf(path,"%s%swlepnu4lp_exclMCmu.root",path2,version);
      wjj[4] = new TFile(path);
      sprintf(path,"%s%swlepnu5lp_inclMCmu.root",path2,version);
      wjj[5] = new TFile(path);

      TH1F *hL[6];
      TH1F *hT[6];

      double scale[6];

      scale[0]=WjjScale*298.5643*Lumi/1563955;
      scale[1]=WjjScale*4574.3616*Lumi/2257330; 
      scale[2]=WjjScale*1273.94*Lumi/2754645; 
      scale[3]=WjjScale*70.5607*Lumi/789021; 
      scale[4]=WjjScale*15.8305*Lumi/778522; 
      scale[5]=WjjScale*11.2901*Lumi/57973;
      ifstream fstr("./TestNames",ios::in);
      while ( fstr.good() && fstr ) 
	{
	  getline(fstr,temp);
	  line = temp.c_str();
	  histname = ParseInputLine(line);
	  for(int file=0 ; file < 6 ; file++)
	    {
	      if(wjj[file] == NULL) 
		{
		  wjj[file] = new TFile("./rootuples/dummymacro.root");
		  scale[file] = 0;
		  cout << "::WARNING:: At least one missing file for process wjj" <<endl>Get(Form(histname.Data(),0,0,0));
	      hT[file]  = (TH1F *) wjj[file]->Get(Form(histname.Data(),0,1,0));
	    }
		    
	  if(hL[0] && hT[0] && hL[1] && hT[1] && hL[2] && hT[2] && hL[3] && hT[3] && hL[4] && hT[4] && hL[5] && hT[5])
	    {
	      for(int file=0 ; file <6>UseCurrentStyle();
		  hT[file]->UseCurrentStyle();
		}

	      hL[0]->Scale(scale[0]);
	      hL[0]->Add(hL[1],scale[1]);
	      hL[0]->Add(hL[2],scale[2]);
	      hL[0]->Add(hL[3],scale[3]);
	      hL[0]->Add(hL[4],scale[4]);
	      hL[0]->Add(hL[5],scale[5]);
		  
	      hT[0]->Scale(scale[0]);
	      hT[0]->Add(hT[1],scale[1]);
	      hT[0]->Add(hT[2],scale[2]);
	      hT[0]->Add(hT[3],scale[3]);
	      hT[0]->Add(hT[4],scale[4]);
	      hT[0]->Add(hT[5],scale[5]);
		  
	      tempC -> Divide(1,2);
	      tempC -> cd(1); hL[0] -> Draw(); tempC -> Update();
	      tempC -> cd(2); hT[0] -> Draw(); tempC -> Update();
	      tempC -> Clear();
	    } 
	}
      tempC -> Close();
      PS -> Close();
      //gROOT -> SetBatch(kFALSE);
      fstr.close();


    }
}

Can you put your file as an attachment. When I copy/paste it from the forum I get C++ errors. It is better to send long files as attachments not as inline code.

Sure. Here it is.
BackgroundControlPlots.C (4.39 KB)

Well, it is not very good. I get:

is it really working for you ?

I just checked (redownloaded the coded from the forum and loaded it into ROOT) and it works fine.

Please send a version of your macro that we can execute.
Your macro requires files.

Rene

Hello,

I found out that commenting out the following line

gROOT->SetStyle(“Plain”);

solved my problem.