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