-
Notifications
You must be signed in to change notification settings - Fork 0
/
d_Wigner_calc.cpp
562 lines (479 loc) · 16.2 KB
/
d_Wigner_calc.cpp
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
//
// main.cpp
// d_Wigner_calc
//
// Created by Deniz Mostarac on 10/07/2017.
// Copyright © 2017 Deniz Mostarac. All rights reserved.
//
#include <iostream>
#include <TFile.h>
#include <TList.h>
#include <TH1D.h>
#include <TF1.h>
#include <vector>
#include "TCanvas.h"
#include <cmath>
#include <TMath.h>
#include <TH2D.h>
#include <cstring>
#include "TWignerd.h"
#include "TSmallWignerd.h"
#include <TGraph.h>
#include <TGraph2D.h>
#include "TComplex.h"
#include <complex>
#include "TStyle.h"
typedef std::vector<std::vector<std::complex<Double_t>>> Matrica;
typedef std::vector<std::vector<Matrica>> matricaMatrice;
// matrix manipulation metods ////////////////////////////////////////////////////////////////////
int noRows(Matrica &m)
{
return m.size();
}
int noColumns(Matrica &m)
{
return m[0].size();
}
bool ifAllowed(Matrica &m1, Matrica &m2)
{
return noColumns(m1) == noRows(m2);
}
Matrica makeMatrix(int no_rows, int no_columns)
{
return Matrica(no_rows, std::vector<std::complex<Double_t>>(no_columns));
}
Matrica multiplyMatrices(Matrica& m1, Matrica &m2)
{
auto m3(makeMatrix(noRows(m1), noColumns(m2)));
for(int i = 0; i < noRows(m1); i++)
for(int j = 0; j < noColumns(m2); j++) {
std::complex<Double_t> suma(0,0);
for(int k = 0; k < noRows(m2); k++) suma += m1[i][k] * m2[k][j]; m3[i][j] = suma;
}
return m3;
}
Matrica multiplyMatrices_alt(Matrica& m1, Matrica &m2,int setting=0)
{
auto m3(makeMatrix(noRows(m1), noColumns(m2)));
for(int i = 0; i < noRows(m1); i++)
for(int j = 0; j < noColumns(m2); j++) {
std::complex<Double_t> suma(0,0);
if(setting==1){
std::cout<< m1[i][j] *m2[i][j]<<" "<<m1[i][j]<<" "<< m2[i][j]<<endl;
}
suma += m1[i][j] * m2[i][j];
m3[i][j] = suma;
}
return m3;
}
void printMatrix(Matrica &m) {
for(int i = 0; i < noRows(m); i++)
{
for(int j = 0; j < noColumns(m); j++)
std::cout << std::setw(10) << m[i][j];
std::cout << std::endl;
} }
bool canBeSummed(Matrica &m1, Matrica &m2)
{
return (noRows(m1) == noRows(m2)) && (noColumns(m1) == noColumns(m2));
}
Matrica addMatrices(Matrica& m1, Matrica& m2)
{
auto m3(makeMatrix(noRows(m1), noColumns(m1))); for(int i = 0; i < noRows(m1); i++)
for(int j = 0; j < noColumns(m1); j++) m3[i][j] = m1[i][j] + m2[i][j]; return m3;
}
///////////////////////////////////////////////////////////////////////////////////////////////
Matrica wig_graph(Int_t l,Int_t m,Int_t n,Int_t L = 1024)
{
// Use this macr to draw a wigner-d function. For more information
// see the classes TWignerd and TSmallWignerd
if (l > L) L = l;
// The number of points on which the function will be sampled
// is 2*L.
const Int_t size = 2*L;
TWignerd wig(l);
wig.Advance(l);
TSmallWignerd smallwd(L);
//printout section
//don't delete "unused" variables, using return by reference!!!
Int_t nDim(0);
Double_t *vecy = smallwd.Get(wig,m,n,nDim);
Double_t *ptrMiddleMan= vecy;
int counter(0);
smallwd.setNoOfElements();
while (counter<smallwd.getNoOfElements()) {
counter++;
}
// container generation and fill
/*idea is to generate a square matrix that will have for each d function,a square matrix of values for 2L theta and phi values*/
Matrica containterTheta;
std::cout<<smallwd.getNoOfElements()<<" length set to containerTheta "<<std::endl;
containterTheta.resize(smallwd.getNoOfElements());
for (auto &element:containterTheta) {
element.resize(1);
}
counter=0;
for (auto &element:containterTheta)
{
for (auto &subElement:element)
{
subElement=(*(ptrMiddleMan+counter));
counter++;
}
}
std::cout<<noRows(containterTheta)<<" number of rows for containerTheta after filling "<<std::endl;
std::cout<<noColumns(containterTheta)<<" number of columns for containerTheta after filling "<<std::endl;
Matrica containterPhi;
containterPhi.resize(smallwd.getNoOfElements());
for (auto &element:containterPhi) {
element.resize(1);
}
Int_t dummyPhi(0);
for (auto &element:containterPhi)
{
for (auto &subElement: element)
{
subElement= std::exp(std::complex<Double_t>(0,m*(2*(TMath::Pi())*(dummyPhi + 1/2)/size)));
dummyPhi++;
}
}
std::cout<<noRows(containterPhi)<<" number of rows for containterPhi after filling "<<std::endl;
std::cout<<noColumns(containterPhi)<<" number of columns for containterPhi after filling "<<std::endl;
/* Here we perform matrix multiplication for one pair of d functions and the presumably complementary phi information.As a chech of the matrices have been properly generated and passed for multiplication, we employ a checker funtion!*/
Matrica aElementMatrix;
aElementMatrix.resize(smallwd.getNoOfElements());
for (auto &element:aElementMatrix) {
element.resize(smallwd.getNoOfElements());
}
for (int i(0); i<noRows(containterPhi); i++)
{
for (auto &element1:containterTheta[i])
{
for (int j(0); j<noRows(containterPhi); j++)
{
for (auto &element2:containterPhi[j])
{
aElementMatrix[i][j]=element1*element2;
}
}
}
}
std::cout<<noRows(aElementMatrix)<<" number of rows for aElementMatrix after filling "<<std::endl;
std::cout<<noColumns(aElementMatrix)<<" number of columns for aElementMatrix after filling "<<std::endl;
return aElementMatrix;
Double_t vecx[size];
for (Int_t j = 0; j < size; ++j)
vecx[j] = TMath::Pi()*(j + 1/2)/size;
}
int sandwichGen(int J,int m,int n, int m_prim,Int_t L = 1024)
{
/////// Canvas preparation and generation, as well as histo declarations! ///////////////
TCanvas* c1= new TCanvas("c1","myhisto",1000,800);
c1->Divide(2);
//TH2D* deadwood1 = new TH2D("deadwood1","a 2D hiato",2048,0,TMath::Pi(),\
// 2048,0,2*(TMath::Pi()));
//TH2D* deadwood2 = new TH2D("deadwood2","a 2D hiatoo",2048,0,TMath::Pi(),\
// 2048,0,2*(TMath::Pi()));
////////// D_matrix generation and fill /////////////////////////////////////////////////
matricaMatrice D_matrix;
D_matrix.resize(2*J+1);
for (auto &element:D_matrix) {
element.resize(1);
}
int cnt(-J);
for (auto &element:D_matrix) {
element[0]=wig_graph(J, cnt,n,L);
cnt++;
std::cout<<"tadaaaa"<<std::endl;
}
///////// transposed_D_matrix generation and fill ///////////////////////////////////////////
matricaMatrice D_matrix_conj;
D_matrix_conj.resize(2*J+1);
for (auto &element:D_matrix_conj) {
element.resize(1);
element[0].resize(2*L);
}
for (auto &element1: D_matrix)
{
for (auto &element2: D_matrix_conj)
{
for (auto &subelement1:element1)
{
for (auto &subelement2:element2)
{
subelement2.resize(subelement1.size());
for (auto &resizer1:subelement1) {
for (auto &resizer2:subelement2) {
resizer2.resize(resizer1.size());
}
}
}
}
}
}
int selector(0);
for (auto &element1: D_matrix)
{
auto& element2=D_matrix_conj[selector];
selector++;
for (auto &subelement1:element1)
{
for (auto &subelement2:element2)
{
for (int i(0); i<noRows(subelement1); i++)
{
for (int j(0); j<noColumns(subelement1); j++)
{
subelement2[i][j]=std::conj(subelement1[i][j]);
}
}
}
}
}
matricaMatrice transposed_D_matrix;
transposed_D_matrix.resize(1);
for (auto &element:transposed_D_matrix) {
element.resize(2*J+1);
}
int browser(0);
for (auto &element:D_matrix_conj) {
transposed_D_matrix[0][browser]=element[0];
browser++;
std::cout<<"lalalalala"<<std::endl;
}
//////// generation of identity matrix of a matrix containing a matrix of all elements 1 ////
std::cout<<"jedinice"<<std::endl;
Matrica jedinice;
jedinice.resize(2*L);
for (auto &element:jedinice) {
element.resize(2*L);
}
for (auto &element:jedinice)
{
for (auto &subElement: element)
{
subElement=std::complex<Double_t>(1,0);
}
}
std::cout<<"id_matrix"<<std::endl;
matricaMatrice id_matrix;
id_matrix.resize(2*J+1);
for (auto &element:id_matrix) {
element.resize(2*J+1);
}
for (int i(0); i<(2*J+1); i++) {
for (int j(0); j<(2*J+1); j++) {
if(i==j)
{
id_matrix[i][j]=jedinice;
}
}
}
std::cout<<"D_matrix_id"<<std::endl;
//////////// doing the sandwich ///////////////////////////////////////////////////////
matricaMatrice D_matrix_id;
D_matrix_id.resize(m_prim);
for (auto &element:D_matrix_id) {
element.resize(1);
}
for (int i(0); i<m_prim; i++) {
for (int j(0); j<m_prim;j++) {
if(i==j)
{
D_matrix_id[i][0]=multiplyMatrices_alt(id_matrix[i][j], D_matrix[i][0]);
}
}
}
std::cout<<"allTogetherReadyForFill"<<std::endl;
int convolutor(0);
Matrica allTogetherReadyForFill;
selector=0;
for (auto &element:D_matrix_id)
{
auto &subelement=D_matrix_conj[selector];
std::cout<<"entered second loop "<<std::endl;
if (convolutor==0)
{
allTogetherReadyForFill=multiplyMatrices_alt(element[0], subelement[0]);
convolutor++;
}
else
{
Matrica privremeni=multiplyMatrices_alt(element[0], subelement[0]);
if (canBeSummed(allTogetherReadyForFill, privremeni))
{
allTogetherReadyForFill=addMatrices(allTogetherReadyForFill, privremeni);
std::cout<<convolutor<<std::endl;
convolutor++;
}
else
{
std::cout<<"huston, we have a problem!!!"<<std::endl;
return 8;
}
}
selector++;
}
////////// print and plot !!! ////////////////////////////////////////////////////////
//printMatrix(allTogetherReadyForFill);
TGraph2D *g1= new TGraph2D(2*L*2*L);
std::ostringstream oss;
oss << "Real Angular Distribution for " << J <<" " << m<<" "<< n;
std::string var1 = oss.str();
const char* foobar1 = var1.c_str();
g1->SetTitle(foobar1);
int iter(0);
Double_t iks, ips;
for (int j(0); j<noRows(allTogetherReadyForFill); j++)
{
iks=(TMath::Pi()*(j + 1/2)/(2*L));
for (int k(0); k<noColumns(allTogetherReadyForFill); k++)
{
ips=(2*(TMath::Pi())*(k + 1/2)/(2*L));
g1->SetPoint(iter,iks, ips, real(allTogetherReadyForFill[j][k]));
iter++;
}
}
c1->cd(1);
gStyle->SetPalette(1);
g1->Draw("surf");
TGraph2D *g2= new TGraph2D(2*L*2*L);
oss.str("");
oss.clear();
oss << "Imaginary Angular Distribution for " << J <<" " << m<<" "<< n;
std::string var2 = oss.str();
const char* foobar2 = var2.c_str();
g2->SetTitle(foobar2);
iter = 0;
for (int j(0); j<noRows(allTogetherReadyForFill); j++)
{
iks=(std::cos(TMath::Pi()*(j + 1/2)/(2*L)));
for (int k(0); k<noColumns(allTogetherReadyForFill); k++)
{
ips=(2*(TMath::Pi())*(k + 1/2)/(2*L));
g2->SetPoint(iter,iks, ips, std::abs(imag(allTogetherReadyForFill[j][k])));
iter++;
}
}
c1->cd(2);
gStyle->SetPalette(1);
g2->Draw("surf");
return 0;
}
void wigner_plotter(Int_t l,Int_t m,Int_t n)
{
TCanvas *canvas = new TCanvas("canvas","Wigned d function",100,10,1000,500);
canvas->Divide(2);
canvas->cd(1);
Int_t L = 256;
if (l > L) L = l;
const Int_t size = 2*L;
TWignerd wig(l);
wig.Advance(l);
TSmallWignerd smallwd(L);
Int_t nDim(0);
Double_t *vecy = smallwd.Get(wig,m,n,nDim);
Double_t *ptrMiddleMan= vecy;
int counter(0);
smallwd.setNoOfElements();
Double_t vecx[size];
for (Int_t j = 0; j < size; ++j)
vecx[j] = TMath::Pi()*(j + 1/2)/size;
TGraph *gr = new TGraph(size,vecx,vecy);
std::ostringstream oss;
oss << "Wigner-d function" << l << m<< n;
std::string var = oss.str();
const char* foobar2 = var.c_str();
gr->SetTitle(foobar2);
gr->SetLineColor(kSpring+3);
gr->SetFillColor(kSpring+3);
gr->SetLineWidth(2);
gr->Draw("ac");
Matrica containterTheta;
std::cout<<smallwd.getNoOfElements()<<" length set to containerTheta "<<std::endl;
containterTheta.resize(smallwd.getNoOfElements());
for (auto &element:containterTheta)
{
element.resize(1);
}
counter=0;
for (auto &element:containterTheta)
{
for (auto &subElement:element)
{
subElement=(*(ptrMiddleMan+counter));
counter++;
}
}
Matrica containterPhi;
containterPhi.resize(smallwd.getNoOfElements());
for (auto &element:containterPhi) {
element.resize(1);
}
Int_t dummyPhi(0);
for (auto &element:containterPhi)
{
for (auto &subElement: element)
{
subElement= std::exp(std::complex<Double_t>(0,m*(2*(TMath::Pi())*(dummyPhi + 1/2)/size)));
dummyPhi++;
}
}
Matrica aElementMatrix;
aElementMatrix.resize(smallwd.getNoOfElements());
for (auto &element:aElementMatrix) {
element.resize(smallwd.getNoOfElements());
}
for (int i(0); i<noRows(containterPhi); i++)
{
for (auto &element1:containterTheta[i])
{
for (int j(0); j<noRows(containterPhi); j++)
{
for (auto &element2:containterPhi[j])
{
aElementMatrix[i][j]=element1*element2;
}
}
}
}
Matrica aElementMatrix_conj;
aElementMatrix_conj.resize(noRows(aElementMatrix));
for (auto &element:aElementMatrix_conj) {
element.resize(noColumns(aElementMatrix));
}
for (int i(0);i<noRows(aElementMatrix);i++) {
for (int j(0); j<noColumns(aElementMatrix); j++) {
aElementMatrix_conj[i][j]=std::conj(aElementMatrix[i][j]);
}
}
Matrica allTogetherReadyForFill;
allTogetherReadyForFill=multiplyMatrices_alt(aElementMatrix, aElementMatrix_conj);
TGraph2D *g1= new TGraph2D(2*L*2*L);
oss.str("");
oss.clear();
oss << "Real Angular Distribution for " << l <<" " << m <<" "<< n;
std::string var1 = oss.str();
const char* foobar1 = var1.c_str();
g1->SetTitle(foobar1);
int iter(0);
Double_t iks, ips;
for (int j(0); j<noRows(allTogetherReadyForFill); j++)
{
iks=(TMath::Pi()*(j + 1/2)/(2*L));
for (int k(0); k<noColumns(allTogetherReadyForFill); k++)
{
ips=(2*(TMath::Pi())*(k + 1/2)/(2*L));
g1->SetPoint(iter,iks, ips, real(allTogetherReadyForFill[j][k]));
iter++;
}
}
canvas->cd(2);
gStyle->SetPalette(1);
g1->Draw("surf");
}
int main()
{
wig_graph(2, -2, 0);
return 0;
}