-
Notifications
You must be signed in to change notification settings - Fork 10
/
particle.cc
1429 lines (1133 loc) · 62.6 KB
/
particle.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file particle.cc
* @author Luca Maccione, Daniele Gaggero
* @email luca.maccione@desy.de
* @email daniele.gaggero@sissa.it
* @brief Implementation of TParticle class. See the .h file
*/
#include "constants.h"
#include "geometry.h"
#include "particle.h"
#include "galaxy.h"
#include "eloss.h"
#include "xsec.h"
#include "crevolutor.h"
#include "grid.h"
#include "gas.h"
#include "input.h"
#include "spectrum.h"
#include "errorcode.h"
#include "diffusion.h"
#ifdef HAVE_ROOT
#include "TFile.h"
#include "TNtupleD.h"
#include "TString.h"
#endif
using namespace std;
vector<double> TParticle::GetEnergyGrid() const {
return _fGalaxy->GetCoordinates()->GetEk();
}
TParticle::TParticle(int A_ /**< Mass number */, int Z_ /**< Charge */, Galaxy* gal /**< A model for the galaxy */, Input* in_ /**< User input */, bool issec_, vector<TXSecBase*> xsecmodel, TNucleiList* l, int K_electron_, bool isDM_, bool isextra, bool isTPP_) :
A(A_),
Z(Z_),
uid(1000*Z_+A_),
dimz(gal->GetCoordinates()->GetDimZ()),
dimE(gal->GetCoordinates()->GetDimE()),
K_electron(K_electron_) {
in = in_;
if (in->feedback >1) cout << endl;
if (in->feedback >1) cout << "********************************************" << endl;
if (in->feedback >1) cout << "*** Welcome to the Particle constructor! ***" << endl;
if (in->feedback >1) cout << "********************************************" << endl << endl;
if (in->DiffT == Anisotropic) {
_fDiff = new TDiffusionCoefficient3D(gal->GetCoordinates(), in, gal->GetSource(), gal->GetBField(), gal->GetGeometry(), A, Z, (A==0));
vector<double> momentum = (A!=0) ? gal->GetCoordinates()->GetMomentum() : gal->GetCoordinates()->GetMomentumEl();
_fDpp = new TReaccelerationCoefficient(momentum, _fDiff, gal->GetGeometry(), in);
}
else {
_fDiff = NULL;
_fDpp = NULL;
}
isDM = isDM_;
if (in->feedback >0) cout<<"... checking IsDM? "<<isDM<<endl;
//modified
issec = issec_;
isExtra = isextra;
if (in->feedback >0) cout<<"... checking IsEXTRA? "<<isExtra<<endl;
isTPP = isTPP_;
_fGalaxy = gal;
decmode = l->GetDecayMode(uid);
lifetime = l->GetLifeTime(uid)/M_LN2;
// possible decay modes ----- DG 24.10.2013 - SK 07.11.2013 ------------------------------------------------------
if (decmode == BP) daughter = 1000*(Z-1)+A;
else if (decmode == BM) {
if ((Z == 14 && A == 32) || (Z == 18 && A ==42)) daughter = 1000*(Z+2)+A; //double beta- for these isotopes
else daughter = 1000*(Z+1)+A;
// 32Si --> 32P (14 yr) --> 32S || 42Ar(2b-)42Ca 100% Ar-K -Ca
}
else if (decmode == EC) {
if (K_electron <= 0) {
lifetime = -1.; // If the nucleus is unstable for EC the "naked" version of these isotopes does not decay
daughter = 0;
}
else { //modified
lifetime = l->GetLifeTime(uid)/M_LN2; // If the nucleus is unstable for EC the decay may happen only after it has attached an electron
daughter = 1000*(Z-1)+A;
}
}
else if (decmode == ECBM) {
if (K_electron <= 0) {
lifetime = l->GetLifeTime_naked(uid)/M_LN2;; // Beta- decay is possible for the naked nucleus
daughter = 1000*(Z+1)+A;
}
else { //modified
lifetime = l->GetLifeTime(uid)/M_LN2; // If the nucleus is unstable for EC the decay may happen only after it has attached an electron
daughter = 1000*(Z-1)+A;
}
}
else if (decmode == ECBP) {
if (K_electron <= 0) {
lifetime = l->GetLifeTime_naked(uid)/M_LN2;; // Beta+ decay is possible for the naked nucleus
daughter = 1000*(Z-1)+A;
if(Z == 28 && A == 56) daughter = 1000*(Z-2)+A; //56Ni makes a double Beta+ decay
}
else { //modified
lifetime = l->GetLifeTime(uid)/M_LN2; // If the nucleus is unstable for EC the decay may happen only after it has attached an electron
daughter = 1000*(Z-1)+A;
}
}
else daughter = 0;
//-----------------------------------------------------------------------------------------------------------------
if(!in->RDECAY){ //fk 130701
lifetime = -1; // -1 means stable!
daughter =0;
if (in->feedback >1) cout << "Radioactive Decay is turned off so every nucleus is stable!" << endl;
}
if (in->feedback >1) cout << "Computing spectrum " << endl;
if (issec) sp = new TSpectrum(gal->GetCoordinates()); // Secondary particles
else {
if (!isDM) {
if (isExtra) sp = new TSpectrum(gal->GetCoordinates(), in, gal->GetInjSpectrum_rho(1000), gal->GetInjSpectrum_alpha(1000), in->cutoff_rig, true, true); // Standard EXTRA component particles
else {
//sp = new TSpectrum(gal->GetCoordinates(), in, gal->GetInjSpectrum(uid), gal->GetInjLowSpectrum(uid), (A==0)); // Standard particles
sp = new TSpectrum(gal->GetCoordinates(), in, gal->GetInjSpectrum_rho(uid), gal->GetInjSpectrum_alpha(uid), in->cutoff_rig, (A==0), false); // Standard particles
}
}
else {
if (in->feedback >1) cout << "Particles coming from DM. Building spectrum..." << endl;
// DM particles
if (in->DMs == EWCorrections) sp = new TSpectrum(gal->GetCoordinates(), in, int(in->mx), in->dmmode, (A==0)*151 + (A==1)*154);
else if (in->DMs == DarkSUSY || in->DMs == Delta) sp = new TSpectrum(gal->GetCoordinates(), in, (A==0)*151 + (A==1)*154);
else if (in->DMs == SelfTable) {
if (in->feedback >1) cout << "Particles coming from DM. Getting datafile with inj spectrum specified by the user... " << endl;
if (A==0) //Electrons and Positrons from DM annihilation/decay
sp = new TSpectrum(gal->GetCoordinates(), in, in->MySelfTableDMel, 0);
if (A==1 && Z==-1) //Antiprotons from DM annihilation/decay
sp = new TSpectrum(gal->GetCoordinates(), in, in->MySelfTableDMap, 0);
if (A==2 && Z==-1)
sp = new TSpectrum(gal->GetCoordinates(), in, in->MySelfTableDMdbar, 0);
}
}
}
eloss.push_back(new TIonizationLoss(gal->GetCoordinates(), gal->GetGas(), gal->GetTotalGas(), in, A, Z));
eloss.push_back(new TCoulombLoss(gal->GetCoordinates(), gal->GetGas(), in, A, Z));
if (in->feedback >1) cout << "[debug] elosses - Bremsstrahlung" << endl;
if (A == 0) {
eloss.push_back(new TBremsstrahlungLoss(gal->GetCoordinates(), gal->GetGas(), gal->GetTotalGas(), in));
if (in->feedback >1) cout << "[debug] elosses - Synchrotron" << endl;
eloss.push_back(new TSynchrotronLoss(gal->GetCoordinates(), gal->GetBField(), in));
if (in->feedback >1) cout << "[debug] elosses - Inverse Compton" << endl;
eloss.push_back(new TICSLoss(gal->GetCoordinates(), gal->GetISRF(), in));
}
if (in->feedback >0) cout<<"... energy losses done!"<<endl;
_fInXSec = new TInelasticCrossSection(gal->GetCoordinates(), in, uid, K_electron, xsecmodel); //modified
if (in->feedback >0) cout << "... inelastic Cross Sections done!" << endl;
if (in->feedback >1) cout << "End of constructor " << endl;
}
/**< The constructor normally used in DRAGON */
//modified
TParticle::TParticle(TParticle& part) :
A(part.A),
Z(part.Z),
uid(part.uid),
dimz(part.dimz),
dimE(part.dimE),
daughter(part.daughter),
lifetime(part.lifetime),
isExtra(part.isExtra),
isTPP(part.isTPP),
isDM(part.isDM),
decmode(part.decmode) {
_fGalaxy = part._fGalaxy;
_fDiff = part._fDiff;
_fDpp = part._fDpp;
_fInXSec = part._fInXSec;
eloss = part.eloss;
density = part.density;
sp = part.sp;
issec = part.issec;
K_electron = part.K_electron; //modified
in = part.in;
}
TParticle::~TParticle() {
if (sp) delete sp;
if (_fInXSec) delete _fInXSec;
for (vector<TEnergyLoss*>::iterator i = eloss.begin(); i != eloss.end(); ++i) {
if (*i) delete *i;
}
eloss.clear();
density.clear();
}
void TParticle::Evolve(vector<TParticle*> part, vector<TCREvolutorBasis*> crev_, TSpallationNetwork* spnet, vector<TXSecBase*> xsecmodel, bool isSecondIteration) {
if (isSecondIteration)
if (in->feedback >1) cout << "This is the SECOND ITERATION " << endl;
TEnergyLoss el(*(eloss.front()));
for (vector<TEnergyLoss*>::iterator i = eloss.begin()+1; i != eloss.end(); ++i) el += (*(*i));
if(!in->ELOSS) el.Set_dpdt_Zero(); //fk 130701
//modified
if (in->feedback >1) cout << "We are building the secondary source term " << endl;
const vector<double> secsource = ComputeSecondarySource(part, spnet, xsecmodel);
if (in->DiffT == Isotropic) {
for (vector<TCREvolutorBasis*>::iterator crev = crev_.begin(); crev != crev_.end(); ++crev) (*crev)->Run(density, density_previous, _fInXSec, el.GetDpdt(), secsource, sp->GetSpectrum(), double(A), double(Z), lifetime, daughter, bool(issec), K_electron, isDM, isExtra); //modified
}
else {
for (vector<TCREvolutorBasis*>::iterator crev = crev_.begin(); crev != crev_.end(); ++crev) (*crev)->Run(density, density_previous, _fInXSec, el.GetDpdt(), secsource, sp->GetSpectrum(), _fDiff, _fDpp, double(A), double(Z), lifetime, daughter, bool(issec), K_electron, isDM, isExtra, _fGalaxy); //modified
}
return ;
}
/**< The constructor normally used in DRAGON */
TParticle2D::TParticle2D(int A_ /**< Mass number */, int Z_ /**< Charge */, Galaxy* gal /**< A model for the galaxy */, Input* in /**< User input */, bool uid_prec, vector<TXSecBase*> xsecmodel, TNucleiList* l, int K_electron_, bool isDM, bool isextra,bool isTPP) :
TParticle(A_, Z_, gal, in, uid_prec, xsecmodel, l, K_electron_, isDM, isextra,isTPP),
dimr(gal->GetCoordinates()->GetDimR()) {
density = vector<double>(dimr*dimz*dimE, 0.0);
}
double TParticle2D::FindNormalization(const double& normrig, const double& normval) {
if (!(uid == 1001 || uid == -1000)) {
cerr << "Asking for normalization but no protons nor primary electrons found" << endl;
exit(NOPROTELNORM);
}
vector<double> r = _fGalaxy->GetCoordinates()->GetR();
unsigned int irsun = (unsigned int) ((in->robs-r.front())/(r.back()-r.front())*(double)(dimr-1));
vector<double> z = _fGalaxy->GetCoordinates()->GetZ();
vector<double> Ek = _fGalaxy->GetCoordinates()->GetEk();
unsigned int izsun = (unsigned int) ((in->zobs-z.front())/(z.back()-z.front())*(double)(dimz-1));
if (in->feedback >1) cout << "irsun = " << irsun << " izsun = " << izsun << endl;
for (int ind = 0; ind < Ek.size(); ind++)
if (in->feedback >1) cout << "spectrum at irsun, izsun = " << density[TParticle::index(irsun,izsun,ind)] << endl;
double r1 = (r[irsun+1]-in->robs)/(r[irsun+1]-r[irsun]);
double r2 = (in->robs-r[irsun])/(r[irsun+1]-r[irsun]);
int ilow = int(log(normrig/Ek[0])/log(Ek[1]/Ek[0]));
if (in->feedback >1) cout << "energy index = " << ilow << endl;
double valuelow = log10( (density[TParticle::index(irsun,izsun,ilow)]*r1+density[TParticle::index(irsun+1,izsun,ilow)]*r2) );
double valuehigh = log10( (density[TParticle::index(irsun,izsun,ilow+1)]*r1+density[TParticle::index(irsun+1,izsun,ilow+1)]*r2) );
if (in->feedback >1) cout << "valuelow and valuehigh " << valuelow << " " << valuehigh << endl;
double e1 = log(Ek[ilow+1]/normrig)/log(Ek[ilow+1]/Ek[ilow]);
double e2 = log(normrig/Ek[ilow])/log(Ek[ilow+1]/Ek[ilow]);
double value = pow(10,valuelow*e1 + valuehigh*e2);
double factor = normval/value;
//cout << value << " " << inp->spect_norm << endl;
//cout << factor << " " << factorint << " comparison of interpolation." << endl;
//cout << "Normalization required in the xml: " << inp->spect_norm << endl;
if (in->feedback >1) cout << "Reference value in arbitrary units = " << value << "; Normalization factor = " << factor << endl << endl;
return factor;
}
vector<double> TParticle2D::ComputeSecondarySource(vector<TParticle*> part, TSpallationNetwork* spnet, vector<TXSecBase*> xsecmodel) {
/**< Here also inverse beta-decay (K-electron capture) must be taken into account */
vector<double> result(density.size(), 0.0);
// If it is the only particle to be propagated, or if it is primary electrons, or if it is DM, do not add secondary contribution
if (part.size() == 1 || (uid == -1000 && !issec) || isDM) return result;
TGas* totalgas = _fGalaxy->GetTotalGas();
TGrid* coord = _fGalaxy->GetCoordinates();
#undef DEBUG
#ifdef DEBUG
vector<double> Ek = coord->GetEk();
#endif
if (issec && fabs(uid) != 1000) { // Secondary protons or tertiary antiprotons or tertiary antideuterons: they are next to their primary brothers...
vector<double> Ek(coord->GetEk());
if (in->spallationxsec != Fluka) {
if (uid == 1001 && issec)
cout << "... secondary protons!" << endl;
if (uid == -999 && issec)
cout << "... tertiary antiprotons!" << endl;
vector<TParticle*>::iterator iprim = part.end()-2; // Primary species
vector<double> beta(coord->GetBeta());
vector<double> spall_spectrum( spnet->GetXSec(uid, uid) );
for (int k = 0; k < dimr; ++k) {
for (int l = 0; l < dimz; ++l) {
int indspat = coord->index(k,l);
double gasdensity = totalgas->GetGas(indspat);
for (int i = 0; i < dimE; ++i) {
double betaigasdensity = beta[i]*gasdensity;
int ind = indspat*dimE+i;
//if (k==0 && l==0) cout << "E= " << Ek[i] << " spall xsec from p = " << spall_spectrum[i] << endl;
for (int ii = i; ii < dimE; ++ii) result[ind] += (*iprim)->GetDensity(indspat*dimE+ii) * betaigasdensity * spall_spectrum[ii];
}
}
}
//cout << "*** End of spallation cross section: ***" << endl;
} else { //Fluka model
if (uid == 1001 && issec)
cout << "Secondary protons!" << endl;
if (uid == -999 && issec)
cout << "Tertiary antiprotons" << endl;
cout << "*** Fluka cross sections! " << endl;
pair<int,int> coupleppr(1001,1001); // Secondary protons, from prim. protons
pair<int,int> couplepHe(2004,1001); // Secondary protons, from Helium
pair<int,int> coupleapap(-999, -999); // Tertiary antiprotons, from sec. antiprotons
cout << "*** Spallation cross section: ***" << endl;
//loop over the parent particles. Only p and He are relevant
for (vector<TParticle*>::iterator ipart = part.begin(); ipart != part.end()-1; ++ipart) {
if ((*ipart)->GetUid() > 2004 || (*ipart)->GetUid() < 0) continue;
for (int i = 0; i < dimE; i++) {
vector<double> spall_spectrum( spnet->GetXSecApEl((*ipart)->GetUid(), uid, i) );
if (spall_spectrum.size() == dimE) {
for (int k = 0; k < dimr; k++) {
for (int l = 0; l < dimz; l++) {
int indspat = coord->index(k,l);
double gasdensity = totalgas->GetGas(indspat);
int ind = indspat*dimE+i;
// ENERGY INTEGRAL
for (int ii=0; ii < dimE; ii++) {
result[ind] += (*ipart)->GetDensity(indspat*dimE+ii) * gasdensity * spall_spectrum[ii];
if ((*ipart)->GetUid() == 1001 && uid==1001 && k==0 && l==0)
cout << " E_parent= " << Ek[i] << " E_daughter= " << Ek[ii] << " spall xsec from p = " << spall_spectrum[ii] << endl;
}
}
}
}
}
}
cout << "*** End of spallation cross section: ***" << endl;
}
} // if (issec && uid != -1000)
else if (uid > 1000) { // nuclei spallation
//modified
vector<double> gamma(coord->GetGamma());
vector<double> beta(coord->GetBeta());
vector<double> energy(coord->GetEk());
//modified
//if K_capture is present, the source term due to electron attachment/stripping is computed
if (K_electron > 0) {
double factor = 1.e-27*Clight;
TParticle* naked_nucleus;
if (part.size() > 1) naked_nucleus = part[part.size()-2];
if (in->feedback >1) cout << "Computing source term for dressed nucleus " << endl;
//cout << "source term coming from nucleus with A = " << naked_nucleus->GetA() << "; Z = " << naked_nucleus->GetZ() << endl;
for (int k = 0; k < dimr; ++k) {
for (int l = 0; l < dimz; ++l) {
int indspat = coord->index(k,l);
double Gasdensity = totalgas->GetGas(indspat);
for (int i = 0; i < dimE; ++i) {
int ind = indspat*dimE+i;
double attach_H=0., attach_He=0., strip_H=0., strip_He=0.;
xsecmodel[0]->Kcapture_cs(energy[i],naked_nucleus->GetZ(),1,&attach_H,&strip_H);
xsecmodel[0]->Kcapture_cs(energy[i],naked_nucleus->GetZ(),2,&attach_He,&strip_He);
result[ind] = Gasdensity * (attach_H + He_abundance*attach_He) * factor * beta[i] * naked_nucleus->GetDensity(ind);
}
}
}
}
//modified
//if K_capture is present and K_electron == 1, the source term ends here: it only contains contribution from the corresponding naked nucleus
else { // if K_capture is present and K_electron == 0, the source term must contain also the spallation and decay contribution from heavier nuclei
for (vector<TParticle*>::iterator ipart = part.begin(); ipart != part.end()-1; ++ipart) { // // //
if ((*ipart)->GetDaughter() == uid && in->feedback >1)
cout << "---> Nucleus " << ((*ipart))->GetUid() << " decays into current particle " << uid << endl;
vector<double> spall_spectrum( spnet->GetXSec( (*ipart)->GetUid(), uid ) );
if (spall_spectrum.size() == dimE || (*ipart)->GetDaughter() == uid) {
double Afactor = double((*ipart)->GetA())/double(A); // To convert between kinetic energy per nucleon (which is approx. constant) to momentum
for (int k = 0; k < dimr; ++k) {
for (int l = 0; l < dimz; ++l) {
int indspat = coord->index(k,l);
double Afactorgasdensity = Afactor*totalgas->GetGas(indspat);
for (int i = 0; i < dimE; ++i) {
int ind = indspat*dimE+i;
if (spall_spectrum.size() == dimE) result[ind] += Afactorgasdensity * spall_spectrum[i] * (*ipart)->GetDensity(ind); // spallation
if ((*ipart)->GetDaughter() == uid) result[ind] += (*ipart)->GetDensity(ind)/(*ipart)->GetLifetime()/gamma[i]; // decay
}
}
}
}
}
} // if (K_electron == 0)
} // else if (uid > 1000)
else { // Secondary antiprotons, electrons and positrons, antideuterons, positrons from TPP
if (!isTPP) {
// ofstream outfile("prova_Pohl.dat", ios::out);
for (vector<TParticle*>::iterator ipart = part.begin(); ipart != part.end()-1; ++ipart) {
if ((*ipart)->GetUid() > 2004 || (*ipart)->GetUid() < 0) continue;
for (int i = 0; i < dimE; i++) {
vector<double> spall_spectrum( spnet->GetXSecApEl((*ipart)->GetUid(), uid, i) );
if (spall_spectrum.size() == dimE) {
for (int k = 0; k < dimr; k++) {
for (int l = 0; l < dimz; l++) {
int indspat = coord->index(k,l);
double gasdensity = totalgas->GetGas(indspat);
int ind = indspat*dimE+i;
// ENERGY INTEGRAL
for (int ii=0; ii < dimE; ii++) { result[ind] += (*ipart)->GetDensity(indspat*dimE+ii) * gasdensity * spall_spectrum[ii];
#ifdef DEBUG
if ((*ipart)->GetUid() == 1001 && uid==1000) outfile << Ek[i] << Ek[ii] << spall_spectrum[ii] << endl;
#endif
}
}
}
}
}
}
// outfile.close();
}
else { //TPP: Secondary positrons coming from TPP -- implemented by D.Gaggero -- november 2011
// if (uid == 1000 && issec) { //TPP: Secondary positrons coming from TPP
if (in->feedback >1) cout << "Building source term for TPP positrons..." << endl;
vector<double> energy(coord->GetEk());
vector<double> R_vec(coord->GetR());
vector<double> z_vec(coord->GetZ());
double DlogE = coord->GetDeltaE();
TISRF* Gal_ISRF = _fGalaxy->GetISRF();
vector <double> nu_vector = Gal_ISRF->GetNuArray();
double DlogNu = Gal_ISRF->GetDnu();
int dimNu = nu_vector.size();
double hPlanck = 4.135667e-15; // eV/Hz
vector <double> ISRF_vector = Gal_ISRF->GetISRF(); // nu U_nu; units: Hz eV cm^-3 Hz^-1
for (vector<TParticle*>::iterator ipart=part.begin(); ipart!=part.end()-1; ++ipart) {
if ((*ipart)->GetUid() == -1000) { //TPP positrons only come from (primary and secondary) electrons
if (in->feedback >1) cout << "Calculating TPP cross section..." << endl;
vector<double> TPP_cross_section(spnet->GetXSecTPP(nu_vector));
if (in->feedback >1) cout << "TPP cross section calculated" << endl;
vector<double> parent_particle_density (dimE*dimr*dimz);
for (int k = 0; k < dimr; k++) {
for (int l = 0; l < dimz; l++) {
for (int ii = 0; ii < dimE; ii++) {
int indspat = coord->index(k,l);
parent_particle_density[indspat*dimE+ii] = (*ipart)->GetDensity(indspat*dimE+ii);
}
}
}
for (int i = 0; i < dimE; i++) {
for (int k = 0; k < dimr; k++) {
for (int l = 0; l < dimz; l++) {
int indspat = coord->index(k,l);
int ind = indspat*dimE+i;
for (int inu = 0; inu<dimNu; inu++) { // integral over frequency_vector of ISRF
double photon_density = ISRF_vector[(inu*dimr+k)*dimz+l] / ((hPlanck * nu_vector[inu])*nu_vector[inu]); // rho_nu; units: cm^-3 Hz^-1
double energy_integral = 0.;
for (int ii=0; ii < dimE; ii++) { // integral over energy of parent particle
double contrib = parent_particle_density[indspat*dimE+ii] * TPP_cross_section[(i*dimNu + inu)*dimE +ii] * DlogE; // cm^-3 * cm^3/Myr DeltalogE:adimensional
energy_integral += contrib;
}
double contrib_2 = photon_density * energy_integral * nu_vector[inu] * DlogNu; // cm^-3 * 1/Myr Deltalognu: adimensional
result[ind] += contrib_2;
}
} //for l = 0,dimz
} // for k = 0,dimr
} //for i=0,dimE
}
if (in->feedback >1) cout << "Building source term for TPP positrons succeeded." << endl;
}
}
} // else
return result;
}
void TParticle2D::Print(fitsfile* output_ptr, double norm) { /**< Print all the information relevant to that nucleus: charge, mass, source abundance, injection spectrum and propagated density. */
int status = 0;
const long naxis = 3;
long size_axes[naxis] = {dimE,dimr,dimz};
long nelements = size_axes[0]*size_axes[1]*size_axes[2];
long fpixel = 1;
int bitpix = FLOAT_IMG;
if (fits_create_img(output_ptr, bitpix, naxis, size_axes, &status)) fits_report_error(stderr, status);
double sab = _fGalaxy->GetSourceAbundance(uid);
if (fits_write_key(output_ptr, TINT, (char*) "Z_", &Z, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TINT, (char*) "A", &A, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TINT, (char*) "Sec", &issec, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TINT, (char*) "DM", &isDM, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TINT, (char*) "EXTRA", &isExtra, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TINT, (char*) "TPP", &isTPP, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TDOUBLE, (char*) "S_Ab", &sab, NULL, &status)) fits_report_error(stderr, status);
int counter = 0;
float* array = new float[nelements];
double weight = 1;
if (A != 0) weight = double(A);
for (int l = 0; l < dimz; ++l) {
for (int k = 0; k < dimr; ++k) {
for (int j = 0; j < dimE; ++j) {
array[counter] = float(weight*density[TParticle::index(k,l,j)]*norm);
counter++;
}
}
}
if (fits_write_img(output_ptr, TFLOAT, fpixel, nelements, array, &status)) fits_report_error(stderr, status);
delete [] array;
return ;
}
void TParticle2D::PrintSpectrum(fitsfile* output_ptr, double norm) { /**< Print all the information relevant to that nucleus: charge, mass, source abundance, injection spectrum and propagated spectrum at Sun position. */
int status = 0;
const long naxis = 1;
long size_axes[naxis] = {dimE};
long nelements = size_axes[0];
long fpixel = 1;
int bitpix = FLOAT_IMG;
if (fits_create_img(output_ptr, bitpix, naxis, size_axes, &status)) fits_report_error(stderr, status);
double sab = (!issec) ? _fGalaxy->GetSourceAbundance(uid) : 0.0;
if (fits_write_key(output_ptr, TINT, (char*) "Z_", &Z, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TINT, (char*) "A", &A, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TINT, (char*) "Sec", &issec, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TINT, (char*) "DM", &isDM, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TINT, (char*) "EXTRA", &isExtra, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TINT, (char*) "TPP", &isTPP, NULL, &status)) fits_report_error(stderr, status);
if (fits_write_key(output_ptr, TDOUBLE, (char*) "S_Ab", &sab, NULL, &status)) fits_report_error(stderr, status);
float* array = new float[nelements];
double weight = 1;
vector<double> r = _fGalaxy->GetCoordinates()->GetR();
vector<double> z = _fGalaxy->GetCoordinates()->GetZ();
vector<double> Ek =_fGalaxy->GetCoordinates()->GetEk();
unsigned int irsun = (unsigned int) ((in->robs-r.front())/(r.back()-r.front())*(double)(dimr-1));
unsigned int izsun = (unsigned int) ((in->zobs-z.front())/(2.0*z.back())*(double)(dimz-1));
double r1 = (r[irsun+1]-in->robs)/(r[irsun+1]-r[irsun]);
double r2 = (in->robs-r[irsun])/(r[irsun+1]-r[irsun]);
if (A != 0) weight = double(A);
if (isDM && in->feedback >1)
cout << "**** particle originating from DARK MATTER *****" << endl;
if (in->feedback >1) cout << "************************************************" << endl;
if (in->feedback >1) cout << "***Writing spectrum at Solar System position... " << endl;
if (in->feedback >1) cout << "************************************************" << endl;
if (in->feedback >1) cout << "A = " << A << " Z = " << Z << " issec = " << issec << endl;
if (in->feedback >1) cout << "************************************************" << endl;
if (in->feedback >1) cout << "Energy -- Normalized flux " << endl;
for (int j = 0; j < dimE; ++j){
array[j] = float(weight*norm*( density[TParticle::index(irsun,izsun,j)]*r1 + density[TParticle::index(irsun+1,izsun,j)]*r2 ));
if (in->feedback >1) cout << Ek[j] << " " << array[j] << endl;
}
if (in->feedback >1) cout << endl;
if (fits_write_img(output_ptr, TFLOAT, fpixel, nelements, array, &status)) fits_report_error(stderr, status);
delete [] array;
return;
}
vector<double> TParticle2D::GetSpectrumAtSunPosition() {
vector<double> result(dimE);
vector<double> r = _fGalaxy->GetCoordinates()->GetR();
vector<double> z = _fGalaxy->GetCoordinates()->GetZ();
vector<double> Ek = _fGalaxy->GetCoordinates()->GetEk();
unsigned int irsun = (unsigned int) ((in->robs-r.front())/(r.back()-r.front())*(double)(dimr-1));
unsigned int izsun = (unsigned int) ((in->zobs-z.front())/(2.0*z.back())*(double)(dimz-1));
double r1 = (r[irsun+1]-in->robs)/(r[irsun+1]-r[irsun]);
double r2 = (in->robs-r[irsun])/(r[irsun+1]-r[irsun]);
double weight = 1;
if (A != 0) weight = double(A);
for (int j = 0; j < dimE; ++j)
result[j] = weight*(density[TParticle::index(irsun,izsun,j)]*r1 + density[TParticle::index(irsun+1,izsun,j)]*r2);
return result;
}
double TParticle2D::GetFluxAtSunPosition(int j) {
vector<double> r = _fGalaxy->GetCoordinates()->GetX();
vector<double> z = _fGalaxy->GetCoordinates()->GetZ();
vector<double> Ek = _fGalaxy->GetCoordinates()->GetEk();
unsigned int irsun = (unsigned int) ((in->robs-r.front())/(r.back()-r.front())*(double)(dimr-1));
unsigned int izsun = (unsigned int) ((in->zobs-z.front())/(2.0*z.back())*(double)(dimz-1));
double r1 = (r[irsun+1]-in->robs)/(r[irsun+1]-r[irsun]);
double r2 = (in->robs-r[irsun])/(r[irsun+1]-r[irsun]);
double weight = 1;
if (A != 0) weight = double(A);
return density[TParticle::index(irsun,izsun,j)]*r1 + density[TParticle::index(irsun+1,izsun,j)]*r2;
}
TParticle3D::TParticle3D(int A_ /**< Mass number */, int Z_ /**< Charge */, Galaxy* gal /**< A model for the galaxy */, Input* in /**< User input */, bool uid_prec, vector<TXSecBase*> xsecmodel, TNucleiList* l, int K_electron_, bool isDM, bool isextra, bool isTPP) :
TParticle(A_, Z_, gal, in, uid_prec, xsecmodel, l, K_electron_, isDM, isextra, isTPP),
dimx(gal->GetCoordinates()->GetDimX()),
dimy(gal->GetCoordinates()->GetDimY()) {
cout << "Welcome to the Particle 3D constructor! " << endl;
int dimz = (gal->GetCoordinates()->GetDimZ());
vector<double> x = (gal->GetCoordinates()->GetX());
vector<double> y = (gal->GetCoordinates()->GetY());
vector<double> z = (gal->GetCoordinates()->GetZ());
//MW130620: What are these deltas used for? -- for now, set them equidistantially
double deltax = ( (x.back() - x.front()) / (dimx-1) );
double deltay = ( (y.back() - y.front()) / (dimy-1) );
double deltaz = ( (z.back() - z.front()) / (dimz-1) );
cout << "Initializing the density vector... " << endl;
density = vector<double>(dimx*dimy*dimz*dimE, 0.0);
density_previous = vector<double>(dimx*dimy*dimz*dimE, 0.0);
if (gal->GetTestMode() == true) {
cout << "Initializing to a gaussian... " << endl;
//double delta_ = deltax * 2.;
double delta_ = deltax/100.;
cout << "Amplitude of initial gaussian = " << delta_ << endl;
double init_value = 0.;
double x1 = 0.;
double x2 = 0.;
double norm1 = 1.;
double norm2 = 0.;
//double x3 = -10;
for (int ix=0; ix<dimx; ix++) {
for (int iy=0; iy<dimy; iy++) {
for (int iz=0; iz<dimz; iz++) {
for (int ip=0; ip<dimE; ip++) {
// double x1 = -20.;
// double x2 = 20.;
if ( gal->IsSourceMoving() == false) {
init_value = norm1 * (1./(sqrt(3.14)*delta_)) * exp( -((x[ix]-x1)*(x[ix]-x1))/(delta_*delta_) - (y[iy]*y[iy])/(delta_*delta_) - (z[iz]*z[iz])/(delta_*delta_) );
init_value += norm2 * (1./(sqrt(3.14)*delta_)) * exp( -((x[ix]-x2)*(x[ix]-x2))/(delta_*delta_) - (y[iy]*y[iy])/(delta_*delta_) - (z[iz]*z[iz])/(delta_*delta_) );
}
else {
init_value = 0.; // (1./(sqrt(3.14)*delta_)) * exp( -((x[ix]-x3)*(x[ix]-x3))/(delta_*delta_) - (y[iy]*y[iy])/(delta_*delta_) - (z[iz]*z[iz])/(delta_*delta_) );
}
// if (ip == 0 && iz == dimz/2 && init_value > 1.e-1)
// cout << " x = " << x[ix] << " y = " << y[iy] << " z = " << z[iz] << " value = " << init_value << endl;
density[index(ix,iy,iz,ip)] = init_value; //initialization ot a Gaussian centered on the origin in order to compare with the analytical solution
}
}
}
}
}
}
//******************************************************************************************************************************************************
double TParticle3D::FindNormalization(const double& sp_ref_rig_norm, const double& spect_norm) {
if (!(uid == 1001 || uid == -1000)) {
cerr << "Asking for normalization but no protons nor primary electrons found" << endl;
exit(NOPROTELNORM);
}
cout << "3D normalization " << endl;
cout << "Observer position: " << in->xobs << " " << in->yobs << " " << in->zobs << endl;
// Matze: rewrite stuff for nonequidistant grid
vector <double> x = _fGalaxy->GetCoordinates()->GetX();
vector <double> y = _fGalaxy->GetCoordinates()->GetY();
vector <double> z = _fGalaxy->GetCoordinates()->GetZ();
vector <double> Ek = _fGalaxy->GetCoordinates()->GetEk();
unsigned int ixsun = 0;
while(x[++ixsun] <= in->xobs){}
ixsun--;
unsigned int iysun = 0;
while(y[++iysun] <= in->yobs){}
iysun--;
unsigned int izsun = 0;
while(z[++izsun] <= in->zobs){}
izsun--;
double rx1 = (x[ixsun+1]-in->xobs)/(x[ixsun+1]-x[ixsun]);
double ry1 = (y[iysun+1]-in->yobs)/(y[iysun+1]-y[iysun]);
double rz1 = (z[izsun+1]-in->zobs)/(z[izsun+1]-z[izsun]);
double rx2 = 1-rx1;
double ry2 = 1-ry1;
double rz2 = 1-rz1;
cout << rx1 << " = rx1; rx2 = " << rx2 << endl;
cout << ry1 << " = ry1; ry2 = " << ry2 << endl;
cout << rz1 << " = rz1; rz2 = " << rz2 << endl;
//double sp_ref_rig_norm, spect_norm;
//sp_ref_rig_norm = (uid == 1001) ? inp->sp_ref_rig_norm : inp->sp_ref_rig_el;
//spect_norm = (uid == 1001) ? inp->spect_norm : inp->spect_norm_el;
int ilow = int(log(sp_ref_rig_norm/Ek[0])/log(Ek[1]/Ek[0]));
cout << "ilow, i.e. energy index " << ilow << endl;
cout << "Ek[ilow] = " << Ek[ilow] << endl;
cout << "Sun coordinates: " << ixsun << " " << iysun << " " << izsun << endl;
cout << "+++ Propagated spectrum at Sun +++" << endl;
for (int i=0; i < Ek.size(); i++)
cout << density[index(ixsun, iysun, izsun, i)] << " " ;
cout << "+++ End of propagated spectrum +++" << endl;
double valuelow = log10( (density[index(ixsun, iysun, izsun, ilow)]*rx1*ry1
+ density[index(ixsun, iysun+1,izsun, ilow)]*rx1*ry2
+ density[index(ixsun+1,iysun, izsun, ilow)]*rx2*ry1
+ density[index(ixsun+1,iysun+1,izsun, ilow)]*rx2*ry2)*rz1
+(density[index(ixsun, iysun, izsun+1,ilow)]*rx1*ry1
+ density[index(ixsun, iysun+1,izsun+1,ilow)]*rx1*ry2
+ density[index(ixsun+1,iysun, izsun+1,ilow)]*rx2*ry1
+ density[index(ixsun+1,iysun+1,izsun+1,ilow)]*rx2*ry2)*rz2);
if (in->feedback >1) cout << "10^valuelow i.e. density at sun pos., ilow energy = " << pow(10,valuelow) << endl;
double valuehigh = log10((density[index(ixsun, iysun, izsun ,ilow+1)]*rx1*ry1
+ density[index(ixsun, iysun+1,izsun ,ilow+1)]*rx1*ry2
+ density[index(ixsun+1,iysun, izsun ,ilow+1)]*rx2*ry1
+ density[index(ixsun+1,iysun+1,izsun ,ilow+1)]*rx2*ry2)*rz1
+(density[index(ixsun, iysun, izsun+1,ilow+1)]*rx1*ry1
+ density[index(ixsun, iysun+1,izsun+1,ilow+1)]*rx1*ry2
+ density[index(ixsun+1,iysun, izsun+1,ilow+1)]*rx2*ry1
+ density[index(ixsun+1,iysun+1,izsun+1,ilow+1)]*rx2*ry2)*rz2);
if (in->feedback >1) cout << "10^valuehigh i.e. density at sun pos., ihigh energy = " << pow(10,valuehigh) << endl;
double e1 = log(Ek[ilow+1]/sp_ref_rig_norm)/log(Ek[ilow+1]/Ek[ilow]);
double e2 = log(sp_ref_rig_norm/Ek[ilow])/log(Ek[ilow+1]/Ek[ilow]);
if (in->feedback >1) cout << e1 << " = e1; e2 = " << e2 << endl;
double value = pow(10,valuelow*e1 + valuehigh*e2);
if (in->feedback >1) cout << "10^(valuelow*e1 + valuehigh*e2) = " << value << endl;
double factor = spect_norm/value;
if (in->feedback >1) cout << "normalization required in the xml: " << spect_norm << endl;
if (in->feedback >1) cout << "interpolated value at ixsun, ixsun+1, iysun, iysun+1, ilow, ilow+1: " << value << endl;
if (in->feedback >1) cout << "normalization factor = norm/value: " << factor << endl;
if (in->feedback >1){
cout << "+++ Propagated NORMALIZED spectrum at Sun +++" << endl;
for (int i=0; i < Ek.size(); i++)
cout << density[index(ixsun, iysun, izsun, i)]*factor << " " ;
cout << "+++ End of propagated spectrum +++" << endl;
}
int dimx = x.size();
int dimy = y.size();
int dimz = z.size();
if (in->feedback >1){
cout << "+++ Propagated NORMALIZED spectrum at the Gal.center +++" << endl;
for (int i=0; i < Ek.size(); i++)
cout << density[index(dimx/2+1, dimy/2+1, izsun, i)]*factor << " " ;
cout << "+++ End of propagated spectrum +++" << endl;
cout << "+++ Propagated NORMALIZED spectrum at intermediate latitude +++" << endl;
for (int i=0; i < Ek.size(); i++)
cout << density[index(ixsun-1, iysun-1, (dimz+izsun)/2, i)]*factor << " " ;
cout << "+++ End of propagated spectrum +++" << endl;
}
return factor;
}
/*
double TParticle3D::FindNormalization(TParticle* electrons, const double& normel) {
//To be used for the extra component
if (!(uid == -1000)) {
cerr << "Asking for normalization of the extra component but no primary electrons found" << endl;
exit(NOPROTELNORM);
}
// Matze: rewrite what needed to be revised,
// 10/12/12: copied that from above
// To Be Improved!! Now it is only a copy of the previous routine!!
vector <double> x = _fGalaxy->GetCoordinates()->GetX();
vector <double> y = _fGalaxy->GetCoordinates()->GetY();
vector<double> z = _fGalaxy->GetCoordinates()->GetZ();
vector<double> Ek = _fGalaxy->GetCoordinates()->GetEk();
unsigned int ixsun = 0;
unsigned int iysun = 0;
unsigned int izsun = 0;
while(x[++ixsun] <= xobs){}
ixsun--;
while(y[++iysun] <= yobs){}
iysun--;
while(z[++izsun] <= zobs){}
izsun--;
double rx1 = (x[ixsun+1]-xobs)/(x[ixsun+1]-x[ixsun]);
double ry1 = (y[iysun+1]-yobs)/(y[iysun+1]-y[iysun]);
double rz1 = (z[izsun+1]-zobs)/(z[izsun+1]-z[izsun]);
double rx2 = 1-rx1;
double ry2 = 1-ry1;
double rz2 = 1-rz1;
cout << rx1 << " = rx1; rx2 = " << rx2 << endl;
cout << ry1 << " = ry1; ry2 = " << ry2 << endl;
cout << rz1 << " = rz1; rz2 = " << rz2 << endl;
double sp_ref_rig_norm, spect_norm;
sp_ref_rig_norm = (uid == 1001) ? inp->sp_ref_rig_norm : inp->sp_ref_rig_el_extra;
spect_norm = (uid == 1001) ? inp->spect_norm : inp->spect_norm_el_extra;
int ilow = int(log(sp_ref_rig_norm/Ek[0])/log(Ek[1]/Ek[0]));
cout << "ilow, i.e. energy index " << ilow << endl;
// To be checked
cout << "sun coordinates (for electrons): " << ixsun << " " << iysun << " " << izsun << endl;
double valuelow = log10( (density[index(ixsun,iysun,izsun,ilow)]*rx1*ry1
+ density[index(ixsun,iysun+1,izsun,ilow)]*rx1*ry2
+ density[index(ixsun+1,iysun,izsun,ilow)]*rx2*ry1
+ density[index(ixsun+1,izsun+1,izsun,ilow)]*rx2*ry2)*rz1
+ (density[index(ixsun,iysun,izsun+1,ilow)]*rx1*ry1
+ density[index(ixsun,iysun+1,izsun+1,ilow)]*rx1*ry2
+ density[index(ixsun+1,iysun,izsun+1,ilow)]*rx2*ry1
+ density[index(ixsun+1,izsun+1,izsun+1,ilow)]*rx2*ry2)*rz2);
cout << "valuelow = " << pow(10,valuelow) << endl;
double valuehigh = log10( (density[index(ixsun,iysun,izsun,ilow+1)]*rx1*ry1
+ density[index(ixsun,iysun+1,izsun,ilow+1)]*rx1*ry2
+ density[index(ixsun+1,iysun,izsun,ilow+1)]*rx2*ry1
+ density[index(ixsun+1,izsun+1,izsun,ilow+1)]*rx2*ry2)*rz1
+ (density[index(ixsun,iysun,izsun+1,ilow+1)]*rx1*ry1
+ density[index(ixsun,iysun+1,izsun+1,ilow+1)]*rx1*ry2
+ density[index(ixsun+1,iysun,izsun+1,ilow+1)]*rx2*ry1
+ density[index(ixsun+1,izsun+1,izsun+1,ilow+1)]*rx2*ry2)*rz2);
cout << "valuehigh = " << pow(10,valuehigh) << endl;
double e1 = log(Ek[ilow+1]/sp_ref_rig_norm)/log(Ek[ilow+1]/Ek[ilow]);
double e2 = log(sp_ref_rig_norm/Ek[ilow])/log(Ek[ilow+1]/Ek[ilow]);
cout << e1 << " = e1; e2 = " << e2 << endl;
double value = pow(10,valuelow*e1 + valuehigh*e2);
double factor = spect_norm/value;
cout << "normalization required in the xml: " << spect_norm << endl;
cout << "interpolated value at ixsun, ixsun+1, iysun, iysun+1, ilow, ilow+1: " << value << endl;
cout << "normalization factor = norm/value: " << factor << endl << endl;
return factor;
}
*/
//******************************************************************************************************************************************************
vector<double> TParticle3D::ComputeSecondarySource(vector<TParticle*> part, TSpallationNetwork* spnet, vector<TXSecBase*> xsecmodel) {
/**< Here also inverse beta-decay (K-electron capture) must be taken into account */
cout << "We are starting the 3D computation of the secondary source " << endl;
vector<double> result(density.size(), 0.0);
// If it is the only particle to be propagated, or if it is primary electrons, do not add secondary contribution
if (part.size() == 1 || (uid == -1000 && !issec) || isDM || isExtra) return result;
TGas* totalgas = _fGalaxy->GetTotalGas();
TGrid* coord = _fGalaxy->GetCoordinates();
if (issec && fabs(uid) != 1000) { // Secondary protons or tertiary antiprotons or tertiary antideuterons: they are next to their primary brothers...
vector<TParticle*>::iterator iprim = part.end()-2; // Primary species
vector<double> beta(coord->GetBeta());
vector<double> spall_spectrum( spnet->GetXSec(uid, uid) );
cout << "Sec. proton or tert. antiproton/antideuteron: " << uid << " "<< issec << endl;
for (int k = 0; k < dimx; ++k) {
for (int j = 0; j < dimy; ++j) {
for (int l = 0; l < dimz; ++l) {
int indspat = coord->indexD(k,j,l);
double gasdensity = totalgas->GetGas(indspat);
//if (l == dimz/2 && j==0)
// cout << k << " " << j << " " << gasdensity << endl;
//if (l == dimz/2 && j==dimy/2)
// cout << k << " " << j << " " << gasdensity << endl;
for (int i = 0; i < dimE; ++i) {
double betaigasdensity = beta[i]*gasdensity;
int ind = indspat*dimE+i;
for (int ii = i+1; ii < dimE; ++ii) result[ind] += (*iprim)->GetDensity(indspat*dimE+ii) * betaigasdensity * spall_spectrum[ii];
}
}
}
}
} // if (issec && uid != -1000)
else if (uid > 1000) { // nuclei spallation
//modified
vector<double> gamma(coord->GetGamma());
vector<double> beta(coord->GetBeta());
vector<double> energy(coord->GetEk());
//modified
//if K_capture is present, the source term due to electron attachment/stripping is computed
if (K_electron > 0) {
double factor = 1.e-27*Clight;