Error in histogramming

[code]// main05.cc is a part of the PYTHIA event generator.
// Copyright © 2014 Torbjorn Sjostrand.
// PYTHIA is licenced under the GNU GPL version 2, see COPYING for details.
// Please respect the MCnet Guidelines, see GUIDELINES for details.

// This is a simple test program.
// It studies jet production at the LHC, using SlowJet and CellJet.
// Note: the two finders are intended to construct approximately the same
// jet properties, but provides output in slightly different format,
// and have here not been optimized to show maximum possible agreement.
#include “TH1.h”
#include “TVirtualPad.h”
#include “TApplication.h”

// ROOT, for saving file.
#include “TFile.h”
#include "Pythia8/Pythia.h"
using namespace Pythia8;

int main(int argc, char* argv[]) {

// Create the ROOT application environment.
TApplication theApp(“hist”, &argc, argv);
// Create file on which histogram(s) can be saved.
TFile* outFile = new TFile(“hist.root”, “RECREATE”);

// Book histogram.
TH1F *hist1 = new TH1F(“eTdiffC”,“eT difference between jets”, 100, -0.5, 799.5);

// Number of events, generated and listed ones.
int nEvent = 500;
int nListJets = 2;

// Generator. LHC process and output selection. Initialization.
Pythia pythia;
pythia.readString(“Beams:frameType = 4”);

pythia.readString("ProcessLevel:all = off");

pythia.readString("Beams:LHEF=unweighted_events.lhe");			

// pythia.readString(“Beams:eCM = 14000.”);
//pythia.readString(“HardQCD:all = on”);
pythia.readString(“PhaseSpace:pTHatMin = 200.”);
pythia.readString(“Next:numberShowInfo = 0”);
pythia.readString(“Next:numberShowProcess = 0”);
pythia.readString(“Next:numberShowEvent = 0”);
pythia.init();

// Common parameters for the two jet finders.
double etaMax = 25.;
double radius = 0.7;
double pTjetMin = 10.;
// Exclude neutrinos (and other invisible) from study.
int nSel = 1;
// Range and granularity of CellJet jet finder.
int nEta = 80;
int nPhi = 64;

// Set up SlowJet jet finder, with anti-kT clustering
// and pion mass assumed for non-photons…
SlowJet slowJet( -1, radius, pTjetMin, etaMax, nSel, 1);

// Set up CellJet jet finder.
CellJet cellJet( etaMax, nEta, nPhi, nSel);

// Histograms. Note similarity in names, even when the two jet finders
// do not calculate identically the same property (pT vs. ET, y vs. eta).
Hist nJetsS(“number of jets, SlowJet”, 50, -0.5, 49.5);
Hist nJetsC(“number of jets, CellJet”, 50, -0.5, 49.5);
Hist nJetsD(“number of jets, CellJet - SlowJet”, 45, -22.5, 22.5);
Hist eTjetsS(“pT for jets, SlowJet”, 100, 0., 500.);
Hist eTjetsC(“eT for jets, CellJet”, 100, 0., 500.);
Hist etaJetsS(“y for jets, SlowJet”, 100, -5., 5.);
Hist etaJetsC(“eta for jets, CellJet”, 100, -5., 5.);
Hist phiJetsS(“phi for jets, SlowJwt”, 100, -M_PI, M_PI);
Hist phiJetsC(“phi for jets, CellJet”, 100, -M_PI, M_PI);
Hist distJetsS(“R distance between jets, SlowJet”, 100, 0., 10.);
Hist distJetsC(“R distance between jets, CellJet”, 100, 0., 10.);
Hist eTdiffS(“pT difference, SlowJet”, 100, -100., 400.);
//Hist eTdiffC(“eT difference, CellJet”, 100, -100., 400.);

// Begin event loop. Generate event. Skip if error.
for (int iEvent = 0; iEvent < nEvent; ++iEvent) {
if (!pythia.next()) continue;

// Analyze Slowet jet properties. List first few.
slowJet. analyze( pythia.event );
if (iEvent < nListJets) slowJet.list();

// Fill SlowJet inclusive jet distributions.
nJetsS.fill( slowJet.sizeJet() );
for (int i = 0; i < slowJet.sizeJet(); ++i) {
  eTjetsS.fill( slowJet.pT(i) );
  etaJetsS.fill( slowJet.y(i) );
  phiJetsS.fill( slowJet.phi(i) );
}

// Fill SlowJet distance between jets.
for (int i = 0; i < slowJet.sizeJet() - 1; ++i)
for (int j = i +1; j < slowJet.sizeJet(); ++j) {
  double dEta = slowJet.y(i) - slowJet.y(j);
  double dPhi = abs( slowJet.phi(i) - slowJet.phi(j) );
  if (dPhi > M_PI) dPhi = 2. * M_PI - dPhi;
  double dR = sqrt( pow2(dEta) + pow2(dPhi) );
  distJetsS.fill( dR );
}

// Fill SlowJet pT-difference between jets (to check ordering of list).
for (int i = 1; i < slowJet.sizeJet(); ++i)
  eTdiffS.fill( slowJet.pT(i-1) - slowJet.pT(i) );

// Analyze CellJet jet properties. List first few.
cellJet. analyze( pythia.event, pTjetMin, radius );
if (iEvent < nListJets) cellJet.list();

// Fill CellJet inclusive jet distributions.
    nJetsC.fill( cellJet.size() );

for (int i = 0; i < cellJet.size(); ++i) {
  eTjetsC.fill( cellJet.eT(i) );
  etaJetsC.fill( cellJet.etaWeighted(i) );
  phiJetsC.fill( cellJet.phiWeighted(i) );

}

// Fill CellJet distance between jets.
for (int i = 0; i < cellJet.size() - 1; ++i)
for (int j = i +1; j < cellJet.size(); ++j) {
 double dEta = cellJet.etaWeighted(i)
   - cellJet.etaWeighted(j);
  double dPhi = abs( cellJet.phiWeighted(i)
    - cellJet.phiWeighted(j) );
  if (dPhi > M_PI) dPhi = 2. * M_PI - dPhi;
  double dR = sqrt( pow2(dEta) + pow2(dPhi) );
  distJetsC.fill( dR );
}

// Fill CellJet ET-difference between jets (to check ordering of list).
for (int i = 1; i < cellJet.size(); ++i)
 hist1->Fill( cellJet.eT(i-1) - cellJet.eT(i) );

// Compare number of jets for the two finders.
nJetsD.fill( cellJet.size() - slowJet.sizeJet() );

// End of event loop. Statistics. Histograms.
}
pythia.stat();
cout << nJetsS << nJetsC<< eTjetsC<< eTjetsS
<< etaJetsS << etaJetsC << phiJetsS << phiJetsC
<< distJetsS << distJetsC << eTdiffS;
// Show histogram. Possibility to close it.
//eTdiffC -> Draw();
std::cout << “\nDouble click on the histogram window to quit.\n”;
gPad->WaitPrimitive();

// Save histogram on file and close file.
// -> Write();
//delete outFile;
// Done.
return 0;
}[/code]
i am getting the following error:
Double click on the histogram window to quit.

