Hi,
first of all best wishes for your holidays.
My program has to simulate the generation of different types of particles. The main program is called Mainmodule and it needs of ParticleType.c+, ResonanceType.c+, Particle.c+ .
When I execute my macro Mainmodule() it gives me Segmentation Violation Error.
I would to know what could be the problem, where I can find it. I think it would be helpful to have the codes of ParticleType, ResonanceType and Particle.
I specify that .L ParticleType, .L ResonanceType, .L Particle and .L Mainmodule works with no error!
===========================================================
There was a crash (kSigSegmentationViolation).
This is the entire stack trace of all threads:
===========================================================
#0 0xb775ece5 in __kernel_vsyscall ()
#1 0xb70d3123 in __waitpid_nocancel () at ../sysdeps/unix/syscall-template.S:84
#2 0xb705d9d6 in do_system (line=0x90b1e38 "/home/nirvana/Immagini/ROOT/etc/gdb-backtrace.sh 6762 1>&2") at ../sysdeps/posix/system.c:148
#3 0xb76180e2 in TUnixSystem::Exec (shellcmd=<optimized out>, this=<optimized out>) at /home/nirvana/Scaricati/root-6.10.02/core/unix/src/TUnixSystem.cxx:2118
#4 TUnixSystem::StackTrace (this=0x8417698) at /home/nirvana/Scaricati/root-6.10.02/core/unix/src/TUnixSystem.cxx:2412
#5 0xb761aa2b in TUnixSystem::DispatchSignals (this=0x8417698, sig=kSigSegmentationViolation) at /home/nirvana/Scaricati/root-6.10.02/core/unix/src/TUnixSystem.cxx:3643
#6 0xb761ab88 in SigHandler (sig=kSigSegmentationViolation) at /home/nirvana/Scaricati/root-6.10.02/core/unix/src/TUnixSystem.cxx:408
#7 0xb76141b3 in sighandler (sig=11) at /home/nirvana/Scaricati/root-6.10.02/core/unix/src/TUnixSystem.cxx:3620
#8 0xb760cfc6 in textinput::TerminalConfigUnix::HandleSignal (this=0xb772c280 <textinput::TerminalConfigUnix::Get()::s>, signum=11) at /home/nirvana/Scaricati/root-6.10.02/core/textinput/src/textinput/TerminalConfigUnix.cpp:100
#9 0xb760cff1 in (anonymous namespace)::TerminalConfigUnix__handleSignal (signum=11) at /home/nirvana/Scaricati/root-6.10.02/core/textinput/src/textinput/TerminalConfigUnix.cpp:36
#10 <signal handler called>
#11 0xb737f5a4 in ParticleType::GetName() const () from /home/nirvana/Immagini/ROOT/macros/ParticleType_c.so
#12 0xb737518e in Particle::FindParticle(char const*) () from /home/nirvana/Immagini/ROOT/macros/Particle_c.so
#13 0xb7375213 in Particle::AddParticleType(char const*, double, int, double) () from /home/nirvana/Immagini/ROOT/macros/Particle_c.so
#14 0xb736eb71 in Mainmodule() () from /home/nirvana/Immagini/ROOT/macros/Mainmodule_C.so
#15 0xa515c083 in ?? ()
#16 0xb42b3d44 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /home/nirvana/Immagini/ROOT/lib/libCling.so
#17 0xb42b4ee6 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned int) () from /home/nirvana/Immagini/ROOT/lib/libCling.so
#18 0xb42b511b in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /home/nirvana/Immagini/ROOT/lib/libCling.so
#19 0xb433ded3 in cling::MetaProcessor::process(char const*, cling::Interpreter::CompilationResult&, cling::Value*, bool) () from /home/nirvana/Immagini/ROOT/lib/libCling.so
#20 0xb42605a0 in HandleInterpreterException (metaProcessor=<optimized out>, input_line=<optimized out>, compRes=
0xbfe7d3b0: (unknown: 144375800), result=0xbfe7d3b4) at /home/nirvana/Scaricati/root-6.10.02/core/metacling/src/TCling.cxx:1887
#21 0xb42733fb in TCling::ProcessLine (this=0x8451a08, line=0x9013740 "#line 1 \"ROOT_prompt_6\"\nMainmodule()", error=0xbfe7d6b8) at /home/nirvana/Scaricati/root-6.10.02/core/metacling/src/TCling.cxx:2050
#22 0xb7526a68 in TApplication::ProcessLine (this=0x8448018, line=<optimized out>, sync=false, err=0xbfe7d6b8) at /home/nirvana/Scaricati/root-6.10.02/core/base/src/TApplication.cxx:1001
#23 0xb773eb1c in TRint::ProcessLineNr (this=0x8448018, filestem=0xb77519a3 "ROOT_prompt_", line=0x89b28d0 "Mainmodule()", error=0xbfe7d6b8) at /home/nirvana/Scaricati/root-6.10.02/core/rint/src/TRint.cxx:741
#24 0xb773ee6d in TRint::HandleTermInput (this=0x8448018) at /home/nirvana/Scaricati/root-6.10.02/core/rint/src/TRint.cxx:602
#25 0xb773e31e in TTermInputHandler::Notify (this=0x89af960) at /home/nirvana/Scaricati/root-6.10.02/core/rint/src/TRint.cxx:131
#26 0xb7740e90 in TTermInputHandler::ReadNotify (this=0x89af960) at /home/nirvana/Scaricati/root-6.10.02/core/rint/src/TRint.cxx:123
#27 0xb7619db5 in TUnixSystem::CheckDescriptors (this=0x8417698) at /home/nirvana/Scaricati/root-6.10.02/core/unix/src/TUnixSystem.cxx:1321
#28 0xb761b42c in TUnixSystem::DispatchOneEvent (this=0x8417698, pendingOnly=false) at /home/nirvana/Scaricati/root-6.10.02/core/unix/src/TUnixSystem.cxx:1076
#29 0xb7500998 in TSystem::InnerLoop (this=0x8417698) at /home/nirvana/Scaricati/root-6.10.02/core/base/src/TSystem.cxx:410
#30 0xb74fedad in TSystem::Run (this=0x8417698) at /home/nirvana/Scaricati/root-6.10.02/core/base/src/TSystem.cxx:360
#31 0xb752317e in TApplication::Run (this=0x8448018, retrn=false) at /home/nirvana/Scaricati/root-6.10.02/core/base/src/TApplication.cxx:1153
#32 0xb7740742 in TRint::Run (this=0x8448018, retrn=false) at /home/nirvana/Scaricati/root-6.10.02/core/rint/src/TRint.cxx:455
#33 0x08048939 in main (argc=1, argv=0xbfe7fb14) at /home/nirvana/Scaricati/root-6.10.02/main/src/rmain.cxx:30
These are the other codes:
ParticleType.h
#ifndef PARTICLETYPE_H
#define PARTICLETYPE_H
class ParticleType {
public:
ParticleType (const char* fName_, double fMass_, int fCharge_);
const char* GetName () const;
double GetMass ()const ;
int GetCharge ()const;
double GetWidth () const;
void Print();
protected:
private:
const char* fName;
const double fMass;
const int fCharge;
};
ParticleType.c+
#include <iostream>
#include "ParticleType.h"
using namespace std;
ParticleType::ParticleType(const char* fName_, double fMass_, int fCharge_) : fName (fName_), fMass (fMass_), fCharge (fCharge_) {}
const char* ParticleType::GetName() const {return fName;}
double ParticleType::GetMass() const {return fMass;}
int ParticleType::GetCharge() const {return fCharge;}
double ParticleType::GetWidth () const {return 0 ;}
void ParticleType::Print() {cout<<fName<<'\n'<<fMass<<'\n'<<fCharge<<'\n';}
ResonanceType.h
#include "ParticleType.h"
#ifndef RESONANCETYPE_H
#define RESONANCETYPE_H
class ResonanceType : public ParticleType {
public:
ResonanceType (const char* fName_, double fMass_, int fCharge_, double fWidth_);
double GetWidth ();
void Print ();
protected:
private:
const double fWidth;
};
#endif
ResonanceType.c+
#include <iostream>
#include "ParticleType.h"
#include "ResonanceType.h"
using namespace std;
ResonanceType::ResonanceType (const char* fName_, double fMass_, int fCharge_, double fWidth_) : ParticleType(fName_, fMass_, fCharge_), fWidth (fWidth_) {}
void ResonanceType::Print () {ParticleType::Print(); cout<<fWidth<<'\n';}
double ResonanceType::GetWidth() {return fWidth;}
Particle.h
#include "ParticleType.h"
#include "ResonanceType.h"
#include <cmath>
#ifndef PARTICLE_H
#define PARTICLE_H
//far ereditare non :: gli attributi massa charge e width
class Particle {
public:
Particle();
Particle(const char *fName_, double fPx_, double fPy_, double fPz_);
double Energy() const;
double Pulse = pow(1/2, pow(2,fPx)+pow(2,fPy)+pow(2,fPz));
int GetFIndex();
static void AddParticleType (const char *fName_, double fMass_, int fCharge_, double fWidth_);
void SetFIndex (int a);
static void PrintArray ();
void PrintOther ();
double GetfPx () const;
double GetfPy () const;
double GetfPz () const;
double GetNewMass () const;
double GetEnergy () const;
double InvMass (Particle &p);
void SetP(double px, double py, double pz);
int Decay2Body(Particle &dau1, Particle &dau2) const;
protected:
private:
static ParticleType* fParticleType [10];
static const int fMaxNumParticleType = 10;
static int fNParticleType;
int fIndex;
double fPx = 0;
double fPy = 0;
double fPz = 0;
static int FindParticle(const char *fName_);
void Boost (double bx, double by, double bz);
int a;
};
#endif
Particle.c+
#include <iostream>
#include "ResonanceType.h"
#include "ParticleType.h"
#include "Particle.h"
#include <cmath>
#include <cstdlib>
using namespace std;
int Particle::fNParticleType = 10;
ParticleType* Particle:: fParticleType[] = {0x0};
Particle::Particle(){}
Particle::Particle (const char*fName_, double fPx_, double fPy_, double fPz_) : fPx(fPx_), fPy(fPy_), fPz(fPz_) {}
double Particle::GetfPx () const
{
return fPx;
}
double Particle::GetfPy () const
{
return fPy;
}
double Particle::GetfPz () const
{
return fPz;
}
double Particle::GetNewMass () const
{
return fParticleType[fIndex]->GetMass();
}
void Particle::SetFIndex (int a)
{
int FIndex=a;
}
int Particle::GetFIndex ()
{
return fIndex;
}
//void Particle::SetFIndex (char*fName) { //!
//;}
void Particle::SetP(double px, double py, double pz)
{
double fPx = px;
double fPy = py;
double fPz = pz;
}
int Particle::FindParticle (const char *fName_)
{
for (int i=0; i<fNParticleType; i++)
{
if (fName_ == fParticleType[i]->GetName())
{
return i;
}
else
{
cout<<"Non c'è corrispondenza"<<'\n';
}
}
return -1;
}
void Particle::AddParticleType (const char *fName_, double fMass_, int fCharge_, double fWidth_)
{
for (int i=0; i<fNParticleType; i++)
{
int b = FindParticle(fName_);
if (b == -1)
{
if (fWidth_ == 0)
{
fParticleType[i]=new ParticleType (fName_, fMass_, fCharge_);
}
else
{
fParticleType[i]=new ResonanceType (fName_, fMass_, fCharge_, fWidth_);
}
}
}
}
void Particle::PrintArray()
{
for(int i=0; i<fNParticleType; i++)
{
fParticleType[i]->Print();
}
}
void Particle::PrintOther ()
{
cout<<"Name"<<fParticleType[fIndex]->GetName()<<'\n'<<"fPx"<<fPx<<'\n'<<"fPy"<<fPy<<'\n'<<"fPz"<<fPz;
}
double Particle::Energy() const
{
double Pulse=pow(GetfPx(), 2)+pow(GetfPy(), 2)+pow(GetfPz(), 2);
double Masstwo= GetNewMass()*GetNewMass();
double Energy=sqrt(Masstwo+Pulse);
return Energy;
}
double Particle::InvMass(Particle &p)
{
double InvMass=(pow(pow(Energy()+p.Energy(),2)-pow(GetfPx()+p.GetfPx(),2)+pow(GetfPy()+p.GetfPy(),2)+pow(GetfPz()+p.GetfPz(),2), 1/2));
return InvMass;
}
int Particle::Decay2Body(Particle &dau1, Particle &dau2) const {
if(GetNewMass() == 0.0){
printf("Decayment cannot be preformed if mass is zero\n");
return 1;
}
double massMot = GetNewMass();
double massDau1 = dau1.GetNewMass();
double massDau2 = dau2.GetNewMass();
if(fIndex > -1){ // add width effect
// gaussian random numbers
float x1, x2, w, y1, y2;
double invnum = 1./RAND_MAX;
do {
x1 = 2.0 * rand()*invnum - 1.0;
x2 = 2.0 * rand()*invnum - 1.0;
w = x1 * x1 + x2 * x2;
} while ( w >= 1.0 );
w = sqrt( (-2.0 * log( w ) ) / w );
y1 = x1 * w;
y2 = x2 * w;
massMot += fParticleType[fIndex]->GetWidth() * y1;
}
if(massMot < massDau1 + massDau2){
printf("Decayment cannot be preformed because mass is too low in this channel\n");
return 2;
}
double pout = sqrt((massMot*massMot - (massDau1+massDau2)*(massDau1+massDau2))*(massMot*massMot - (massDau1-massDau2)*(massDau1-massDau2)))/massMot*0.5;
double norm = 2*M_PI/RAND_MAX;
double phi = rand()*norm;
double theta = rand()*norm*0.5 - M_PI/2.;
dau1.SetP(pout*sin(theta)*cos(phi),pout*sin(theta)*sin(phi),pout*cos(theta));
dau2.SetP(-pout*sin(theta)*cos(phi),-pout*sin(theta)*sin(phi),-pout*cos(theta));
double energy = sqrt(fPx*fPx + fPy*fPy + fPz*fPz + massMot*massMot);
double bx = fPx/energy;
double by = fPy/energy;
double bz = fPz/energy;
dau1.Boost(bx,by,bz);
dau2.Boost(bx,by,bz);
return 0;
}
void Particle::Boost(double bx, double by, double bz)
{
double energy = GetEnergy();
//Boost this Lorentz vector
double b2 = bx*bx + by*by + bz*bz;
double gamma = 1.0 / sqrt(1.0 - b2);
double bp = bx*fPx + by*fPy + bz*fPz;
double gamma2 = b2 > 0 ? (gamma - 1.0)/b2 : 0.0;
fPx += gamma2*bp*bx + gamma*bx*energy;
fPy += gamma2*bp*by + gamma*by*energy;
fPz += gamma2*bp*bz + gamma*bz*energy;
}
Mainmodule.c+
#include <iostream>
#include "ParticleType.h"
#include "ResonanceType.h"
#include "Particle.h"
#include "cmath"
#include "TMath.h"
#include "TRandom.h"
#include "TH1D.h"
#include "TFile.h"
#include "TCanvas.h"
using namespace std;
int Mainmodule()
{
double Px, Py, Pz;
double Energia, Impulso_Trasverso, Impulso;
double MassaInv;
Particle particella [110]; //100 particelle per volta, sistema e riempie, poi lo fa per 10^5 volte
Particle::AddParticleType ("pioni", 0.13957, 1, 0);
Particle::AddParticleType ("Kaoni", 0.49367, 1, 0);
Particle::AddParticleType ("protoni", 0.93827, 1, 0);
Particle::AddParticleType ("K*", 0.89166, 0, 0.050);
Particle::AddParticleType ("pioni", 0.13957, -1, 0);
Particle::AddParticleType ("Kaoni", 0.49367, -1, 0);
Particle::AddParticleType ("protoni", 0.93827, -1, 0);
Double_t x = 0;
Double_t y = 0;
Double_t phi = 0;
Double_t theta = 0;
TFile *file=new TFile("Particelle.root", "RECREATE");
TH1D *HTypes=new TH1D ("HTypes", "Types", 7, 0, 110);
TH1D *HAzimuth=new TH1D ("HAzimuth", "Azimuth_Angle_Distribution", 100, 0, 2*TMath::Pi());
TH1D *HPolar=new TH1D ("HPolar", "Polar_Angle_Distribution", 100, 0, TMath::Pi());
TH1D *HPulse=new TH1D ("HPulse", "Pulse_Distribution", 100, 0, 1000);
TH1D *HTrasverso_Pulse=new TH1D ("HTrasverso_Pulse", "Trasverso_Pulse_Distribution", 100, 0, 1000);
TH1D *HEnergy=new TH1D ("HEnergy", "Energy_Distribution", 100, 0, 1000);
TH1D *HInvEverybody=new TH1D ("HInvEverybody", "InvMass_Everybody", 500, 0, 1000);
TH1D *HInvOpposite_Sign=new TH1D ("HInvOpposite_Sign", "InvMass_Opposite_Sign", 500, 0, 1000);
TH1D *HInvSame_Sign=new TH1D ("HInvSame_Sign", "InvMass_Same_Sign", 500, 0, 1000);
TH1D *HInvPione_concorde=new TH1D ("HInvPione_concorde", "InvMass_Pioneplus/Kaoneminus", 500, 0, 1000);
TH1D *HInvPione_discorde=new TH1D ("HInvPione_discorde", "InvMass_Pioneminus/Kaoneplus", 500, 0, 1000);
TH1D *HInvK=new TH1D ("HInvK", "InvMass_K*", 500, 0, 1000);
for (Int_t i=0; i<10; i++)
{
int n=0;
for (Int_t j=0; j<110; j++)
{
cout<<"asdasd"<<endl;
x=gRandom->Rndm();
y=gRandom->Rndm();
phi=gRandom->Uniform(0, 2*TMath::Pi());
theta=gRandom->Uniform(0, TMath::Pi());
Impulso=gRandom->Exp(1.0);
if (x<0.01)
{
if (y<0.50)
{
particella[j].SetFIndex(1);
}
}
if (x<0.10)
{
if (y<0.50) {particella[j].SetFIndex(2);}
else {particella[j].SetFIndex(3);}
}
if (x<0.20)
{if (y<0.50) {particella[j].SetFIndex(4);}
else {particella[j].SetFIndex(5);}}
if (x<1.00)
{if (y<0.50) {particella[j].SetFIndex(6);}
else {particella[j].SetFIndex(7);} }
HTypes->Fill(particella[j].GetFIndex()); //Rimepio Types
Px=Impulso*sin(theta)*cos(phi);
Py=Impulso*sin(theta)*sin(phi);
Pz=Impulso*cos(theta);
HAzimuth->Fill(phi);
//Rimepio Azimuth Angle
HPolar->Fill(theta);
//Rimpio Polar Angle
HPulse->Fill(Impulso);
// Rimepio Pulse
particella[j].SetP(Px,Py,Pz); //Impulso per ogni particella
Impulso_Trasverso = pow((pow(Px, 2)+pow(Py, 2)),1/2);
HTrasverso_Pulse->Fill(Impulso_Trasverso);
//Riempio Trasverso Pulse
Energia = particella[j].GetEnergy();
HEnergy->Fill(Energia);
//Rimepio Energy
double InvMass;
if (x<0.01)
{
particella[n].Decay2Body(particella[n+1], particella[n+2]);
MassaInv=particella[n+1].InvMass(particella[n+2]);
HInvK->Fill(MassaInv);
//Rimepio K*
n+=2;
if (x<0.005)
{
particella[100+n].SetFIndex(6);
particella[100+n+1].SetFIndex(5);
}
else
{
particella[100+n].SetFIndex(7);
particella[100+n+1].SetFIndex(4);
}
particella[j].Decay2Body(particella[100+n], particella[100+n+1]);
MassaInv=particella[100+n].InvMass(particella[100+n+1]);
HInvK->Fill(MassaInv);
}
}
for(Int_t k=0; k<110; k++)
{
for (Int_t h=0; h<110; h++)
{
MassaInv=particella[k].InvMass(particella[h]);
HInvEverybody->Fill(MassaInv);
//Rimepio Everybody
if( (particella[k].GetFIndex()==4 || particella[k].GetFIndex()==2 || particella[k].GetFIndex()==6) &&
(particella[h].GetFIndex()==4 || particella[h].GetFIndex()==2 || particella[h].GetFIndex()==6))
{
HInvSame_Sign->Fill(MassaInv);
}
if((particella[k].GetFIndex()==7 || particella[k].GetFIndex()==5 || particella[k].GetFIndex()==3) &&
(particella[h].GetFIndex()==7 || particella[h].GetFIndex()==5 || particella[h].GetFIndex()==3))
{
HInvSame_Sign->Fill(MassaInv);
}
//concorde
if((particella[k].GetFIndex()==4 || particella[k].GetFIndex()==2 || particella[k].GetFIndex()==6) &&
(particella[h].GetFIndex()==7 || particella[h].GetFIndex()==5 || particella[h].GetFIndex()==3))
{
HInvOpposite_Sign->Fill(MassaInv);
}
if((particella[k].GetFIndex()==7 || particella[k].GetFIndex()==5 || particella[k].GetFIndex()==3) &&
(particella[h].GetFIndex()==4 || particella[h].GetFIndex()==2 || particella[h].GetFIndex()==6))
{
HInvOpposite_Sign->Fill(MassaInv);
}
//discorde
if((particella[k].GetFIndex()==6) && (particella[h].GetFIndex()==4) || (particella[k].GetFIndex()==7) && (particella[h].GetFIndex()==5) || (particella[k].GetFIndex()==4) && (particella[h].GetFIndex()==6) || (particella[k].GetFIndex()==5) && (particella[h].GetFIndex()==7))
{
HInvPione_concorde->Fill(MassaInv);
}
//pionekaoneconcorde
if((particella[k].GetFIndex()==6) && (particella[h].GetFIndex()==5) || (particella[k].GetFIndex()==7) && (particella[h].GetFIndex()==4) || (particella[k].GetFIndex()==5) && (particella[h].GetFIndex()==6) || (particella[k].GetFIndex()==4) && (particella[h].GetFIndex()==7))
{
HInvPione_discorde->Fill(MassaInv);
}
//pionekaonediscorde
}
}
}
file->Write();
file->Close();
return 0;
}
Thanks very much.