forked from joaoabcoelho/OscProb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PMNS_Base.cxx
1436 lines (1151 loc) · 36.8 KB
/
PMNS_Base.cxx
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
////////////////////////////////////////////////////////////////////////
//
// Base class for oscillations of neutrinos in matter in a
// n-neutrino framework.
//
//......................................................................
//
//
////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <cassert>
#include <stdlib.h>
#include <algorithm>
#include "PMNS_Base.h"
using namespace std;
using namespace OscProb;
// Some usefule complex numbers
const complexD PMNS_Base::zero(0,0);
const complexD PMNS_Base::one(1,0);
// Define some constants from PDG 2015
const double PMNS_Base::kGeV2eV = 1.0e+09; // GeV to eV conversion
const double PMNS_Base::kKm2eV = 1.0 / 1.973269788e-10; // (hbar.c [eV.km])^-1
const double PMNS_Base::kNA = 6.022140857e23; // Avogadro constant (N_A)
const double PMNS_Base::kK2 = 1e-3 * kNA / pow(kKm2eV,3); // N_A * (hbar*c [GeV.cm])^3 * kGeV2eV
const double PMNS_Base::kGf = 1.1663787e-05; // G_F/(hbar*c)^3 [GeV^-2]
//......................................................................
///
/// Constructor.
///
/// Sets the number of neutrinos and initializes attributes
///
/// Default starts with a 2 GeV muon neutrino.
///
/// Path is set to the default 1000 km in crust density.
///
/// Oscillation parameters are from PDG for NH by default.
///
/// @param numNus - the number of neutrino flavours
///
PMNS_Base::PMNS_Base(int numNus) :
fGotES(false), fBuiltHms(false), fMaxCache(1e6), fProbe(numNus)
{
SetUseCache(false); // Don't cache eigensystems
fNumNus = numNus; // Set the number of neutrinos
SetStdPath(); // Set some default path
SetEnergy(2); // Set default energy to 2 GeV
SetIsNuBar(false); // Neutrino by default
InitializeVectors(); // Initialize all vectors
SetStdPars(); // Set PDG parameters
ResetToFlavour(1); // Numu by default
}
//......................................................................
///
/// Nothing to clean.
///
PMNS_Base::~PMNS_Base(){}
//......................................................................
///
/// Set vector sizes and initialize elements to zero.
///
void PMNS_Base::InitializeVectors()
{
fDm = vector<double>(fNumNus, 0);
fTheta = vector< vector<double> >(fNumNus, vector<double>(fNumNus,0));
fDelta = vector< vector<double> >(fNumNus, vector<double>(fNumNus,0));
fNuState = vector<complexD>(fNumNus, zero);
fHms = vector< vector<complexD> >(fNumNus, vector<complexD>(fNumNus,zero));
fPhases = vector<complexD>(fNumNus, zero);
fBuffer = vector<complexD>(fNumNus, zero);
fEval = vector<double>(fNumNus, 0);
fEvec = vector< vector<complexD> >(fNumNus, vector<complexD>(fNumNus,zero));
}
//......................................................................
///
/// Turn on/off caching of eigensystems.
/// This can save a lot of CPU time by avoiding recomputing eigensystems
/// if we've already seen them recently.
/// Especially useful when running over multiple earth layers and even more
/// if multiple baselines will be computed, e.g. for atmospheric neutrinos.
///
/// @param u - flag to set caching on (default: true)
///
void PMNS_Base::SetUseCache(bool u)
{
fUseCache = u;
}
//......................................................................
///
/// Clear the cache
///
void PMNS_Base::ClearCache()
{
fMixCache.clear();
}
//......................................................................
///
/// Set maximum number of cached eigensystems.
/// Finding eigensystems can become slow and take up memory.
/// This protects the cache from becoming too large.
///
/// @param mc - Max cache size (default: 1e6)
///
void PMNS_Base::SetMaxCache(int mc)
{
fMaxCache = mc;
}
//......................................................................
///
/// Try to find a cached version of this eigensystem.
///
bool PMNS_Base::TryCache()
{
if(fUseCache && !fMixCache.empty()){
fProbe.SetVars(fEnergy, fPath, fIsNuBar);
std::set<EigenPoint>::iterator it = fMixCache.find(fProbe);
if(it != fMixCache.end()){
for(int i=0; i<fNumNus; i++){
fEval[i] = (*it).fEval[i] * (*it).fEnergy / fEnergy;
for(int j=0; j<fNumNus; j++){
fEvec[i][j] = (*it).fEvec[i][j];
}
}
return true;
}
}
return false;
}
//......................................................................
///
/// If using caching, save the eigensystem in memory
///
void PMNS_Base::FillCache()
{
if(fUseCache){
if(fMixCache.size()>fMaxCache){
fMixCache.erase(fMixCache.begin());
fMixCache.erase(--fMixCache.end());
}
for(int i=0; i<fNumNus; i++){
fProbe.fEval[i] = fEval[i];
for(int j=0; j<fNumNus; j++){
fProbe.fEvec[i][j] = fEvec[i][j];
}
}
fMixCache.insert(fProbe);
}
}
//......................................................................
///
/// Set standard oscillation parameters from PDG 2015.
///
/// For two neutrinos, Dm is set to the muon disappearance
/// effective mass-splitting and mixing angle.
///
void PMNS_Base::SetStdPars()
{
if(fNumNus>2){
// PDG values for 3 neutrinos
// Also applicable for 3+N neutrinos
SetAngle(1,2, asin(sqrt(0.304)));
SetAngle(1,3, asin(sqrt(0.0219)));
SetAngle(2,3, asin(sqrt(0.514)));
SetDm(2, 7.53e-5);
SetDm(3, 2.52e-3);
}
else if(fNumNus==2){
// Effective muon disappearance values
// for two-flavour approximation
SetAngle(1,2, 0.788);
SetDm(2, 2.47e-3);
}
}
//......................................................................
///
/// Set standard single path.
///
/// Length is 1000 km, so ~2 GeV peak energy.
///
/// Density is approximate from CRUST2.0 (~2.8 g/cm^3).
/// Z/A is set to a round 0.5.
///
void PMNS_Base::SetStdPath(){
NuPath p;
p.length = 1000; // 1000 km default
p.density = 2.8; // Crust density
p.zoa = 0.5; // Crust Z/A
p.layer = 0; // Single layer
SetPath(p);
}
//......................................................................
///
/// Set neutrino energy in GeV.
///
/// This will check if value is changing to keep track of whether
/// the eigensystem needs to be recomputed.
///
/// @param E - The neutrino energy in GeV
///
void PMNS_Base::SetEnergy(double E)
{
// Check if value is actually changing
fGotES *= (fEnergy == E);
fEnergy = E;
}
//......................................................................
///
/// Set anti-neutrino flag.
///
/// This will check if value is changing to keep track of whether
/// the eigensystem needs to be recomputed.
///
/// @param isNuBar - Set to true for anti-neutrino and false for neutrino.
///
void PMNS_Base::SetIsNuBar(bool isNuBar)
{
// Check if value is actually changing
fGotES *= (fIsNuBar == isNuBar);
fIsNuBar = isNuBar;
}
//......................................................................
///
/// Get the neutrino energy in GeV.
///
double PMNS_Base::GetEnergy() {
return fEnergy;
}
//......................................................................
///
/// Get the anti-neutrino flag.
///
bool PMNS_Base::GetIsNuBar() {
return fIsNuBar;
}
//......................................................................
///
/// Set the path currentlyin use by the class.
///
/// This will be used to know what path to propagate through next.
///
/// It will also check if values are changing to keep track of whether
/// the eigensystem needs to be recomputed.
///
/// @param p - A neutrino path segment
///
void PMNS_Base::SetCurPath(NuPath p)
{
// Check if relevant value are actually changing
fGotES *= (fPath.density == p.density);
fGotES *= (fPath.zoa == p.zoa);
fPath = p;
}
//......................................................................
///
/// Clear the path vector.
///
void PMNS_Base::ClearPath(){
fNuPaths.clear();
}
//......................................................................
///
/// Set vector of neutrino paths.
/// @param paths - A sequence of neutrino paths
///
void PMNS_Base::SetPath(std::vector<NuPath> paths){
fNuPaths=paths;
}
//......................................................................
///
/// Get the vector of neutrino paths.
///
vector<NuPath> PMNS_Base::GetPath(){
return fNuPaths;
}
//......................................................................
///
/// Add a path to the sequence.
/// @param p - A neutrino path segment
///
void PMNS_Base::AddPath(NuPath p){
fNuPaths.push_back(p);
}
//......................................................................
///
/// Add a path to the sequence defining attributes directly.
/// @param length - The length of the path segment in km
/// @param density - The density of the path segment in g/cm^3
/// @param zoa - The effective Z/A of the path segment
/// @param layer - An index to identify the layer type (e.g. earth inner core)
///
void PMNS_Base::AddPath(double length, double density, double zoa, int layer){
AddPath(NuPath(length, density, zoa, layer));
}
//......................................................................
///
/// Set a single path.
///
/// This destroys the current path sequence and creates a new first path.
///
/// @param p - A neutrino path segment
///
void PMNS_Base::SetPath(NuPath p){
ClearPath();
AddPath(p);
}
//......................................................................
///
/// Set a single path defining attributes directly.
///
/// This destroys the current path sequence and creates a new first path.
///
/// @param length - The length of the path segment in km
/// @param density - The density of the path segment in g/cm^3
/// @param zoa - The effective Z/A of the path segment
/// @param layer - An index to identify the layer type (e.g. earth inner core)
///
void PMNS_Base::SetPath(double length, double density, double zoa, int layer){
SetPath(NuPath(length, density, zoa, layer));
}
//......................................................................
///
/// Set some single path attribute.
///
/// An auxiliary function to set individual attributes in a single path.
///
/// If the path sequence is not a single path, a new single path will
/// be created and the previous sequence will be lost. Use with care.
///
/// @param att - The value of the attribute
/// @param idx - The index of the attribute (0,1,2,3) = (L, Rho, Z/A, Layer)
///
void PMNS_Base::SetAtt(double att, int idx){
if(fNuPaths.size() != 1){
cout << "Warning: Clearing path vector and starting new single path." << endl;
cout << "To avoid possible issues, use the SetPath function." << endl;
SetStdPath();
}
switch(idx){
case 0: fNuPaths[0].length = att; break;
case 1: fNuPaths[0].density = att; break;
case 2: fNuPaths[0].zoa = att; break;
case 3: fNuPaths[0].layer = att; break;
}
}
//......................................................................
///
/// Set the length for a single path.
///
/// If the path sequence is not a single path, a new single path will
/// be created and the previous sequence will be lost. Use with care.
///
/// @param L - The length of the path segment in km
///
void PMNS_Base::SetLength(double L){
SetAtt(L, 0);
}
//......................................................................
///
/// Set single path density.
///
/// If the path sequence is not a single path, a new single path will
/// be created and the previous sequence will be lost. Use with care.
///
/// @param rho - The density of the path segment in g/cm^3
///
void PMNS_Base::SetDensity(double rho){
SetAtt(rho, 1);
}
//......................................................................
///
/// Set single path Z/A.
///
/// If the path sequence is not a single path, a new single path will
/// be created and the previous sequence will be lost. Use with care.
///
/// @param zoa - The effective Z/A of the path segment
///
void PMNS_Base::SetZoA(double zoa){
SetAtt(zoa, 2);
}
//......................................................................
///
/// Set all values of a path attribute.
///
/// An auxiliary function to set individual attributes in a path sequence.
///
/// If the path sequence is of a different size, a new path sequence will
/// be created and the previous sequence will be lost. Use with care.
///
/// @param att - The values of the attribute
/// @param idx - The index of the attribute (0,1,2,3) = (L, Rho, Z/A, Layer)
///
void PMNS_Base::SetAtt(std::vector<double> att, int idx){
// Get the sizes of the attribute and
// path sequence vectors
int nA = att.size();
int nP = fNuPaths.size();
// If the vector sizes are equal, update this attribute
if(nA == nP){
for(int i=0; i<nP; i++){
switch(idx){
case 0: fNuPaths[i].length = att[i]; break;
case 1: fNuPaths[i].density = att[i]; break;
case 2: fNuPaths[i].zoa = att[i]; break;
case 3: fNuPaths[i].layer = att[i]; break;
}
}
}
// If the vector sizes differ, create a new path sequence
// and set value for this attribute. Other attributes will
// be taken from default single path.
else{
cout << "Warning: New vector size. Starting new path vector." << endl;
cout << "To avoid possible issues, use the SetPath function." << endl;
// Start a new standard path just
// to set default values
SetStdPath();
// Create a path segment with default values
NuPath p = fNuPaths[0];
// Clear the path sequence
ClearPath();
// Set this particular attribute's value
// and add the path segment to the sequence
for(int i=0; i<nA; i++){
switch(idx){
case 0: p.length = att[i]; break;
case 1: p.density = att[i]; break;
case 2: p.zoa = att[i]; break;
case 3: p.layer = att[i]; break;
}
AddPath(p);
}
}
}
//......................................................................
///
/// Set multiple path lengths.
///
/// If the path sequence is of a different size, a new path sequence will
/// be created and the previous sequence will be lost. Use with care.
///
/// @param L - The lengths of the path segments in km
///
void PMNS_Base::SetLength(std::vector<double> L){
SetAtt(L, 0);
}
//......................................................................
///
/// Set multiple path densities.
///
/// If the path sequence is of a different size, a new path sequence will
/// be created and the previous sequence will be lost. Use with care.
///
/// @param rho - The densities of the path segments in g/cm^3
///
void PMNS_Base::SetDensity(std::vector<double> rho){
SetAtt(rho, 1);
}
//......................................................................
///
/// Set multiple path Z/A values.
///
/// If the path sequence is of a different size, a new path sequence will
/// be created and the previous sequence will be lost. Use with care.
///
/// @param zoa - The effective Z/A of the path segments
///
void PMNS_Base::SetZoA(std::vector<double> zoa){
SetAtt(zoa, 2);
}
//......................................................................
///
/// Set multiple path layer indices.
///
/// If the path sequence is of a different size, a new path sequence will
/// be created and the previous sequence will be lost. Use with care.
///
/// @param lay - Indices to identify the layer types (e.g. earth inner core)
///
void PMNS_Base::SetLayers(std::vector<int> lay){
vector<double> lay_double(lay.begin(), lay.end());
SetAtt(lay_double, 3);
}
//......................................................................
///
/// Set the mixing angle theta_ij in radians.
///
/// Requires that i<j. Will notify you if input is wrong.
/// If i>j, will assume reverse order and swap i and j.
///
/// This will check if value is changing to keep track of whether
/// the hamiltonian needs to be rebuilt.
///
/// @param i,j - the indices of theta_ij
/// @param th - the value of theta_ij
///
void PMNS_Base::SetAngle(int i, int j, double th)
{
if(i>j){
cout << "Warning: First argument should be smaller than second argument" << endl;
cout << " Setting reverse order (Theta" << j << i << "). " << endl;
int temp = i;
i = j;
j = temp;
}
if(i<1 || i>fNumNus-1 || j<2 || j>fNumNus){
cout << "ERROR: Theta" << i << j << " not valid for " << fNumNus;
cout << " neutrinos. Doing nothing." << endl;
return;
}
// Check if value is actually changing
fBuiltHms *= (fTheta[i-1][j-1] == th);
fTheta[i-1][j-1] = th;
}
//......................................................................
///
/// Get the mixing angle theta_ij in radians.
///
/// Requires that i<j. Will notify you if input is wrong.
/// If i>j, will assume reverse order and swap i and j.
///
/// @param i,j - the indices of theta_ij
///
double PMNS_Base::GetAngle(int i, int j)
{
if(i>j){
cout << "Warning: First argument should be smaller than second argument" << endl;
cout << " Setting reverse order (Theta" << j << i << "). " << endl;
int temp = i;
i = j;
j = temp;
}
if(i<1 || i>fNumNus-1 || j<2 || j>fNumNus){
cout << "ERROR: Theta" << i << j << " not valid for " << fNumNus;
cout << " neutrinos. Returning zero." << endl;
return 0;
}
return fTheta[i-1][j-1];
}
//......................................................................
///
/// Set the CP phase delta_ij in radians.
///
/// Requires that i+1<j. Will notify you if input is wrong.
/// If i>j, will assume reverse order and swap i and j.
///
/// This will check if value is changing to keep track of whether
/// the hamiltonian needs to be rebuilt.
///
/// @param i,j - the indices of delta_ij
/// @param delta - the value of delta_ij
///
void PMNS_Base::SetDelta(int i, int j, double delta)
{
if(i>j){
cout << "Warning: First argument should be smaller than second argument" << endl;
cout << " Setting reverse order (Delta" << j << i << "). " << endl;
int temp = i;
i = j;
j = temp;
}
if(i<1 || i>fNumNus-1 || j<2 || j>fNumNus){
cout << "ERROR: Delta" << i << j << " not valid for " << fNumNus;
cout << " neutrinos. Doing nothing." << endl;
return;
}
if(i+1==j){
cout << "Warning: Rotation " << i << j << " is real. Doing nothing." << endl;
return;
}
// Check if value is actually changing
fBuiltHms *= (fDelta[i-1][j-1] == delta);
fDelta[i-1][j-1] = delta;
}
//......................................................................
///
/// Get the CP phase delta_ij in radians.
///
/// Requires that i+1<j. Will notify you if input is wrong.
/// If i>j, will assume reverse order and swap i and j.
///
/// @param i,j - the indices of delta_ij
///
double PMNS_Base::GetDelta(int i, int j)
{
if(i>j){
cout << "Warning: First argument should be smaller than second argument" << endl;
cout << " Setting reverse order (Delta" << j << i << "). " << endl;
int temp = i;
i = j;
j = temp;
}
if(i<1 || i>fNumNus-1 || j<2 || j>fNumNus){
cout << "ERROR: Delta" << i << j << " not valid for " << fNumNus;
cout << " neutrinos. Returning zero." << endl;
return 0;
}
if(i+1==j){
cout << "Warning: Rotation " << i << j << " is real. Returning zero." << endl;
return 0;
}
return fDelta[i-1][j-1];
}
//......................................................................
///
/// Set the mass-splitting dm_j1 = (m_j^2 - m_1^2) in eV^2
///
/// Requires that j>1. Will notify you if input is wrong.
///
/// This will check if value is changing to keep track of whether
/// the hamiltonian needs to be rebuilt.
///
/// @param j - the index of dm_j1
/// @param dm - the value of dm_j1
///
void PMNS_Base::SetDm(int j, double dm)
{
if(j<2 || j>fNumNus){
cout << "ERROR: Dm" << j << "1 not valid for " << fNumNus;
cout << " neutrinos. Doing nothing." << endl;
return;
}
// Check if value is actually changing
fBuiltHms *= (fDm[j-1] == dm);
fDm[j-1] = dm;
}
//......................................................................
///
/// Get the mass-splitting dm_j1 = (m_j^2 - m_1^2) in eV^2
///
/// Requires that j>1. Will notify you if input is wrong.
///
/// @param j - the index of dm_j1
///
double PMNS_Base::GetDm(int j)
{
if(j<2 || j>fNumNus){
cout << "ERROR: Dm" << j << "1 not valid for " << fNumNus;
cout << " neutrinos. Returning zero." << endl;
return 0;
}
return fDm[j-1];
}
//......................................................................
///
/// Get the effective mass-splitting dm_j1 in matter in eV^2
///
/// Requires that j>1. Will notify you if input is wrong.
///
/// @param j - the index of dm_j1
///
double PMNS_Base::GetDmEff(int j)
{
if(j<2 || j>fNumNus){
cout << "ERROR: Dm" << j << "1 not valid for " << fNumNus;
cout << " neutrinos. Returning zero." << endl;
return 0;
}
// Solve the Hamiltonian to update eigenvalues
SolveHam();
// Sort eigenvalues in same order as vacuum Dm^2
vector<int> TrueIdx(fNumNus, 0);
vector<double> TrueVals(fNumNus, 0);
vector<int> EffIdx(fNumNus, 0);
for(int i=0; i<fNumNus; i++){
TrueIdx[i] = i;
EffIdx[i] = i;
}
sort(TrueIdx.begin(), TrueIdx.end(), IdxCompare(fDm));
for(int i=0; i<fNumNus; i++) TrueVals[i] = TrueIdx[i];
sort(TrueIdx.begin(), TrueIdx.end(), IdxCompare(TrueVals));
sort(EffIdx.begin(), EffIdx.end(), IdxCompare(fEval));
// Return eigenvalues * 2E
return (fEval[EffIdx[TrueIdx[j-1]]] - fEval[EffIdx[TrueIdx[0]]]) * fEnergy * 2e9;
}
//......................................................................
///
/// Rotate the Hamiltonian by the angle theta_ij and phase delta_ij.
///
/// The rotations assume all off-diagonal elements with i > j are zero.
/// This is correct if the order of rotations is chosen appropriately
/// and it speeds up computation by skipping null terms
///
/// @param i,j - the indices of the rotation ij
///
void PMNS_Base::RotateH(int i,int j){
// Do nothing if angle is zero
if(fTheta[i][j]==0) return;
double fSinBuffer = sin(fTheta[i][j]);
double fCosBuffer = cos(fTheta[i][j]);
double fHmsBufferD;
complexD fHmsBufferC;
// With Delta
if(i+1<j){
complexD fExpBuffer = complexD(cos(fDelta[i][j]), -sin(fDelta[i][j]));
// General case
if(i>0){
// Top columns
for(int k=0; k<i; k++){
fHmsBufferC = fHms[k][i];
fHms[k][i] *= fCosBuffer;
fHms[k][i] += fHms[k][j] * fSinBuffer * conj(fExpBuffer);
fHms[k][j] *= fCosBuffer;
fHms[k][j] -= fHmsBufferC * fSinBuffer * fExpBuffer;
}
// Middle row and column
for(int k=i+1; k<j; k++){
fHmsBufferC = fHms[k][j];
fHms[k][j] *= fCosBuffer;
fHms[k][j] -= conj(fHms[i][k]) * fSinBuffer * fExpBuffer;
fHms[i][k] *= fCosBuffer;
fHms[i][k] += fSinBuffer * fExpBuffer * conj(fHmsBufferC);
}
// Nodes ij
fHmsBufferC = fHms[i][i];
fHmsBufferD = real(fHms[j][j]);
fHms[i][i] *= fCosBuffer * fCosBuffer;
fHms[i][i] += 2 * fSinBuffer * fCosBuffer * real(fHms[i][j] * conj(fExpBuffer));
fHms[i][i] += fSinBuffer * fHms[j][j] * fSinBuffer;
fHms[j][j] *= fCosBuffer * fCosBuffer;
fHms[j][j] += fSinBuffer * fHmsBufferC * fSinBuffer;
fHms[j][j] -= 2 * fSinBuffer * fCosBuffer * real(fHms[i][j] * conj(fExpBuffer));
fHms[i][j] -= 2 * fSinBuffer * real(fHms[i][j] * conj(fExpBuffer)) * fSinBuffer * fExpBuffer;
fHms[i][j] += fSinBuffer * fCosBuffer * (fHmsBufferD - fHmsBufferC) * fExpBuffer;
}
// First rotation on j (No top columns)
else{
// Middle rows and columns
for(int k=i+1; k<j; k++){
fHms[k][j] = -conj(fHms[i][k]) * fSinBuffer * fExpBuffer;
fHms[i][k] *= fCosBuffer;
}
// Nodes ij
fHmsBufferD = real(fHms[i][i]);
fHms[i][j] = fSinBuffer * fCosBuffer * (fHms[j][j] - fHmsBufferD) * fExpBuffer;
fHms[i][i] *= fCosBuffer * fCosBuffer;
fHms[i][i] += fSinBuffer * fHms[j][j] * fSinBuffer;
fHms[j][j] *= fCosBuffer * fCosBuffer;
fHms[j][j] += fSinBuffer * fHmsBufferD * fSinBuffer;
}
}
// Without Delta (No middle rows or columns: j = i+1)
else{
// General case
if(i>0){
// Top columns
for(int k=0; k<i; k++){
fHmsBufferC = fHms[k][i];
fHms[k][i] *= fCosBuffer;
fHms[k][i] += fHms[k][j] * fSinBuffer;
fHms[k][j] *= fCosBuffer;
fHms[k][j] -= fHmsBufferC * fSinBuffer;
}
// Nodes ij
fHmsBufferC = fHms[i][i];
fHmsBufferD = real(fHms[j][j]);
fHms[i][i] *= fCosBuffer * fCosBuffer;
fHms[i][i] += 2 * fSinBuffer * fCosBuffer * real(fHms[i][j]);
fHms[i][i] += fSinBuffer * fHms[j][j] * fSinBuffer;
fHms[j][j] *= fCosBuffer * fCosBuffer;
fHms[j][j] += fSinBuffer * fHmsBufferC * fSinBuffer;
fHms[j][j] -= 2 * fSinBuffer * fCosBuffer * real(fHms[i][j]);
fHms[i][j] -= 2 * fSinBuffer * real(fHms[i][j]) * fSinBuffer;
fHms[i][j] += fSinBuffer * fCosBuffer * (fHmsBufferD - fHmsBufferC);
}
// First rotation (theta12)
else{
fHms[i][j] = fSinBuffer * fCosBuffer * fHms[j][j];
fHms[i][i] = fSinBuffer * fHms[j][j] * fSinBuffer;
fHms[j][j] *= fCosBuffer * fCosBuffer;
}
}
}
//......................................................................
///
/// Build Hms = H*2E, where H is the Hamiltonian in vacuum on flavour basis
/// and E is the neutrino energy in eV. Hms is effectively the matrix of
/// masses squared.
///
/// This is a hermitian matrix, so only the
/// upper triangular part needs to be filled
///
/// The construction of the Hamiltonian avoids computing terms that
/// are simply zero. This has a big impact in the computation time.
///
void PMNS_Base::BuildHms()
{
// Check if anything changed
if(fBuiltHms) return;
// Tag to recompute eigensystem
fGotES = false;
for(int j=0; j<fNumNus; j++){
// Set mass splitting
fHms[j][j] = fDm[j];
// Reset off-diagonal elements
for(int i=0; i<j; i++){
fHms[i][j] = 0;
}
// Rotate j neutrinos