I get an error ; break segmentation. Why ? It doesn’t work !
Cheers
EventData.h script is
[code]#include
class Particle {
public:
Particle() {memset(fTags, 0, sizeof(fTags)); }
double fPosX,fPosY,fPosZ; // particle position nearest to interaction point
double fMomentum; // particle momentum
double fMomentumPhi; // particle direction (phi)
double fMomentumEta; // particle direction (eta)
Long64_t fTags[128]; // particle tags
};
class EventData {
public:
std::vector fParticles; // particles of the event
int fEventSize; // size (in bytes) of the event
void SetSize() {
fEventSize = sizeof(EventData) + fParticles.size() * sizeof(Particle);
}
void Clear() {
fParticles.clear();
}
void AddParticle(const Particle& p) { fParticles.push_back§; }
//ClassDef(EventData,1); // Data for an event
};
#ifdef MAKECINT
#pragma link C++ class Particle+;
#pragma link C++ class EventData+;
#endif[/code]
Macro script is
[code]// Prefer compiled:
#include “TTree.h”
#include “TFile.h”
#include “TRandom.h”
#include “TMath.h”
#include
#include “EventData.h”
void createTree(ULong64_t numEvents = 200) {
TFile* f = new TFile(“eventdata.root”, “RECREATE”);
TTree* tree = new TTree(“EventTree”, “Tutorial tree”);
EventData* event = new EventData();
tree->Branch(“event”, &event);
Particle p;
for (ULong64_t i = 0; i < numEvents; ++i) {
event->Clear();
// generate event information
int nParticles = 10 * gRandom->Exp(10.);
// for every particle in the event generate the particle data
for (int ip = 0; ip < nParticles; ++ip) {
do {
p.fPosX = gRandom->Gaus(gRandom->PoissonD(0.1), 1.)
+ gRandom->BreitWigner(0.1, 0.1);;
} while (fabs(p.fPosX) > 10.);
p.fPosY = gRandom->Gaus(gRandom->PoissonD(0.01), .7);
p.fPosZ = gRandom->Gaus(gRandom->PoissonD(10), 19.);
p.fMomentum = gRandom->Exp(12);
p.fMomentumPhi = gRandom->Uniform(2*TMath::Pi());
do {
p.fMomentumEta = gRandom->BreitWigner(0.01, 10.);
} while (fabs(p.fMomentumEta) > 12.);
event->AddParticle(p);
}
event->SetSize();
tree->Fill();
if (i % (numEvents/50) == 0) {
printf("*");
fflush(stdout);
}
}
printf("\n");
tree->Write();
delete f;
}[/code]