THStack question

Hi,

I have to superimpose 4 histos stored in a root file, and save the superimposed histo in another file.

I used THStack with this code:

[code]#include <TFile.h>
#include <TObjArray.h>
#include <TGraph.h>
#include <TObject.h>
#include <TCint.h>
#include <TGraphErrors.h>
#include <TMultiGraph.h>
#include <TMarker.h>
#include <TTree.h>
#include <TBranch.h>
#include <TFolder.h>
#include <TString.h>
#include <TH1.h>
#include <THStack.h>
#include <TCanvas.h>
#include
#include
#include

using namespace std;

int main(){

ostringstream title;
ostringstream titlegraph1;
ostringstream titlegraph2;
ostringstream titlegraph3;
ostringstream titlegraph4;

ostringstream endTitle;
ostringstream otherTitle;

title<<“el10MeVtheta0phi0”;

otherTitle<<title.str().c_str()<<“TotPmts.root”<<ends;

cout<<“Processing “<<otherTitle.str().c_str()<<”…”;
TFile *myfile =TFile::Open(otherTitle.str().c_str());

titlegraph1<<title.str()<<“pmt1”;
titlegraph2<<title.str()<<“pmt2”;
titlegraph3<<title.str()<<“pmt3”;
titlegraph4<<title.str()<<“Tot”;

TH1F primo =(TH1F)myfile->Get(titlegraph1.str().c_str());
TH1F secondo =(TH1F)myfile->Get(titlegraph2.str().c_str());
TH1F terzo =(TH1F)myfile->Get(titlegraph3.str().c_str());
TH1F tot =(TH1F)myfile->Get(titlegraph4.str().c_str());

THStack *hs = new THStack(“pmts”,“pmts”);
primo->SetLineColor(kRed);
secondo->SetLineColor(kGreen);
terzo->SetLineColor(kBlue);
tot->SetLineColor(kYellow);

hs->Add(primo);
hs->Add(secondo);
hs->Add(terzo);
hs->Add(tot);

TFile *prova =new TFile(“prova.root”,“recreate”);
primo->Write();
secondo->Write();
terzo->Write();
tot->Write();
hs->Write();

cout<<“All Green!\n”;
return 0;
}[/code]

all is ok.

There is a way to include the drawing option “nostack” in the script?

I mean, i create a .exe file compiling this script outside of ROOT, i run it and i create the prova.root file with the histos.
Now i have to select the stack file, select “DrawClone” and select the option nostack.

There is a way to “automate” this process, and have the corrected histo ready?
(i think i have the same problem trying to include grid lines or labels from script, but this is another story) .

Amir

Once you have attached the file, why don’t you simply do: pmts->Draw(“nostack”) ; … did I missed something ?

the “setting axis range” thread is newer than this one.

As you have noticed :wink: i’m not expert of ROOT.

here i was trying to run an early version of sovrapposiz.cc (the file i sent you in the other thread) and call Draw(), SetTitle() and other cosmetics without having to start a ROOT session. (So i could leave the pc working alone, in the night).
I thought i could store someway the nostack option in the program so, the next time i would open a TBrowser, a simple doubleclick on the icon i wold have the stack displayed with the nostack option.
But i realized i can’t use Draw() and related methods outside ROOT: for example to compile pmts->Draw(nostack) outside ROOT produces a segfault.

So i created a script to run it in a ROOT session after creating the stack with sovrapposiz.cc (is the one named drawing.cc)

Now first i run the sovrapposiz.cc, then i open ROOT and run drawing.cc .

everithing works fine now.

Thank you very very much for your time