cosmicrays / hermes

HERMES is a publicly available computational framework for the line of sight integration over galactic radiative processes which creates sky maps in the HEALPix-compatibile format.
GNU General Public License v3.0
22 stars 9 forks source link

Gamma-ray absorption in dark matter annihilation (help required) #25

Closed TejasSatheesh closed 1 year ago

TejasSatheesh commented 2 years ago

Hi,

I was trying to modify the DarkMatterIntegrator to include the absorption of gamma rays as well. So, in the DarkMatterIntegrator.cpp (located in /src/integrators), I pasted the following from the PiZeroAbsorptionIntegrator.cpp

auto cmbPhotonField(const QEnergy &eps) { using hermes::units::expm1; const auto K = 1. / (M_PI M_PI) / pow<3>(h_planck_bar c_light); const auto cmbTemperature = 2.725_K; const auto kT = k_boltzmann cmbTemperature; return K pow<2>(eps) / expm1(eps / kT); }

QInverseLength DarkMatterIntegrator::absorptionCoefficient(const QEnergy &Egamma) const { auto integrand = [this, Egamma](double eps) { return staticcast(cmbPhotonField(QEnergy(eps)) * bwCrossSec->integratedOverTheta(Egamma, QEnergy(eps))); };

QEnergy epsMin = 1e-5_eV;
QEnergy epsMax = 5e-3_eV;

double abs_error = 0.0;  // disabled
double rel_error = 1.0e-4;
int key = GSL_INTEG_GAUSS51;  // GSL_INTEG_GAUSS15;
double result = 0;
double error = 0;

gsl_function_pp<decltype(integrand)> Fp(integrand);
gsl_function *F = static_cast<gsl_function *>(&Fp);

gsl_integration_workspace *w = gsl_integration_workspace_alloc(GSL_LIMIT);
gsl_integration_qag(F, static_cast<double>(epsMin), static_cast<double>(epsMax), abs_error, rel_error, GSL_LIMIT,
                    key, w, &result, &error);
gsl_integration_workspace_free(w);

return QInverseLength(result);

}

After pasting, I ran a python code with DarkMatterIntegrator to evaluate flux as a function of gamma -ray energy. The code ran without any errors. But I think I haven't re-compiled properly. To re-compile, should I run make -j in the hermes main directory? Can anyone tell me if what I have done is correct to include absorption for the DM annihilation to gamma-ray process? Also, it looks like what I have done only considers absorption from only the ambient CMB field and not the entire ISRF model (which includes even IR emmisions from dust, the star light as described by Vernetto and Lipari's model).

Any help in this regard would be really useful.

Thanks! Tejas Satheesh

TejasSatheesh commented 2 years ago

Hi,

I also pasted the following in /hermes/python/integrators.cpp in the DarkMatterIntegrator section, replacing the"PiZeroAbsorptionIntegrator" with "DarkMatterIntegrator" in the code.

declare_default_integrator_methods(pizeroabsintegrator); pizeroabsintegrator.def("absorptionCoefficient", &PiZeroAbsorptionIntegrator::absorptionCoefficient); pizeroabsintegrator.def( "integrateOverLOS", static_cast<QDiffIntensity (PiZeroAbsorptionIntegrator::*)(const QDirection &, const QEnergy &) const>( &PiZeroAbsorptionIntegrator::integrateOverLOS));

Can anyone tell if what I did is correct for including absorption in DarkMatterIntegrator? But, I think I am doing some mistake in recompiling. Can anyone please tell how do I re-compile to make the changes I made effective?

Thanks! Tejas Satheesh

adundovi commented 2 years ago

After pasting, I ran a python code with DarkMatterIntegrator to evaluate flux as a function of gamma -ray energy. The code ran without any errors. But I think I haven't re-compiled properly. To re-compile, should I run make -j in the hermes main directory? Can anyone tell me if what I have done is correct to include absorption for the DM annihilation to gamma-ray process? Also, it looks like what I have done only considers absorption from only the ambient CMB field and not the entire ISRF model (which includes even IR emmisions from dust, the star light as described by Vernetto and Lipari's model).

