Fork me on GitHub

Opened 12 years ago

Closed 12 years ago

#49 closed Task (fixed)

math related suggestions

Reported by: Pavel Demin Owned by:
Priority: major Milestone:
Component: Delphes code Version:
Keywords: Cc:

Description (last modified by Pavel Demin)

Looking at the Delphes code, I've noticed a couple of things that could be improved:

  • Most of the underlying libraries operate with double precision numbers. However in Delphes, some variables are single precision. Should not we switch to double for all variables?
  • There are at least 13 calls to something like sqrt(pow(x,2), pow(y,2)). As most of them are inside loops, it would be better to replace them with hypot(x, y). Here is a command to find corresponding lines:
    grep -r "sqrt( *pow" trunk/* | grep c:
    
  • A strange pi constant is defined as 3.14159265358979312 in interface/D_Constants.h and in Utilities/Fastjet/plugins/CDFCones/interface/CalTower.hh. Normally, it should be 3.14159265358979323846. Moreover M_PI is already defined in math.h, pi and twopi are defined in Utilities/CLHEP/Units/PhysicalConstants.h. It would be better to use definitions from PhysicalConstants.h.

Change History (9)

comment:1 by Pavel Demin, 12 years ago

Description: modified (diff)

comment:2 by Pavel Demin, 12 years ago

Description: modified (diff)

comment:3 by Pavel Demin, 12 years ago

Description: modified (diff)

comment:4 by Pavel Demin, 12 years ago

I've run Delphes through a profiler and it found some hot spots:

  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 12.50      0.44     0.17   340235     0.00     0.00  RESOLution::BinEtaPhi(float, float, float&, float&)
  8.09      0.78     0.11  5497210     0.00     0.00  DeltaR(float, float, float, float)
  4.41      0.99     0.06  5497210     0.00     0.00  DeltaPhi(float, float)

BinEtaPhi and DeltaR are from src/SmearUtil.cc.

DeltaR is easy to optimize:

  • replace 2*pi with twopi in DeltaPhi
  • replace sqrt(pow... with hypot

Here are profiler results ater the modification:

  %   cumulative   self              self     total
 time   seconds   seconds    calls  ms/call  ms/call  name
 17.97      0.23     0.23   340235     0.00     0.00  RESOLution::BinEtaPhi(float, float, float&, float&)
  4.69      0.86     0.06  5497210     0.00     0.00  DeltaR(float, float, float, float)
  2.34      0.97     0.03  5497210     0.00     0.00  DeltaPhi(float, float)

I'll check if anything could be done with BinEtaPhi.

comment:5 by favereau, 12 years ago

Nice work !

I think binetaphi is very badly written. in:

https://server06.fynu.ucl.ac.be/projects/delphes/browser/trunk/src/SmearUtil.cc#L1536

We see that a loop is used to see in which phi region the particle falls. As all regions have equal phi size, i suggest we get it directly as:

int((pi+phi)/dphi)*dphi + dphi/2. 

or something like that.

I think we have to keep the eta loop as all cells can have different eta size.

comment:6 by Pavel Demin, 12 years ago

Looking at the at the calorimeter related code it occurred to me that we could use a 2D histogram TH2D with variable bin sizes. Then filling the towers will become:

towers.Fill(eta, phi, E)

Or at least we should use TMath::BinarySearch when filling calorimeter towers.

comment:7 by Pavel Demin, 12 years ago

Looks like it would be possible to eliminate 90% of DeltaR/DeltaPhi calls buy storing initial number of tracks associated with a tower. This could be done via PseudoJet::set_user_index method. Then number of tracks within a jet can be calculated as a sum of all _user_indexes from all jet's constituents.

comment:8 by favereau, 12 years ago

in the same binetaphi function, the last line computing the phi is wrong, it should be corrected in the rewrite of the function.

comment:9 by Pavel Demin, 12 years ago

Resolution: fixed
Status: newclosed

These issues are fixed in Delphes 3.

Note: See TracTickets for help on using tickets.