*** Break *** segmentation violation

===========================================================
There was a crash (#6 0xb7248e1b in SigHandler(ESignals) () from /home/amandeep/root/lib/libCore.so).
This is the entire stack trace of all threads:

#0 0xb77b3428 in __kernel_vsyscall ()
#1 0xb657e683 in __waitpid_nocancel () at …/sysdeps/unix/syscall-template.S:81
#2 0xb6508f25 in do_system (line=0x9aa3850 “/home/amandeep/root/etc/gdb-backtrace.sh 6331 1>&2”) at …/sysdeps/posix/system.c:148
#3 0xb7242f1b in TUnixSystem::Exec(char const*) () from /home/amandeep/root/lib/libCore.so
#4 0xb7246c22 in TUnixSystem::StackTrace() () from /home/amandeep/root/lib/libCore.so
#5 0xb7248ce7 in TUnixSystem::DispatchSignals(ESignals) () from /home/amandeep/root/lib/libCore.so
#6 0xb7248e1b in SigHandler(ESignals) () from /home/amandeep/root/lib/libCore.so
#7 0xb7241df2 in sighandler(int) () from /home/amandeep/root/lib/libCore.so
#8
#9 0x080b0ee2 in main ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#9 0x080b0ee2 in main ()

Hi,

at the moment it’s early to say it’s ROOT fault. As gdb says, this is an error which occurred in your main function. You can compile the executable with the “-g” option to see more clearly at what line the issue happens.

D

Hi,
in your example the line:

is commented out. So there is never a canvas drawn hence gPad == NULL.
In fact there is no pointer “eTdiffC” you probably want:

At least for me that does not crash.

Otto