cosmicrays / hermes-examples

Examples for HERMES

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

problem with IC integrator in python

danielegaggero opened this issue · comments

Hi Andrej, I have a problem with the IC integrator, only in the python interface

I am reading leptons from a FITS file like this:
dragon2D_lepton = cosmicrays.Dragon2D(filename, [Electron])

and then, when I initialize the integrator like this:
integratorIC_cmb = InverseComptonIntegrator(dragon2D_lepton, CMB_photons, kn_crosssection)

I get the error

TypeError: init(): incompatible constructor arguments. The following argument types are supported:
1. pyhermes.InverseComptonIntegrator(arg0: hermes::cosmicrays::CosmicRayDensity, arg1: hermes::photonfields::PhotonField, arg2: hermes::interactions::DifferentialCrossSection)

Invoked with: <pyhermes.cosmicrays.Dragon2D object at 0x15ae3b9c70>, ('cmb', <pyhermes.photonfields.CMB object at 0x15ae3e36f8>), <pyhermes.interactions.KleinNishina object at 0x15ae3e32d0>

The problem is not present in the pi0 integrator.
Also, it is not present in the C++ version.

We noticed that, in the file "integrators.cpp" enclosed in the "python/" folder,

the pi0 integrator has this initialization:

py::init<
const std::vector<std::shared_ptrcosmicrays::CosmicRayDensity>,

while the IC does not have the vector initialization. Can it be part of the problem?
Thanks
Daniele

Hi Daniele,

thanks for the detailed report. It is true that the IC integrator, unlike Pi0, does not accept more than one CR object (provided as a python list), but it should accept one just fine (as you wrote). I tested the following python script and it runs:

https://github.com/cosmicrays/hermes-examples/blob/master/python/e3-ic-dragon2d.py

Hence, your example should also work if all input objects are the same. Can you compare your script with it?

Regarding passing many CR objects to IC - it can be accomplished by implementing additional "init" with vector (like in Pi0), but I remember vaguely that we said it is not required in case of leptons... If there is a case in which we put different CRs as a listo to the IC integrator, we'll easily extend it.

Yes, if that works it should suffices the scope.

Hi Andrej, the example works.

I found out the problem: I have to remember to set

name1, CMB_photons = ('cmb', photonfields.CMB())
name2, ISRF_photons = ('isrf', photonfields.ISRF())

before passing CMB_photons to the integrator, since ('cmb', photonfields.CMB()) returns a pair of objects

Hi Daniele,

yes, but that is a matter of taste. I did it to keep photon field names for later - to put them in file names for this specific example... but you can also just write without them:

CMB_photons = photonfields.CMB()
ISRF_photons = photonfields.ISRF()

sure, yes this is cleaner indeed :)