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:

- Look for energy counts (second culomn) corresponding to b bin, b-1 bin and b+1 bin.
- Calculate the the counts corresponding to the b bin, minus the half sum of the counts corresponding to b-1 and b+1 bins
- 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:

epsiolon=(1923-(131+127)/2)/10^6=0.0018

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?

Thanks

efficiency.cpp (967 Bytes)

EnergySpectrumResults.txt (20.1 KB)

bin.txt (31 Bytes)