You should recompile the code inside the build directory, not the main one, i.e. cd build and make -j.

Regarding the new integrator implementation, I suggest that you make a new integrator starting as a copy of DarkMatterIntegrator, however, you should put new files both in include/hermes/integrators/ and in src/integrators/ and add them to include/hermes.h and CMakeLists.txt. Finally, if you want to use it through Python, in python/integrators.cpp you should also append new lines defining this integrator.

Maybe an easier way, for starting, would be to do this outside of the hermes main tree, coding this only in cpp, without header files and everything in a single file, like examples here.

TejasSatheesh commented 2 years ago

Okay, so I tried to create a new integrator named DarkMatterAbsorptionIntegrator, I added a new file in src/integrators and include/hermes/integrators/ and also added them to include/hermes.h and CMakeLists.txt . When I re-compiled, I got some errors like error: ‘const class hermes::DarkMatterAbsorptionIntegrator’ has no member named ‘spectralEmissivity’ error: no declaration matches ‘hermes::units::QGREmissivity hermes::DarkMatterAbsorptionIntegrator::spectralEmissivity(const Vector3QLength&, hermes::units::QEnergy) const’

Actually I am unable to attach the new files (the .cpp and .h files) here. I have emailed them through my github account email to the address <reply+AYZNRGXWJYD3INUUNM2QJ7GAPFQ2TEVBNHHERCGPKY@reply.github.com. Can you please look into them and suggest possible corrections to fix the errors? (Please let me know if you have received my email or not)

Thanks! Tejas

adundovi commented 2 years ago

You cannot attach files here through an e-mail. Try drag'n'drop using the GitHub web interface for replying to this issue. Also, your interface (the header file, .h) and the source file (.cpp) are not consistent -- you should have spectralEmissivity in both.

TejasSatheesh commented 2 years ago

Okay, actually I tried to drag and drop, but the file type is not supported. So, I have converted the source file and the header file into .txt format and attached here. I am a bit confused on how to add the spectralEmissivity (I am more used to python actually, not used to C++). Can you please tell in a bit more detail on how do I do that?

Thanks! Tejas absorption_source.txt absorptionIntegrator_header.txt

adundovi commented 2 years ago

Every method (such as spectralEmissivity) defined and used in a source (cpp) file should be declared also in appropriate header file. This is not the case in attachments you've sent.

I can help you better only if you explain or attach mathematical equations which describes what you are trying to achieve. From these equation then you should derive numerical functions / methods of the new integrator.

TejasSatheesh commented 2 years ago

