strange macro behaviour

T Auger (thauger@phns27.saclay.cea.fr)
Tue, 15 Sep 1998 18:48:16 +0200


Hi Rooters,
we observed a strange behaviour in one of our macro using CLHEP. The
macro processed once failed at the byte-compilation and gave a break
seg fault. Then just hiting return made it work! Could someone give me
a hint on what we are doing wrong or is this a bug?
(the macro follows the prints).
cheers,
Thierry.

root [0] .x phi.C
Error: non class,struct,union object $proton_out used with . or ->
FILE:/home/crash17/marchand/root/macro/./phi.C LINE:83
alors 0
nmatch 2
nmatch 0
nmatch 0
nmatch 1
proton 0.000000
nmatch 1
proton 0.000000
nmatch 1
proton 0.000000
nmatch 1
proton 0.000000
nmatch 1
proton 0.000000
nmatch 2
nmatch 0
nmatch 1
proton 0.000000

*** Break *** segmentation violation

alors 0
nmatch 2
nmatch 0
nmatch 0
nmatch 1
proton 1.008929
nmatch 1
proton 0.984921
nmatch 1
proton 1.515583
nmatch 1
proton 1.088752
nmatch 1
proton 1.352676
nmatch 2
nmatch 0
nmatch 1
proton 1.114028
nmatch 0
nmatch 1
proton 1.449203
nmatch 1
proton 1.760664
nmatch 0
nmatch 1
proton 1.586831
nmatch 1
proton 1.116349
nmatch 1
proton 1.130289
nmatch 4
nmatch 1
proton 1.148586
nmatch 0
nmatch 1
proton 0.969677
nmatch 1
proton 1.014140

{
//
// macro pour lire un tree et looper sur les particules chargees
// histogramme la masse apres notre pid.
//
gROOT->Reset();
TFile f("/home/crash17/marchand/root/macro/g6-opp.root");

TTree *T = (TTree*)gDirectory->Get("T");
//Declaration of leaves types
TClasEvent *event;
class HepLorentzVector;

TH1F histo1("histo1","mass",100,-0.5,1.5);
TH1F histo2("histo2","mass kaon m",150,-1.,1.5);

//Set branch addresses
T->SetBranchAddress("event",&event);
Int_t nentries = T->GetEntries();
nentries = 1000000;
TClonesArray *tab;
Int_t nbytes = 0;
TTrack *track;
TTrack *tproton;
TTrack *tkaonp;
Int_t npro = 0;
Int_t nkp = 0;
Int_t indkp[10] = {0,0,0,0,0,0,0,0,0,0};
Int_t indpro[10] = {0,0,0,0,0,0,0,0,0,0};
Int_t iseckp[10] = {0,0,0,0,0,0,0,0,0,0};
Int_t isecpro[10] = {0,0,0,0,0,0,0,0,0,0};


for (Int_t i=0; i<nentries;i++) {
nbytes += T->GetEvent(i);

tab = event->GetDetectedTracks();
Float_t egamma = event->GetE();

HepLorentzVector photon(0,0,egamma,egamma);
HepLorentzVector proton_in(0,0,0,0.93827);
npro = 0;
nkp = 0;
for(Int_t j=0;j<=tab->GetLast();j++) {
track = (TTrack*)tab->At(j);

// recuperer les protons et K+ en gardant leur index
if(track->Id()==2212) {
indpro[npro] = j;
isecpro[npro] = track->GetSectorId();
npro++;
}
if(track->Id()==321) {
indkp[nkp] = j;
iseckp[nkp] = track->GetSectorId();
nkp++;
}
histo1->Fill(track->GetMass());
}

// printf("nproton %d nkaonp %d\n",npro,nkp);

if(nkp*npro>=1) {

// test sur secteurs opposes p-K+
Int_t nmatch = 0;
for(Int_t k=0;k<npro;k++) {
for(Int_t l=0;l<nkp;l++) {
if(fabs(isecpro[k]-iseckp[l])==3) {
Int_t indprs=indpro[k];
Int_t indkps=indkp[l];
nmatch++;
}
}
}

if(nmatch==1) printf("nmatch %d\n",nmatch);
if(nmatch==1){
tproton = (TTrack*)tab->At(indprs);
// printf("%f %f %f %f\n",tproton->Px(),tproton->Py(),tproton->Pz(),tproton->E_id());
HepLorentzVector proton_out((Double_t)tproton->Px(),
(Double_t)tproton->Py(),
(Double_t)tproton->Pz(),
(Double_t)tproton->E_id());
tkaonp = (TTrack*)tab->At(indkps);
// printf(" proton %f\n",proton_out.e());
HepLorentzVector kaonp(tkaonp->Px(),tkaonp->Py(),tkaonp->Pz(),tkaonp->E_id());
kaonm=photon+proton_in-proton_out-kaonp;
histo2->Fill(kaonm.mag2());
}
}

event->Clear();
if(i%5000 == 0) printf("alors %d\n",i);
}

}