Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6588963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:06:49+00:00 2026-05-25T17:06:49+00:00

This is part of a macro I am writing in the ROOT framework using

  • 0

This is part of a macro I am writing in the ROOT framework using C++ and some predefined classes. I get a floating point exception upon including the lines marked below (starting with minv = ...). What is the reason for this error?

Double_t ppx[3000],ppy[3000],ppz[3000],pE[3000];
Double_t m = 0.000511;
Double_t minv,epx,epy,epz,eE;
for(Int_t n = 0; n < nEvents; n++) {
  inTree->GetEntry(n);

  Int_t nTracks = trackArray->GetEntries();
  htrack->Fill(nTracks);
  for(Int_t i = 0; i < nTracks; i++) {
    Track* trackData = (Track*)trackArray->At(i);
    if(trackData->fCharge ==1)
    {
      ppx[i] = (trackData->fPt) * TMath::Cos(trackData->fPhi);
      ppy[i] = (trackData->fPt) * TMath::Sin(trackData->fPhi);
      ppz[i] = (trackData->fPt) * sinh(trackData->fEta);
      pE[i] = m * m  - ppx[i] * ppx[i] - ppy[i] * ppy[i] - ppz[i] * ppz[i];
    }
    hPt->Fill(trackData->fPt);
  }
  for(Int_t i = 0; i < nTracks; i++) {
    Track* trackData = (Track*)trackArray->At(i);
    if(trackData->fCharge == -1)

      for (Int_t k=0;k<nTracks;k++){
        epx = (trackData->fPt) * TMath::Cos(trackData->fPhi);
        epy = (trackData->fPt) * TMath::Sin(trackData->fPhi);
        epz = (trackData->fPt) * sinh(trackData->fEta);
        eE = m*m  - epx *epx - epy * epy - epz * epz;
        // the following two lines cause the exception:
        minv = ((eE +pE[k]) * (eE + pE[k])) - ((epx + ppx[k]) * (epx + ppx[k])) - ((epy + ppy[k]) * (epy + ppy[k])) - ((epz + ppz[k]) * (epz + ppz[k])    );
        invm->Fill(minv);
      }
  }
}

nEventsProcessed++;
}

PS: I know this is not very efficient coding, I am a beginner.

I printed out the values of minv. Here is a small sample indicative of the output

-0.225634
-0.657662
-0.225634
1.53201
-0.225634
nan
-0.630927
-0.225634
-0.225634
-0.225634
-0.225634
-0.228794
-0.225634
-0.7196
-0.225634
-0.225634
-0.520265
-0.228796
0.608326
-0.225634
-0.225634
-0.225634
-0.733564
2.74301
-0.763932
-0.225634
-0.225634
nan
-0.228643
-0.225634
-0.225634
-0.225634
-0.584549

Addition: The nan’s are very strange. The numbers in their vicinity look normal and this is not a function that blows up, so am I using into junk values of the array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:06:49+00:00Added an answer on May 25, 2026 at 5:06 pm

    In the first loop over all tracks, you only fill the arrays if the track charge is positive. In the second loop, you access the arrays no matter whether the charge of the k-th track is positive.

    If you want to fill minv (I guess the invariant mass) only for opposite-charged tracks, remove the first if that checks for a positive charge and change the last loop to:

    for (Int_t i=0; i<nTracks; i++) {
        Track* trackData = (Track*)trackArray->At(i);
        for (Int_t k=0; k<nTracks; k++){
            Track* trackData2 = (Track*)trackArray->At(k);
            if (trackData->fCharge == trackData2->fCharge)
                continue;
    
            // calculate minv here
            invm->Fill(minv);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that this part of my code is where the exception occurs: c
The code we're using is straightforward in this part of the search query: myCriteria.Add(
I’m using the following flags, but still I m not able to get this
I'm writing some template classes for parseing some text data files, and as such
I'm for a solution to part of a macro I'm writing that will hide
I've got this workbook I've been trying to get to work via macro code.
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
I have been putting off developing this part of my app for sometime purely
I am trying to learn and writting this part of code. while testing few
I just started learning C but I don't understand this part of the code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.