-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxsec.cc
2684 lines (2009 loc) · 95.7 KB
/
xsec.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
#include "xsec.h"
#include "kamae.h"
TSpallationNetwork::TSpallationNetwork(TGrid* coord, Input* in, std::vector<TXSecBase*> xsecmodel, std::vector<int>& nuclei) {
std::cout << "\nXSecs option " << in->spallationxsec << std::endl;
if (in->spallationxsec == Fluka){
spallXsecFile = "data/FlukaSpallInclusiveXsec_last_cumulative.dat";
spallXsecFile_p = "data/Fluka_Proton_production_new.dat";
}
else if (in->spallationxsec == GalpropXSec){
spallXsecFile = "data/galprop_eval_iso_cs_updated.dat";
spallXsecFile_p = "";
}
else if (in->spallationxsec == Webber03){
spallXsecFile = "data/webber_xsec_total.dat";
spallXsecFile_p = "";}
else if (in->spallationxsec == DRAGON2){
spallXsecFile = "data/crxsecs_fragmentation_Evoli2019_cumulative_modified.dat";
spallXsecFile_p = "";}
else {
std::cout << "Wrong SpallationXSec option!! --> Taking the default one (DRAGON2 for nuclei, DRAGON treatment for Secondary protons) \n" << std::endl;
spallXsecFile = "data/crxsecs_fragmentation_Evoli2019_cumulative_modified.dat";
spallXsecFile_p = "";
}
DRAGONEnergyVector.clear();
const double factor = Clight*1.e-27;
std::vector<double> beta = coord->GetBeta();
DRAGONEnergyVector = coord->GetEk();
const int dimEn = DRAGONEnergyVector.size();
std::cout << std::endl << "Energy min " << *DRAGONEnergyVector.begin() << " Energy max " << DRAGONEnergyVector.back() << "\n" << "Energy entries " << DRAGONEnergyVector.size() << "\n" << std::endl;
if (in->spallationxsec == Fluka || in->spallationxsec == DRAGON2){
std::cout << std::endl << "Reading spallation cross sections... " << std::endl;
if(in->spallationxsec == Fluka) std::cout << " From Fluka table! \n" << std::endl;
else if(in->spallationxsec == DRAGON2) std::cout << " From DRAGON2 table! \n" << std::endl;
else std::cout << " From default (DRAGON2 algorithm)" << std::endl;
datafileSpall.open(spallXsecFile.c_str());
if (!datafileSpall){
std::cout << "SpallationXSec file not found!! --> Check the folder data in your setup for the file " << spallXsecFile << "\n" << std::endl;
exit(-1);}
std::cout << spallXsecFile << std::endl;
std::string header;
getline(datafileSpall, header); //skipping the header
std::cout << "this is the header: " << header << std::endl;
double parentUID_tableFormat;
double daughterUID_tableFormat;
int parentUID;
int daughterUID;
double kineticEnergy = 0.;
double xsec;
double xsec_He;
std::string comment1;
int counter = 0;
spallationKineticEnergyVector.clear();
while (datafileSpall >> parentUID_tableFormat >> daughterUID_tableFormat >> kineticEnergy >> xsec >> xsec_He >> comment1) {
//if (counter%5000==0)
//std::cout << parentUID_tableFormat << " " << daughterUID_tableFormat<< " " << kineticEnergy << " " << xsec << " " << xsec_He << " " << comment1.c_str() << std::endl;
if (parentUID_tableFormat == 8.16 && daughterUID_tableFormat == 6.12)
spallationKineticEnergyVector.push_back(kineticEnergy/1000.); // * MeV --> CHECK UNITS!!! //The DragonEnergy is in GeV
double fracPart, intPart=0;
fracPart = modf(parentUID_tableFormat, &intPart);
parentUID = int(intPart*1000. + fracPart*100.) ; //1000*Z + A
double fracPart2, intPart2=0;
fracPart2 = modf(daughterUID_tableFormat, &intPart2);
daughterUID = int(intPart2*1000. + fracPart2*100.) ; //1000*Z + A
// If nucleus is antiproton of leptons skip it. Skip also if mass(daughter) > mass(parent)
if (daughterUID <= 1001 || intPart < intPart2) continue;
std::pair<int,int> couple1(parentUID, daughterUID);
std::pair<double,double> couple2(xsec, xsec_He);
spallationXsections[couple1].push_back(couple2); // mbarn --> CHECK UNITS!!!
//std::cout << couple1.first << " " << couple1.second << " " << couple2.first << std::endl;
counter++;
} // end of the while loop
datafileSpall.close();
std::cout << "...spallation cross sections successfully read from file" << std::endl << std::endl;
} // End if Carmelo or Fluka
TGalpropXSec default_Galpropobject(coord, in);
default_Galpropobject.set_sigma_cc();
int ISS = -1;
default_Galpropobject.sigtap_cc(ISS);
if(in->spallationxsec == DRAGON2){ //Adding the He contribution to the DRAGON2 XSecs
std::vector <double> AddedXSec_vec;
for (int iloop = 0; iloop < nuclei.size()-1; ++iloop) {
// If antiprotons or leptons, do not compute spallation. If protons, do not compute, because their spallation products will be computed elsewhere
if (nuclei[iloop] <= 1001) continue;
int iz = -1000; // parent nucleus charge
int ia = -1000; // parent nucleus mass
Utility::id_nuc(nuclei[iloop], ia, iz);
for (int idaught = iloop+1; idaught < nuclei.size(); ++idaught) {
int jz = -1000; // daughter nucleus charge
int ja = -1000; // daughter nucleus mass
Utility::id_nuc(nuclei[idaught], ja, jz);
// If nucleus is antiproton of leptons skip it. Skip also if mass(daughter) > mass(parent)
if (nuclei[idaught] < 1001 || ia < ja) continue;
pair<int,int> couple(1000*iz+ia,1000*jz+ja);
if (jz > 2 ){
if (spallationXsections[couple].empty()){
for(unsigned int is = 0; is < spallationKineticEnergyVector.size(); ++is) {
spallationXsections[couple].push_back(std::pair <double, double> (0., 0.));
}
}
else{
for(unsigned int is = 0; is < spallationKineticEnergyVector.size(); ++is) {
spallationXsections[couple][is].first = (spallationXsections[couple][is].first*(1.0 + He_abundance*default_Galpropobject.He_to_H_CS_ratio(spallationKineticEnergyVector[is],iz,ia,jz,ja)));
}
}
}
else{ //For helium, tritium or deuterion creation we need Webber Spall XSecs
spall[couple] = default_Galpropobject.GetXSec(iz, ia, jz, ja);
}
}
}
}
///////////////////// PROTON XSECS \\\\\\\\\\\\\\\\\\\
int dimFlukaTables = 160;
int dimprot = dimFlukaTables;
double Ep[dimprot], Elept[dimprot], Eap[dimprot];
double T[dimEn], ET[dimEn];
double DBlog = 1./16;
const double factorprot = factor*coord->GetDeltaE();
const double factorelpos = 1.e3*factorprot; // barn/GeV --- *10^3 ---> mbarn/GeV --- *factorprot ---> cm^3/s
std::pair<int,int> coupleppr(1001, 1001); // Secondary protons, from protons
std::pair<int,int> couplepHe(2004, 1001); // Secondary protons, from Helium
if (in->spallationxsec != Fluka) {
std::cout << "\nFilling secondary protons table";
std::cout << " --> using DRAGON treatment of secondary protons" << std::endl;
double xsec;
spall[coupleppr] = vector<double>(dimEn, 0);
for(unsigned int ip = 0; ip < dimEn; ++ip) {
PP_inel = 0.0;
PA_inel = 0.0;
aPP_non = 0.0;
aPA_non = 0.0;
aPP_ann = 0.0;
aPA_ann = 0.0;
default_Galpropobject.nucleon_cs(2, DRAGONEnergyVector[ip], 1, 2, 4, &PP_inel, &PA_inel, &aPP_non, &aPA_non, &aPP_ann, &aPA_ann); // CROSEC INEXS
spall[coupleppr][ip] = in->SPALL*factorprot*(PP_inel + He_abundance*PA_inel);
}
std::cout << "\n Secondary protons OK!!\n" << std::endl;
}
else { //fluka
std::ifstream infile;
infile.open(spallXsecFile_p.c_str());
std::cout << "Opening secondary proton spallXsec file: " << spallXsecFile_p.c_str() << std::endl;
if (!infile.is_open()){ std::cout << "problem opening Secproton file: "<< spallXsecFile_p << " !!!" << std::endl;
exit(-1);}
double a,b,c,d;
Matrix_p_pp = std::vector<double>(dimprot*dimprot, 0.0);
Matrix_p_pHe = std::vector<double>(dimprot*dimprot, 0.0);
Matrix_p_Hep = std::vector<double>(dimprot*dimprot, 0.0);
Matrix_p_HeHe = std::vector<double>(dimprot*dimprot, 0.0);
for (int i = 0; i < dimprot; i++) {
for (int j = 0; j < dimprot; j++) {
infile >> a >> b >> c >> d;
ind = i * (dimprot-1) + j;//index_matrix(i,j);
Matrix_p_pp[ind] = a;
Matrix_p_pHe[ind] = b;
Matrix_p_Hep[ind] = c;
Matrix_p_HeHe[ind] = d;
}
}
infile.close();
std::cout << "Filling secondary protons table " << std::endl;
std::pair<int,int> coupleppr(1001, 1001); // Secondary protons, from protons
std::pair<int,int> couplepHe(2004, 1001); // Secondary protons, from Helium
for (int i = 0; i < dimprot; i++) { //Here we are filling at the beggining of the ApEl species all the energy vectors for FLUKA. If different
//tables were to have different dimensions or different energy configurations this is not correct anymore.
Elept[i] = pow(10., log10(1e-2)+double(i)*DBlog+0.5*DBlog);
Ep[i] = Elept[i];
Eap[i] = Elept[i];
}
//float total_p, total_He;
spall_apel[coupleppr] = vector< vector<double> >(dimEn, vector<double>(dimEn, 0.0));
spall_apel[couplepHe] = vector< vector<double> >(dimEn, vector<double>(dimEn, 0.0));
for (int j = 0; j < dimprot; j++) ET[j] = pow(10, log10(1e-2) + double(j)*DBlog);
for (unsigned int j = 0; j < dimEn; j++){
Epr = DRAGONEnergyVector[j];
for (unsigned int i = 0; i < dimEn; i++){
cs_pp = 0.;
cs_pHe = 0.;
cs_Hep = 0.;
cs_HeHe = 0.;
Ep_i = std::min(Ep[dimprot-1], DRAGONEnergyVector[i]);
if(Epr >= ET[0] && Epr<=ET[dimprot-1] && Ep_i >=Ep[0] && Ep_i<=Ep[dimprot-1]) { //Interpolation is possible!
j_pr = int(floor(log10(Epr/ET[0])/DBlog));
if (j_pr > dimEn-2) j_pr = dimEn-2;
u = (Epr-ET[j_pr])/(ET[j_pr+1]-ET[j_pr]);
i_ap = int(floor(log10(Ep_i/Ep[0])/DBlog));
if (i_ap > dimEn-2) i_ap = dimEn-2;
index = i_ap * (dimprot-1) + j_pr;//index_matrix(i_ap,j_pr);
index1 = index+1; //index_matrix(i_ap,j_pr+1);
valuefix = Matrix_p_pp[index];
valueup = Matrix_p_pp[index1];
cs_pp = valuefix*(1-u) + valueup*u;
valuefix = Matrix_p_pHe[index];
valueup = Matrix_p_pHe[index1];
cs_pHe = valuefix*(1-u) + valueup*u;
valuefix = Matrix_p_Hep[index];
valueup = Matrix_p_Hep[index1];
cs_Hep = valuefix*(1-u) + valueup*u;
valuefix = Matrix_p_HeHe[index];
valueup = Matrix_p_HeHe[index1];
cs_HeHe = valuefix*(1-u) + valueup*u;
}
spall_apel[coupleppr][i][j] = Epr*(cs_pp + He_abundance*cs_pHe)*factorelpos;
spall_apel[couplepHe][i][j] = 4.0*Epr*(cs_Hep + He_abundance*cs_HeHe)*factorelpos;
}
}
std::cout << "\n Fluka Secondary protons OK!!\n" << std::endl;
}
// If antiprotons and/or leptons are wanted in output, add them, and add also secondary protons
if(in->prop_ap || in->prop_lep || in->prop_deuteron) {
vector<double> pp = coord->GetMomentum();
size_t limit = 100000;
gsl_integration_workspace* w = gsl_integration_workspace_alloc(limit);
std::pair<int,int> coupleapap(-999, -999); // Tertiary antiprotons
std::pair<int,int> coupleappr(1001,-999); // Secondary antiprotons, from protons
std::pair<int,int> coupleapHe(2004,-999); // Secondary antiprotons, from Helium
spall_apel[coupleappr] = vector< vector<double> >(dimEn, vector<double>(dimEn, 0.0));
spall_apel[coupleapHe] = vector< vector<double> >(dimEn, vector<double>(dimEn, 0.0));
spall_apel[coupleapap] = vector< vector<double> >(dimEn, vector<double>(dimEn, 0.0));
if(in->prop_ap) {
if (in->apy == Winkler){
std::cout << "Reading sec antiprotons tables method Winkler... " << std::endl;
TSpallationNetwork::InitXSecWinkler(factorelpos);
std::cout << "\n Winkler secondary antiprotons OK!! \n" << std::endl;
std::cout << "Filling tert antiprotons table DRAGON procedure ... " << std::endl;
spall[coupleapap] = vector<double>(dimEn, 0);
for(unsigned int ip = 0; ip < dimEn; ++ip) {
PP_inel = 0.0;
PA_inel = 0.0;
aPP_non = 0.0;
aPA_non = 0.0;
aPP_ann = 0.0;
aPA_ann = 0.0;
default_Galpropobject.nucleon_cs(2, DRAGONEnergyVector[ip], -1, 2, 4, &PP_inel, &PA_inel, &aPP_non, &aPA_non, &aPP_ann, &aPA_ann);
spall[coupleapap][ip] = factorprot*( aPP_non + He_abundance*aPA_non );
}
}
else if (in->apy == GalpropFunction){ //Sec and Tertiary XS from Galprop
std::cout << "Filling sec antiprotons table method Galprop... " << std::endl;
for (unsigned int i = 0; i < dimEn; i++) {
for (unsigned int ii=i+1; ii < dimEn; ii++) { //ii is the progenitor energy!
spall_apel[coupleappr][i][ii] = factorelpos*DRAGONEnergyVector[ii]*(default_Galpropobject.antiproton_cc1(w,limit,in->antiproton_cs, pp[i], pp[ii], 1, 1, 1, 1) * ( (!in->scaling) + (in->scaling)*(0.12 * pow(DRAGONEnergyVector[i], -1.67) + 1.78)) + (!in->scaling)*He_abundance*default_Galpropobject.antiproton_cc1(w,limit,in->antiproton_cs, pp[i], pp[ii], 1, 1, 2, 4));
spall_apel[coupleapHe][i][ii] = factorelpos*DRAGONEnergyVector[ii]*4.0*(default_Galpropobject.antiproton_cc1(w,limit,in->antiproton_cs, pp[i], 4.0*pp[ii], 2, 4, 1, 1) * ( (!in->scaling) + (in->scaling)*(0.12 * pow(DRAGONEnergyVector[i], -1.67) + 1.78)) + (!in->scaling)*He_abundance*default_Galpropobject.antiproton_cc1(w,limit,in->antiproton_cs, pp[i], 4.0*pp[ii], 2, 4, 2, 4));
}
}
std::cout << "\n Secondary antiprotons OK!!\n " << std::endl;
std::cout << "Filling tert antiprotons table DRAGON procedure ... " << std::endl;
spall[coupleapap] = vector<double>(dimEn, 0);
for(unsigned int ip = 0; ip < dimEn; ++ip) {
PP_inel = 0.0;
PA_inel = 0.0;
aPP_non = 0.0;
aPA_non = 0.0;
aPP_ann = 0.0;
aPA_ann = 0.0;
default_Galpropobject.nucleon_cs(2, DRAGONEnergyVector[ip], -1, 2, 4, &PP_inel, &PA_inel, &aPP_non, &aPA_non, &aPP_ann, &aPA_ann);
spall[coupleapap][ip] = factorprot*( aPP_non + He_abundance*aPA_non );
}
}
else if (in->apy == FlukaAp){
spallXsecFile_ap = "data/Fluka_Antiproton_production_new.dat";
spallXsecFile_Tap = "data/Fluka_TertiaryAntiproton_production_new.dat";
std::ifstream infile;
infile.open(spallXsecFile_ap.c_str());
std::cout << "Opening secondary antiproton spallXsec file " << spallXsecFile_ap.c_str() << std::endl;
if (!infile.is_open()){ std::cout << "problem opening SecAp Fluka file!!"<< std::endl;
exit(-1);}
double a,b,c,d;
Matrix_Ap_pp = std::vector<double>(dimprot*dimprot, 0.0);
Matrix_Ap_pHe = std::vector<double>(dimprot*dimprot, 0.0);
Matrix_Ap_Hep = std::vector<double>(dimprot*dimprot, 0.0);
Matrix_Ap_HeHe = std::vector<double>(dimprot*dimprot, 0.0);
for (int j = 0; j < dimprot; j++) ET[j] = pow(10, log10(1e-2) + double(j)*DBlog);
for (int i = 0; i < dimprot; i++) {
Elept[i] = pow(10., log10(1e-2)+double(i)*DBlog+0.5*DBlog);
Ep[i] = Elept[i];
Eap[i] = Elept[i];
}
for (int i = 0; i < dimprot; i++) {
for (int j = 0; j < dimprot; j++) {
infile >> a >> b >> c >> d;
ind = i * (dimprot-1) + j;//index_matrix(i,j);
Matrix_Ap_pp[ind] = a;
Matrix_Ap_pHe[ind] = b;
Matrix_Ap_Hep[ind] = c;
Matrix_Ap_HeHe[ind] = d;
}
}
infile.close();
std::cout << "Filling sec antiprotons table " << std::endl;
for (unsigned int j = 0; j < dimEn; j++){
Epr = DRAGONEnergyVector[j];
for (unsigned int i = 0; i < dimEn; i++){
cs_pp = 0.;
cs_pHe = 0.;
cs_Hep = 0.;
cs_HeHe = 0.;
Eap_i = std::min(Eap[dimprot-1], DRAGONEnergyVector[i]);
if(Epr >= ET[0] && Epr<=ET[dimprot-1] && Eap_i >=Eap[0] && Eap_i<=Eap[dimprot-1]) {
j_pr = int(floor(log10(Epr/ET[0])/DBlog));
if (j_pr > dimEn-2) j_pr = dimEn-2;
u = (Epr-ET[j_pr])/(ET[j_pr+1]-ET[j_pr]);
i_ap = int(floor(log10(Eap_i/Eap[0])/DBlog));
if (i_ap > dimEn-2) i_ap = dimEn-2;
index = i_ap * (dimprot-1) + j_pr;//index_matrix(i_ap,j_pr);
index1 = index+1; //index_matrix(i_ap,j_pr+1);
valuefix = Matrix_Ap_pp[index];
valueup = Matrix_Ap_pp[index1];
cs_pp = valuefix*(1-u) + valueup*u;
valuefix = Matrix_Ap_pHe[index];
valueup = Matrix_Ap_pHe[index1];
cs_pHe = valuefix*(1-u) + valueup*u;
valuefix = Matrix_Ap_Hep[index];
valueup = Matrix_Ap_Hep[index1];
cs_Hep = valuefix*(1-u) + valueup*u;
valuefix = Matrix_Ap_HeHe[index];
valueup = Matrix_Ap_HeHe[index1];
cs_HeHe = valuefix*(1-u) + valueup*u;
}
if (cs_pp <1.e-30) {
cs_pp=0.;
}
if (cs_pHe <1.e-30) {
cs_pHe=0.;
}
if (cs_Hep <1.e-30) {
cs_Hep=0.;
}
if (cs_HeHe <1.e-30) {
cs_HeHe=0.;
}
spall_apel[coupleappr][i][j] = Epr*(cs_pp + He_abundance*cs_pHe)*factorelpos;
spall_apel[coupleapHe][i][j] = 4.0*Epr*(cs_Hep + He_abundance*cs_HeHe)*factorelpos;
}
}
std::cout << "\n Secondary Antiprotons OK!!\n" << std::endl;
infile.open(spallXsecFile_Tap.c_str());
std::cout << "Opening tertiary antiproton spallXsec file " << spallXsecFile_Tap.c_str() << std::endl;
if (!infile.is_open()){ std::cout << "problem opening TertAp file!!"<< std::endl;
exit(-1);}
a = 0;
b = 0;
Matrix_Ap_app = std::vector<double>(dimprot*dimprot, 0.0);
Matrix_Ap_apHe = std::vector<double>(dimprot*dimprot, 0.0);
for (int i = 0; i < dimprot; i++) {
for (int j = 0; j < dimprot; j++) {
infile >> a >> b;
ind = i * (dimprot-1) + j;//index_matrix(i,j);
Matrix_3Ap_app.push_back(a);
Matrix_3Ap_apHe.push_back(b);
}
}
infile.close();
std::cout << "Filling tert antiprotons table " << std::endl;
for (unsigned int j=0; j<dimEn; j++){
std::vector<double> apap_vec;
Epr = DRAGONEnergyVector[j];
double thisum = 0.;
for (unsigned int i = 0; i < dimEn; i++) {
cs_pp = 0.;
cs_pHe = 0.;
Eap_i = std::min(Eap[dimprot-1], DRAGONEnergyVector[i]); //Energy[i]);
if(Epr >= ET[0] && Epr<=ET[dimprot-1] && Eap_i >=Eap[0] && Eap_i<=Eap[dimprot-1]) {
j_pr = int(floor(log10(Epr/ET[0])/DBlog));
if (j_pr > dimEn-2) j_pr = dimEn-2;
u = (Epr-ET[j_pr])/(ET[j_pr+1]-ET[j_pr]);
i_ap = int(floor(log10(Eap_i/Eap[0])/DBlog));
if (i_ap > dimEn-2) i_ap = dimEn-2;
index = i_ap * (dimprot-1) + j_pr;//index_matrix(i_ap,j_pr);
index1 = index + 1;//index_matrix(i_ap,j_pr+1);
valuefix = Matrix_3Ap_app[index];
valueup = Matrix_3Ap_app[index1];
cs_pp = valuefix*(1-u) + valueup*u;
valuefix = Matrix_3Ap_apHe[index];
valueup = Matrix_3Ap_apHe[index1];
cs_pHe = valuefix*(1-u) + valueup*u;
}
if (cs_pp <1.e-30) {
cs_pp=0.;
}
if (cs_pHe <1.e-30) {
cs_pHe=0.;
}
spall_apel[coupleapap][i][j] = Epr*(cs_pp + He_abundance*cs_pHe)*factorelpos;
}
}
} //End tertAntip
std::cout << "\n Tertiary Antiprotons OK!!\n" << std::endl;
} // ap
if (in->prop_lep) {
std::pair<int,int> coupleel(1001, -1000); // Electrons from protons
std::pair<int,int> couplepos(1001, 1000); // Positrons from protons
std::pair<int,int> coupleelHe(2004, -1000); // Electrons from He
std::pair<int,int> coupleposHe(2004, 1000); // Positrons from He
spall_apel[coupleel] = vector< vector<double> >(dimEn, vector<double>(dimEn, 0.0));
spall_apel[couplepos] = vector< vector<double> >(dimEn, vector<double>(dimEn, 0.0));
spall_apel[coupleelHe] = vector< vector<double> >(dimEn, vector<double>(dimEn, 0.0));
spall_apel[coupleposHe] = vector< vector<double> >(dimEn, vector<double>(dimEn, 0.0));
for (int j = 0; j < dimprot; j++) ET[j] = pow(10, log10(1e-2) + double(j)*DBlog);
for (int i = 0; i < dimprot; i++) {
Elept[i] = pow(10., log10(1e-2)+double(i)*DBlog+0.5*DBlog);
Ep[i] = Elept[i];
Eap[i] = Elept[i];
}
if (in->ly == GalpropTable) {
std::cout << "\nGalprop leptons XSecs, loading..." << std::endl;
spallXsecFile_pos = "data/ElTablefile";//Galprop_Positron_production_new.dat";
spallXsecFile_el = "data/PosTablefile";//Galprop_Electron_production_new.dat";
Nelectrons = 160;//401;
Nprotons = 160;//801;
}//End Elpos Galprop
else if(in->ly == Pohl) TSpallationNetwork::InitXSecPohl(factorelpos);
else if (in->ly == Kamae){std::cout << "Kamae leptons " << std::endl; TSpallationNetwork::InitXSecKamae(factorelpos); }
else if (in->ly == FlukaLep) {
std::cout << "\nFluka leptons XSecs, loading..." << std::endl;
spallXsecFile_el = "data/Fluka_Electron_production_new.dat";
spallXsecFile_pos = "data/Fluka_Positron_production_new.dat";
Nelectrons = 160;
Nprotons = 160;;
}
else{
std::cout << "Wrong SpallationXSec option!! --> Taking the default one (Kamae) \n" << std::endl;
TSpallationNetwork::InitXSecKamae(factorelpos);
}
if(in->ly == FlukaLep || in->ly == GalpropTable){
std::cout << "Opening electron production file " << spallXsecFile_el.c_str() << std::endl;
std::ifstream infile;
infile.open(spallXsecFile_el.c_str());
if (!infile.is_open()){ std::cout << "problem opening spall_el file!!"<< std::endl;
exit(-1);}
double a,b,c,d;
Matrix_El_pp = std::vector<double>(Nelectrons*Nprotons, 0.0);
Matrix_El_pHe = std::vector<double>(Nelectrons*Nprotons, 0.0);
Matrix_El_Hep = std::vector<double>(Nelectrons*Nprotons, 0.0);
Matrix_El_HeHe = std::vector<double>(Nelectrons*Nprotons, 0.0);
Matrix_Pos_pp = std::vector<double>(Nelectrons*Nprotons, 0.0);
Matrix_Pos_pHe = std::vector<double>(Nelectrons*Nprotons, 0.0);
Matrix_Pos_Hep = std::vector<double>(Nelectrons*Nprotons, 0.0);
Matrix_Pos_HeHe = std::vector<double>(Nelectrons*Nprotons, 0.0);
for (int i = 0; i < Nelectrons; i++) {
for (int j = 0; j < Nprotons; j++) {
infile >> a >> b >> c >> d;
ind = i * (Nelectrons-1) + j; //index_matrix(i,j);
Matrix_El_pp[ind] = a;
Matrix_El_pHe[ind] = b;
Matrix_El_Hep[ind] = c;
Matrix_El_HeHe[ind] = d;
}
}
infile.close();
infile.open(spallXsecFile_pos.c_str());
std::cout << "Opening positron production file " << spallXsecFile_pos.c_str() << std::endl;
if (!infile.is_open()){ std::cout << "problem opening spall_pos file!!"<< std::endl;
exit(-1);}
for (int i = 0; i < Nelectrons; i++) {
for (int j = 0; j < Nprotons; j++) {
infile >> a >> b >> c >> d;
ind = i * (Nelectrons-1) + j; //index_matrix(i,j);
Matrix_Pos_pp[ind] = a;
Matrix_Pos_pHe[ind] = b;
Matrix_Pos_Hep[ind] = c;
Matrix_Pos_HeHe[ind] = d;
}
}
infile.close();
int dimlept = 160; //Be careful with this, it can be different!
int dimpr = dimlept;
double DBprlog = DBlog;
int i_lept;
std::cout << "filling leptons... " << std::endl;
for (unsigned int j=0; j<dimEn; j++){
Epr = DRAGONEnergyVector[j];
for (unsigned int i = 0; i < dimEn; i++) {
cs_pp = 0.;
cs_pHe = 0.;
cs_Hep = 0.;
cs_HeHe = 0.;
double Eel = std::min(Elept[dimlept-1], DRAGONEnergyVector[i]);
if(Epr >= ET[0] && Epr<=ET[dimpr-1] && Eel >=Elept[0] && Eel<=Elept[dimlept-1]) {
j_pr = int(floor(log10(Epr/ET[0])/DBprlog));
if (j_pr > dimpr-1) j_pr = dimpr-1;
u = (Epr-ET[j_pr])/(ET[j_pr+1]-ET[j_pr]);
i_lept = int(floor(log10(Eel/Elept[0])/DBlog));
if (i_lept > dimlept-1) i_lept = dimlept-1;
index = i_lept * (dimlept-1) + j_pr; //index_matrix(i_lept,j_pr);
index1 = index+1;//index_matrix(i_lept,j_pr+1);
valuefix = Matrix_El_pp[index];
valueup = Matrix_El_pp[index1];
cs_pp = valuefix*(1-u) + valueup*u;
valuefix = Matrix_El_pHe[index];
valueup = Matrix_El_pHe[index1];
cs_pHe = valuefix*(1-u) + valueup*u;
valuefix = Matrix_El_Hep[index];
valueup = Matrix_El_Hep[index1];
cs_Hep = valuefix*(1-u) + valueup*u;
valuefix = Matrix_El_HeHe[index];
valueup = Matrix_El_HeHe[index1];
cs_HeHe = valuefix*(1-u) + valueup*u;
}
spall_apel[coupleel][i][j] = Epr*(cs_pp + He_abundance*cs_pHe)*factorelpos;
spall_apel[coupleelHe][i][j] = 4.0*Epr*(cs_Hep + He_abundance*cs_HeHe)*factorelpos;
cs_pp = 0.;
cs_pHe = 0.;
cs_Hep = 0.;
cs_HeHe = 0.;
if(Epr >= ET[0] && Epr<=ET[dimpr-1] && Eel >=Elept[0] && Eel<=Elept[dimlept-1]) {
j_pr = int(floor(log10(Epr/ET[0])/DBprlog));
if (j_pr > dimpr-1) j_pr = dimpr-1;
u = (Epr-ET[j_pr])/(ET[j_pr+1]-ET[j_pr]);
i_lept = int(floor(log10(Eel/Elept[0])/DBlog));
if (i_lept > dimlept-1) i_lept = dimlept-1;
index = i_lept * (dimlept-1) + j_pr;//index_matrix(i_lept,j_pr);
index1 = index+1;//index_matrix(i_lept,j_pr+1);
valuefix = Matrix_Pos_pp[index];
valueup = Matrix_Pos_pp[index1];
cs_pp = valuefix*(1-u) + valueup*u;
valuefix = Matrix_Pos_pHe[index];
valueup = Matrix_Pos_pHe[index1];
cs_pHe = valuefix*(1-u) + valueup*u;
valuefix = Matrix_Pos_Hep[index];
valueup = Matrix_Pos_Hep[index1];
cs_Hep = valuefix*(1-u) + valueup*u;
valuefix = Matrix_Pos_HeHe[index];
valueup = Matrix_Pos_HeHe[index1];
cs_HeHe = valuefix*(1-u) + valueup*u;
}
spall_apel[couplepos][i][j] = Epr*(cs_pp + He_abundance*cs_pHe)*factorelpos;
spall_apel[coupleposHe][i][j] = 4.0*Epr*(cs_Hep + He_abundance*cs_HeHe)*factorelpos;
}
}
}//End table reading
std::cout << "\n Leptons OK!! \n " << std::endl;
}//el
if (in->prop_deuteron) {
std::cout << "Dedicated deuteron propagation is not yet available..." << std::endl;
std::pair<int,int> coupledeutdeut(-998,-998); // Tertiary antideuterons
std::pair<int,int> coupledeutapr(-999,-998); // Secondary antideuterons, from antiprotons
std::pair<int,int> coupledeutpr(1001,-998); // Secondary antideuterons, from protons
std::pair<int,int> coupledeutHe(2004,-998); // Secondary antideuterons, from Helium
}
} //End of triple option
if (in->spallationxsec == Fluka || in->spallationxsec == DRAGON2){
std::pair <double, double> xsecpair;
//double xsecHint, xsecHeint;
for(std::map<std::pair<int, int>, std::vector<std::pair<double, double> > >::iterator it = spallationXsections.begin(); it != spallationXsections.end(); ++it) {
std::pair<int, int> couple1 = it->first; // (*it).first
if (couple1.second <= 1001) continue;
//std::cout << "Getting spallation cross sections from " << couple1.first << " to " << couple1.second << std::endl;
for (int ie = 0; ie < DRAGONEnergyVector.size(); ie++) {
xsecpair = TSpallationNetwork::GetXSecPair(couple1.first, couple1.second, DRAGONEnergyVector[ie]);
//std::cout << "XSecH " << xsecpair.first << " XSecHe " << xsecpair.second << std::endl;
if (xsecpair.first > 10000. || xsecpair.first < 0.)
std::cout << "\n\n\n\nSomething strange happens with H when filling " << xsecpair.first;
if (xsecpair.second != 0. || xsecpair.second < 0.)
std::cout << "\n\nSomething strange happens with He when filling";
spallationXsectionsInterpolated[couple1].push_back(xsecpair);
if (in->spallationxsec == DRAGON2)
xsecpair.second = 0;
spall[couple1].push_back(factor*beta[ie]*(spallationXsectionsInterpolated[couple1][ie].first + He_abundance*spallationXsectionsInterpolated[couple1][ie].second));
} //End of Energy loop
} // End of nuclei loop
} //option Fluka and Carmelo
else{ //If we have Webber or Galprop we do not have anything to read!
if (in->spallationxsec == Webber03) std::cout << "\nWebber spallation XSecs\n" << std::endl;
else if (in->spallationxsec == GalpropXSec){ default_Galpropobject.InitXSec(); std::cout << "\nGalprop spallation XSecs\n" << std::endl; }
for (int iloop = 0; iloop < nuclei.size(); ++iloop) {
// If antiprotons or leptons, do not compute spallation. If protons, do not compute, because their spallation products will be computed elsewhere
if (nuclei[iloop] <= 1001) continue;
int iz = -1000; // parent nucleus charge
int ia = -1000; // parent nucleus mass
Utility::id_nuc(nuclei[iloop], ia, iz);
for (int idaught = iloop+1; idaught < nuclei.size(); ++idaught) {
int jz = -1000; // daughter nucleus charge
int ja = -1000; // daughter nucleus mass
Utility::id_nuc(nuclei[idaught], ja, jz);
std::pair <double, double> couple1 (nuclei[iloop], nuclei[idaught]);
//std::cout << "Getting spallations " << couple1.first << " to " << couple1.second << std::endl;
// If nucleus is antiproton of leptons skip it. Skip also if mass(daughter) > mass(parent)
if (nuclei[idaught] < 1001 || ia < ja) continue;
spall[couple1] = default_Galpropobject.GetXSec(iz, ia, jz, ja);
}
}
} //End Webber and Galprop option
std::cout << "\n...General grid inter and extrapolation done\n\n" << std::endl << std::endl;
return ;
}
std::vector<double> TGalpropXSec::GetXSec(int iz, int ia, int jz, int ja) {
int IZ1,IA1,IZ3,IA3,kopt,info, K_electron =0;
int galdef_network_par=0; // temporary solution; value 1 caused problems in nuc_package
double branching_ratio,t_half;
const int diz=3; // maximum delta Z considered
const double factor = Clight*1.e-27;
kopt = cross_section_option; //= 12, defined in constants.h
if (inn->spallationxsec == Webber03 || inn->spallationxsec == DRAGON2){ //In case we ask for Webber
kopt = 1;
if (jz == 3 | jz == 2)
kopt = 2 ;
}
std::vector<double> spalla = std::vector<double>(energy.size(), 0.0);
// a loop over an intermediate state; final state must be as requested
for (IZ1=(jz-diz>1) ? jz-diz: 1; IZ1<=iz && IZ1<=jz+diz; IZ1++) {
for (IA1=(2*IZ1-4>ja) ? 2*IZ1-4: ja; IA1<ia && IA1<=2.5*IZ1+4.2; IA1++) {
// channel selection procedure
if (IA1 < IZ1 || ia-IA1 < iz-IZ1) continue;
// IMOS20010816 line below
branching_ratio = TGalpropXSec::nucdata(galdef_network_par,IZ1,IA1,K_electron,jz,ja, &IZ3,&IA3,&t_half);
if (branching_ratio == 0) continue;
t_half = t_half / year;
// skip if long-lived intermediate state
if(t_half>=t_half_limit // IMOS20010816
&& 100*IZ1+IA1!=100*jz+ja && 100*IZ3+IA3!=100*jz+ja) continue;
for(unsigned int ip = 0; ip < energy.size(); ip++){
spalla[ip] += (TGalpropXSec::isotope_cs(energy[ip]*1000.0,iz,ia,IZ1,IA1,kopt,&info)*branching_ratio*(1.0+ He_abundance*TGalpropXSec::He_to_H_CS_ratio(energy[ip],iz,ia,IZ1,IA1))*beta[ip]*factor);
}
} //ja1 //jz1
}
return spalla;
}
void TGalpropXSec::InitXSec(){
int i,j,k,size;
const int BufferSize=200;
char readBuffer[BufferSize];
std::ifstream data;
data_filename.push_back("data/galprop_nucdata.dat");
data_filename.push_back("data/galprop_p_cs_fits.dat");
data_filename.push_back("data/galprop_eval_iso_cs_updated.dat");
for (int j = 0; j < 3 ; j++){
std::cout << "Opening file " << data_filename[j].c_str() << std::endl;
data.open(data_filename[j].c_str()); // open file if exists
if(data.fail()) {std::cout <<"Error opening file "<< data_filename[j] << std::endl;
exit(1); }
while(!isspace(data.get()) && !data.eof()) // skip comments:
data.getline(readBuffer,BufferSize,'\n'); // any symbol in 1st col.
for(i=0; i<3; data >> n_data[i++][j]); // read array's sizes
data.getline(readBuffer,BufferSize,'\n'); // skip the rest of line
for(size=1, i=0; i<3; size*=n_data[i++][j]); // allocate space
if (j == 0) nucdat = new float[size];
else if (j == 1) protdat = new float[size];
else csdat = new float[size];
for(k = 0; k < size && !data.eof();) // read data loop
{
while(!isspace(data.get()) && !data.eof()) // skip comments:
data.getline(readBuffer,BufferSize,'\n'); // any symbol in 1st col.
if (j == 0)
for(i=0; i < n_data[0][j]; i++) data >> *(nucdat+k++);
else if (j == 1)
for(i=0; i < n_data[0][j]; i++) data >> *(protdat+k++);
else
for(i=0; i < n_data[0][j]; i++) data >> *(csdat+k++);
data.getline(readBuffer,BufferSize,'\n'); // skip the rest of line
}
data.close();
}
}
double TGalpropXSec::isotope_cs(double emev,int iz,int ia,int izf,int iaf,int kopt,int* info) {
int a1,a2,i,j,size, itable=0, info1;
double e1,y,err2,xi1,xi2, f1=0., f2=0., T[11], a[3]={1.,1.,0.}, b[6];
float *cs_data = csdat, *p_cs = protdat;
double *tp=T;
double ej;
double CSmb = 0.0;
e1 = emev;
*info = kopt;
// CHECK if user wants to use specific program (the value of "kopt")
if(kopt == 1) CSmb = wsigma_cc(iz,ia,izf,iaf,emev); // Webber's code IMOS20020502
if(kopt == 2) CSmb = yieldx_cc(iz,ia,izf,iaf,e1); // TS code IMOS20020502
CSmb = max(0.,CSmb);
if(kopt == 1 || kopt == 2) return(CSmb);
a1 = fnuc(iz, ia);
a2 = fnuc(izf,iaf);
// EVALUATED CROSS SECTIONS
if(kopt == 12 || kopt == 22)
{
CSmb = eval_cs(emev,a1,a2,&info1);
if (info1 > 0) return(std::max(0.,CSmb));
kopt--; // if evaluation doesn't exist,
} // try other options
// if user wants, use THE CROSS SECTION FITS
if(kopt == 11 || kopt == 21)
{
// special cases: Be, B - recursion calls
if(izf != 0)
{
// A = 10
if(10 == iaf) // B10 = B10 + C10 = a10 - Be10
{
b[0] = isotope_cs(emev,iz,ia,0,iaf,21,&j);
if(j == -21)
{ // B10
if(510 == a2)
{
b[0]-=isotope_cs(emev,iz,ia,4,iaf,21,&j);
return(std::max(0.,b[0]));
}
if(5 < izf) return(0.); // C10, =0
}
}
// A = 11
if(11 == iaf) // B11 = a11 = Be11 + B11 + C11
{
b[0] = isotope_cs(emev,iz,ia,0,iaf,21,&j);
if(j == -21)
{
if(511 == a2) return(std::max(0.,b[0])); // B11
return(0.); // =0 for the rest
}
}
}
// straight search in the table
for(i=0; i<n_data[1][1]-1; i++, p_cs+=n_data[0][1]) // -1 fixes the reading error in the line below
if(a1 == inuc(*p_cs) && a2 == inuc(*(p_cs+1)))
{
for(p_cs+=2, j=0; j<6; b[j++]=*p_cs++); // take the parameters
if(b[0] >= 0.) // if positive use fit
{
*info=-kopt;
if(emev < b[5]) return(0); // fitting function
b[0]*=(1.+sin(b[1]*pow(log10(emev),1.*b[2]))*exp(-b[3]*(emev-b[4])));
return(std::max(0.,b[0]));
}
kopt = (int)(-b[0]+0.1); // negative b[0] gives kopt
}
if(izf == 0) return(0.);
}
// CHECK if user wants to use specific program (the value of "kopt")
if(kopt == 1) CSmb = wsigma_cc(iz,ia,izf,iaf,emev); // Webber's code IMOS20020502
if(kopt == 2) CSmb = yieldx_cc(iz,ia,izf,iaf,e1); // TS code IMOS20020502
CSmb = max(0.,CSmb);
if(kopt == 1 || kopt == 2) return(CSmb);
// STARTING THE ALGHORITHM
for(i=0; i<11; T[i++] = 0.);
// CHECK the array: cs_data (is there a channel we are looking for ?)
for(size=1, i=0; i<3; size*=n_data[i++][2]);
for(tp = T, i=0; i<size; i+=n_data[0][2], tp = T, f1=0., f2=0.)
{
if(a1 != inuc(*(cs_data+i))) continue;