Okay. Actually, I am trying to include the absorption of gamma-rays in the ISRF medium (as described in Vernetto and Lipari's model, in equations (25) to (28) in https://arxiv.org/pdf/2105.13165.pdf) for the prompt gamma-ray emission from DM annihilations. But I think I understood what I needed to do. So, I have corrected the header file, and declared the spectralEmissivity which was not done before.

After doing this and re-compiling, that error is fixed. But I still have some errors.

error: redefinition of ‘hermes::units::QDiffIntensity hermes::DarkMatterAbsorptionIntegrator::integrateOverLOS(const QDirection&, const QEnergy&) const’ /home/tejas/hermes/src/integrators/DarkMatterAbsorptionIntegrator.cpp:115:30: error: ‘bwCrossSec’ was not declared in this scope /home/tejas/hermes/include/hermes/Common.h:102:55: error: void value not ignored as it ought to be 102 | return static_cast<gsl_function_pp *>(params)->_func(x);

make[2]: [CMakeFiles/hermes.dir/build.make:427: CMakeFiles/hermes.dir/src/integrators/DarkMatterAbsorptionIntegrator.cpp.o] Error 1 make[2]: Waiting for unfinished jobs.... make[1]: [CMakeFiles/Makefile2:619: CMakeFiles/hermes.dir/all] Error 2 make: [Makefile:141: all] Error 2

I have attached the new corrected source and header files. I am a bit confused on the above errors. Can you please tell how do I proceed to fix the remaining errors?

Thanks! Tejas absorptionIntegrator_header.txt absorption_source.txt

adundovi commented 2 years ago

Errors are saying:

TejasSatheesh commented 2 years ago

Okay, with the integrateOverLOS, I understand where the two definitions are. So, in this integrator, what I want to achieve is to take the result of the gamma-ray emissivity from DM annihilations computed from the DarkMatterIntegrator and then include the absorption mechanism to compute the attenuated gamma-ray emissivity. So, in the source file I attached, I have removed one definition of the integrateOverLOS and added some lines to take the result from the existing DarkMatterIntegrator and compute the absorption (like it is done in the PiZeroAbsorptionIntegrator). But I am still getting some errors while re-compiling, looks like it is not calling the DarkMatterIntegrator I mentioned in the source file code. Can you please tell how do I take the result from the DarkMatterIntegrator and use it to compute the absorption?

Thanks! Tejas absorption_source.txt

TejasSatheesh commented 2 years ago

For the above source, I am facing errors like

error: class ‘hermes::DarkMatterAbsorptionIntegrator’ does not have any field named ‘DarkMatterIntegrator’ error: no matching function for call to ‘hermes::IntegratorTemplate<hermes::units::Quantity<std::ratio<-4, 1>, std::ratio<1>, std::ratio<-1>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<-1> >, hermes::units::Quantity<std::ratio<2>, std::ratio<-2, 1>, std::ratio<1>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0>, std::ratio<0> > >::IntegratorTemplate()’ 10 | : DarkMatterIntegrator(spectrum, profile)

adundovi commented 2 years ago
DarkMatterAbsorptionIntegrator::DarkMatterAbsorptionIntegrator(
    const std::shared_ptr<darkmatter::DarkMatterSpectrum> &spectrum,
    const std::shared_ptr<darkmatter::GalacticProfile> &profile)
    : DarkMatterIntegrator(spectrum, profile) {
    setDescription("DarkMatterAbsorptionIntegrator");
}    

In the initializer list, you cannot initialize DarkMatterIntegrator since it is not a member of DarkMatterAbsorptionIntegrator.

You could either create a new, private instance of DarkMatterIntegrator inside of the DarkMatterAbsorptionIntegrator constructor (this should be declared in the header file), and then call this instance later, in, e.g., integrateOverLOS, or you could try to inherit DarkMatterIntegrator (the most elegant way) and extend it with required features, or you could just copy all needed elements of DarkMatterIntegrator into DarkMatterAbsorptionIntegrator as there is no DarkMatterIntegrator in the source at all.

TejasSatheesh commented 2 years ago

Okay, so I first made a copy of DarkMatterIntegrator with the name DarkMatterAbsorptionIntegrator and re-compiled it, which happened without any errors. After this, in the source file of DarkMatterAbsorptionIntegrator, I have all the elements of DarkMatterIntegrator copied and then I added few more lines to include the absorption. I made the necessary changes in the header file as well. Then I got the following error, which I could not understand.

/usr/bin/ld: CMakeFiles/hermes.dir/src/integrators/DarkMatterAbsorptionIntegrator.cpp.o: in function hermes::cmbPhotonField(hermes::units::Quantity<std::ratio<2l, 1l>, std::ratio<-2l, 1l>, std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> > const&)': DarkMatterAbsorptionIntegrator.cpp:(.text+0x6bf): multiple definition ofhermes::cmbPhotonField(hermes::units::Quantity<std::ratio<2l, 1l>, std::ratio<-2l, 1l>, std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> > const&)'; CMakeFiles/hermes.dir/src/integrators/PiZeroAbsorptionIntegrator.cpp.o:PiZeroAbsorptionIntegrator.cpp:(.text+0x1127): first defined here collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/hermes.dir/build.make:900: libhermes.so] Error 1 make[1]: [CMakeFiles/Makefile2:619: CMakeFiles/hermes.dir/all] Error 2 make: *** [Makefile:141: all] Error 2

Can you please explain this error and any suggestions to fix this? I have attached my modified source and header files as well. Also, regarding the changes I made in the source file, I am a bit doubtful if it includes the entire ISRF model or is it just considering the CMB?

