Hi ROOTers,
I have this code:
{
gROOT->Reset();
gSystem->Load("/.../libPhysics.so");
TLorentzVector target(0.0, 0.0, 0.0, 0.938);
TLorentzVector beam(0.0, 0.0, .65, .65);
TLorentzVector W = beam + target;
Double_t masses[3] = { 0.938, 0.139, 0.139} ;
TGenPhaseSpace event;
event.SetDecay(W, 3, masses);
TH2F h2("h2","h2", 50,1.1,1.8, 50,1.1,1.8);
for (Int_t n=0;n<100000;n++) {
Double_t weight = event.Generate();
TLorentzVector *pProton = event.GetDecay(0);
TLorentzVector *pPip = event.GetDecay(1);
TLorentzVector *pPim = event.GetDecay(2);
TLorentzVector pPPip = *pProton + *pPip;
TLorentzVector pPPim = *pProton + *pPim;
h2.Fill(pPPip.M2() ,pPPim.M2() ,weight);
}
h2.SetXTitle("(m_{#pi^{+}}+m_{p})^{2}");
h2.SetYTitle("(m_{#pi^{-}}+m_{p})^{2}");
h2.Draw("cont");
}
I receve this output:
/home/lm17n000032/Scrivania/./PhaseSpace.C:9:16: error: redefinition of 'target'
TLorentzVector target(0.0, 0.0, 0.0, 0.938);
^
/home/lm17n000032/Scrivania/./PhaseSpace.C:9:16: note: previous definition is here
TLorentzVector target(0.0, 0.0, 0.0, 0.938);
I don’t understand why this code doesn’t work. Someone can help me please?
Target is definited only once.
_ROOT Version: 6.13/03
_Platform: Xubuntu 18.04
_Compiler: gcc version 7.3.0
Why happened this? Some times run sometimes not.
Axel
November 1, 2018, 7:31am
4
Indeed, ROOT6’s support of the combination of gROOT->Reset()
and unnamed macros is limited.
Please try this:
void PhaseSpace() {
TLorentzVector target(0.0, 0.0, 0.0, 0.938);
TLorentzVector beam(0.0, 0.0, .65, .65);
TLorentzVector W = beam + target;
Double_t masses[3] = { 0.938, 0.139, 0.139} ;
TGenPhaseSpace event;
event.SetDecay(W, 3, masses);
TH2F h2("h2","h2", 50,1.1,1.8, 50,1.1,1.8);
for (Int_t n=0;n<100000;n++) {
Double_t weight = event.Generate();
TLorentzVector *pProton = event.GetDecay(0);
TLorentzVector *pPip = event.GetDecay(1);
TLorentzVector *pPim = event.GetDecay(2);
TLorentzVector pPPip = *pProton + *pPip;
TLorentzVector pPPim = *pProton + *pPim;
h2.Fill(pPPip.M2() ,pPPim.M2() ,weight);
}
h2.SetXTitle("(m_{#pi^{+}}+m_{p})^{2}");
h2.SetYTitle("(m_{#pi^{-}}+m_{p})^{2}");
h2.DrawCopy("cont");
}
The error vanish,and the code work,but i dont understand why if I change .drawCOpy with draw the code generate a withe canvas.
Axel
November 1, 2018, 12:01pm
6
Because it’s a function-local histogram: the liftetime of h2
ends at the end of the function, and it will get removed from the canvas. By using DrawCopy()
, a copy gets drawn and stays on the canvas even when the lifetime of h2
ends.
Thank you so much. Now i understand the reason.
system
Closed
November 15, 2018, 1:36pm
8
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.