Hi,
I’m having trouble with making a plot on a TCanvas:
I create the canvas with the command inside the function void Analysis::Terminate()
TCanvas *c1=new TCanvas(L2cuts", “L2cuts”, 200, 10, 800, 800);
and then a command like histogram->Draw();
but when I run the script the histogram flashes up and then disappears.
The file will save ok with the histogram showing but I want an interactive canvas so I can move the stats boxes around and so on.
Any ideas?
Ellie
Post the shortest possible version of your script reproducing the problem.
It looks like the classical example of objects being destroyed when
the script terminates because one object is out of scope or because
you are closing the file containing your objects.
Rene
this is the same problem except I’ve made the code a lot shorter…
Ellie
#define Analysis_cxx
#include “Analysis.h”
#include “functions.h”
#include <TROOT.h>
#include <TH1F.h>
#include <TF1.h>
#include <TCanvas.h>
#include “THistPainter.h”
#include “TPaveStats.h”
#include <TMath.h>
#include <TStyle.h>
#include
#include
#include <TLorentzVector.h>
using namespace std;
void Analysis::Begin(TTree *tree)
{
Etcut_nocuts_hist=new TH1F(“Etcut (nocuts)”, “Etcut”, 60,0,120);
Etcut_L1_hist=new TH1F(“Etcut_L1”, “Etcut_L1”, 60,0,120);
Etcut_L2_hist=new TH1F(“Etcut_L2”, “Etcut”, 60,0,120);
}
void Analysis::SlaveBegin(TTree *tree)
{
Init(tree);
TString option = GetOption();
}
Bool_t Analysis::Process(Long64_t entry)
{
fChain->GetTree()->GetEntry(entry);
cout << entry << endl;
for (int i=0; i<nRoi; i++)
Etcut_nocuts_hist->Fill(EtcutL2[i]/1000);
return kTRUE;
}
void Analysis::SlaveTerminate()
{
}
void Analysis::Terminate()
{
gStyle->SetOptStat(11111);
TCanvas *c1=new TCanvas(“L2Cuts”,“L2cuts”, 200, 10, 800,800);
Etcut_nocuts_hist->GetXaxis()->SetTitle(“Et/GeV”);
Etcut_nocuts_hist->SetLineColor(kBlue);
Etcut_nocuts_hist->Draw();
Etcut_L1_hist->SetLineColor(kGreen);
Etcut_L1_hist->Draw(“SAMES”);
Etcut_L2_hist->SetLineColor(kRed);
Etcut_L2_hist->Draw(“SAMES”);
}
oops sorry; remove the 4 lines near the bottom where I have EtcutL1 and L2 being drawn, I didn’t mean to paste them
Ellie
This is not something that we can execute.
Olease post the strict minimum NECESSARY to run your system.
Rene