Thanks! Tejas absorptionIntegrator_header.txt absorption_source.txt

adundovi commented 2 years ago

You cannot define two functions with the same name (in this case cmbPhotonField). Either include the one defined in PiZeroAbsorptionIntegrator or change the name of your copy.

Regarding ISRF - I don't see that it is included in your modifications - it's only CMB. You should pass a PhotonField object to your integrator, such as in InverseComptonIntegrator.

TejasSatheesh commented 2 years ago

Okay, I will look into the ISRF to pass a PhotonField. With the cmbPhotonField, I renamed it to cmbPhotonField2 in the source directory (l have attached this here). But, I am facing errors like as shown below

/usr/bin/ld: libhermes.so: undefined reference to hermes::DarkMatterAbsorptionIntegrator::integrateOverLOS(std::array<hermes::units::Quantity<std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<1l, 1l>, std::ratio<0l, 1l> >, 2ul> const&, hermes::units::Quantity<std::ratio<2l, 1l>, std::ratio<-2l, 1l>, std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> > const&) const' collect2: error: ld returned 1 exit status make[2]: *** [CMakeFiles/testCosmicRays.dir/build.make:94: testCosmicRays] Error 1 make[1]: *** [CMakeFiles/Makefile2:376: CMakeFiles/testCosmicRays.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... /usr/bin/ld: libhermes.so: undefined reference tohermes::DarkMatterAbsorptionIntegrator::integrateOverLOS(std::array<hermes::units::Quantity<std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<1l, 1l>, std::ratio<0l, 1l> >, 2ul> const&, hermes::units::Quantity<std::ratio<2l, 1l>, std::ratio<-2l, 1l>, std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> > const&) const' collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/testDarkMatter.dir/build.make:94: testDarkMatter] Error 1 make[1]: [CMakeFiles/Makefile2:221: CMakeFiles/testDarkMatter.dir/all] Error 2

I am getting this with all the directories of CMakeFiles containing test...dir . I am a bit confused about this. Is it that I have to add something else after re-naming the cmbPhotonField? Can you please let me know how to fix this?

Thanks! Tejas absorptionIntegrator_header.txt absorption_source.txt

adundovi commented 2 years ago

Did you add new source and header files to CMakeLists.txt, too?

TejasSatheesh commented 2 years ago

Yeah, I did that..but there was a problem again, then I re built the "build" file. Then it is not giving any errors. I have attached the CMakeLists.txt here, can you please confirm once if it is right?

Thanks! CMakeLists.txt

TejasSatheesh commented 2 years ago

Also, I have also attached the integrators.cpp as a txt file, where I had to ad extra lines (the DarkMatterAbsorptionIntegrator in the last and added the lines). Can you please confirm if this is right?

Thanks! python_integrators.txt

TejasSatheesh commented 2 years ago

Okay, actually when I tried to run a python code using the new DarkMatterAbsorptionIntegrator, I am getting an error that the "DarkMatterAbsorptionIntegrator" is not defined. I think I am missing something..Can you please let me know what I am missing?

Thanks!

TejasSatheesh commented 2 years ago

I did make install after make -j in the build directory. Now it is working...finally just to confirm, I hope it is considering absorption, for the source, header, python and CMakeLists.txt (I have attached these here)...can you please confirm if everything is right? (Now I am able to run my python code with the new DarkMaterAbsorptionIntegrator without errors)

Thanks! Tejas absorptionIntegrator_header.txt absorption_source.txt python_integrators.txt CMakeLists.txt

TejasSatheesh commented 2 years ago

Just a last question, I wanted to add extra mass of dark matter particle values. For this, I added the required values in /hermes/python/darkmatter.cpp and also in the include/hermes/darkmatter/PPPC4DMIDChannels.h . For example, I have added the 1000TeV mass to these files I just mentioned and I re-compiled it, it re-compiled without any errors. But, when I am running a python code using the 1000TeV DM mass, I am getting an error that the "dark matter mass value not found" . Can any one please help me out with this? (After this, I think I can close this issue.)

Thanks! Tejas