Efficiency macro

Hello, I need a macro to calculate the efficiency.
The macro must be read the energy values x (the number of energy values are not fixed. The depends on the specific materia) from bin.txt file. Then it must find these values in EnergySpectrumResults.txt file and calculate in which first culomn is the bin energy, second culomn the counts of energy and third culom the counts of emitted gammas.

To calculate the efficiency the macro must do:

  1. Look for energy counts (second culomn) corresponding to b bin, b-1 bin and b+1 bin.
  2. Calculate the the counts corresponding to the b bin, minus the half sum of the counts corresponding to b-1 and b+1 bins
  3. Divide the result of point 2 by the number of total simulated events (10^6 ).

Then the macro should calculate the BR (i.e. gamma counts/total simulated events)

Lastly the macro should write in a txt file (for each value in bin.txt):

bin - efficiency - BR

Example.: in the attached bin.txt file, the first level is 563. Looking at EnergySpectrumResults I’ve:

counts corresponding to 563 = 1923
counts corresponding to 562=131
counts corresponding to 564=127

then my efficiency is:


Moreover, the gamma counts corresponding to 563 is 83540, then my BR is 83564/10^6=0.083564

Then, the first line of the results.txt file must be

563 0.0018 0.083564

and so on for other values written in bin.txt (considering that each materia has a specific number of these values, for example the Pb-210 has only an energy for which calculate the efficiency).

Could someone help me to write the macro?

efficiency.cpp (967 Bytes)
EnergySpectrumResults.txt (20.1 KB)
bin.txt (31 Bytes)

you just needed to implement your logic to the data acquired. I think a major error cause you could have encountered is the use of the 2 dummy variables.

Below the working code.

efficiency.cpp (1.6 KB)


1 Like

Hi @dilicus thank you!
My specific problem was how to get the value from the data file to compare with the bin values from bin file!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.