Garfield++ v1r0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
ViewMedium.cc
Go to the documentation of this file.
1
2#include <iostream>
3#include <string>
4#include <sstream>
5#include <cmath>
6
7#include <TAxis.h>
8
9#include "Plotting.hh"
10#include "Medium.hh"
11#include "ViewMedium.hh"
12
13namespace Garfield {
14
16 : m_debug(false),
17 m_canvas(0),
18 m_hasExternalCanvas(false),
19 m_medium(0),
20 m_eMin(0.),
21 m_eMax(1000.),
22 m_bMin(0.),
23 m_bMax(5.),
24 m_aMin(0.),
25 m_aMax(3.14),
26 m_vMin(0.),
27 m_vMax(0.),
28 m_efield(500.),
29 m_bfield(1.e2),
30 m_angle(0.),
31 m_etolerance(1.),
32 m_btolerance(0.01),
33 m_atolerance(0.05),
34 m_nFunctions(0),
35 m_nGraphs(0) {
36
37 m_className = "ViewMedium";
38
39 m_functions.clear();
40 m_graphs.clear();
42}
43
45
46 if (!m_hasExternalCanvas && m_canvas != 0) delete m_canvas;
47}
48
49void ViewMedium::SetCanvas(TCanvas* c) {
50
51 if (c == 0) return;
52 if (!m_hasExternalCanvas && m_canvas != 0) {
53 delete m_canvas;
54 m_canvas = 0;
55 }
56 m_canvas = c;
57 m_hasExternalCanvas = true;
58}
59
61
62 if (m == 0) {
63 std::cerr << m_className << "::SetMedium:\n";
64 std::cerr << " Medium pointer is null.\n";
65 return;
66 }
67
68 m_medium = m;
69}
70
71void ViewMedium::SetElectricFieldRange(const double emin, const double emax) {
72
73 if (emin >= emax || emin < 0.) {
74 std::cerr << m_className << "::SetElectricFieldRange:\n";
75 std::cerr << " Incorrect field range.\n";
76 return;
77 }
78
79 m_eMin = emin;
80 m_eMax = emax;
81}
82
83void ViewMedium::SetMagneticFieldRange(const double bmin, const double bmax) {
84
85 if (bmin >= bmax || bmin < 0.) {
86 std::cerr << m_className << "::SetMagneticFieldRange:\n";
87 std::cerr << " Incorrect field range.\n";
88 return;
89 }
90
91 m_bMin = bmin;
92 m_bMax = bmax;
93}
94
95void ViewMedium::SetBAngleRange(const double amin, const double amax) {
96
97 if (amin >= amax || amin < 0.) {
98 std::cerr << m_className << "::SetBAngleRange:\n";
99 std::cerr << " Incorrect field range.\n";
100 return;
101 }
102
103 m_aMin = amin;
104 m_aMax = amax;
105}
106
107void ViewMedium::SetFunctionRange(const double vmin, const double vmax) {
108
109 if (vmin >= vmax || vmin < 0.) {
110 std::cerr << m_className << "::SetFunctionRange:\n";
111 std::cerr << " Incorrect range.\n";
112 return;
113 }
114
115 m_vMin = vmin;
116 m_vMax = vmax;
117}
118
119void ViewMedium::SetFunctionRange() { m_vMin = m_vMax = 0.; }
120
121void ViewMedium::PlotElectronVelocity(const char xaxis, const double e,
122 const double b, const double a) {
123
124 bool keep = false;
125 SetupCanvas();
126 double min = 0., max = 0.;
127 std::string title = "";
128 if (xaxis == 'e') {
129 title = "electric field [V/cm]";
130 min = m_eMin;
131 max = m_eMax;
132 } else if (xaxis == 'b') {
133 title = "magnetic field [T]";
134 min = m_bMin;
135 max = m_bMax;
136 } else if (xaxis == 'a') {
137 title = "magnetic field angle [rad]";
138 min = m_aMin;
139 max = m_aMax;
140 }
141 AddFunction(min, max, m_vMin, m_vMax, keep, title, "drift velocity [cm/ns]",
142 0, xaxis, e, b, a);
143 keep = true;
144 AddFunction(min, max, m_vMin, m_vMax, keep, title, "drift velocity [cm/ns]",
145 23, xaxis, e, b, a);
146 keep = true;
147 AddFunction(min, max, m_vMin, m_vMax, keep, title, "drift velocity [cm/ns]",
148 24, xaxis, e, b, a);
149 m_canvas->Update();
150}
151
152void ViewMedium::PlotHoleVelocity(const char xaxis, const double e,
153 const double b, const double a) {
154
155 bool keep = false;
156 SetupCanvas();
157 double min = 0., max = 0.;
158 std::string title = "";
159 if (xaxis == 'e') {
160 title = "electric field [V/cm]";
161 min = m_eMin;
162 max = m_eMax;
163 } else if (xaxis == 'b') {
164 title = "magnetic field [T]";
165 min = m_bMin;
166 max = m_bMax;
167 } else if (xaxis == 'a') {
168 title = "magnetic field angle [rad]";
169 min = m_aMin;
170 max = m_aMax;
171 }
172 AddFunction(min, max, m_vMin, m_vMax, keep, title,
173 "drift velocity [cm/ns]", 10, xaxis, e, b, a);
174 keep = true;
175 AddFunction(min, max, m_vMin, m_vMax, keep, title,
176 "drift velocity [cm/ns]", 25, xaxis, e, b, a);
177 keep = true;
178 AddFunction(min, max, m_vMin, m_vMax, keep, title,
179 "drift velocity [cm/ns]", 26, xaxis, e, b, a);
180 m_canvas->Update();
181}
182
183void ViewMedium::PlotIonVelocity(const char xaxis, const double e,
184 const double b, const double a) {
185
186 bool keep = false;
187 SetupCanvas();
188 AddFunction(m_eMin, m_eMax, m_vMin, m_vMax, keep, "electric field [V/cm]",
189 "drift velocity [cm/ns]", 20, xaxis, e, b, a);
190 m_canvas->Update();
191}
192
193void ViewMedium::PlotElectronDiffusion(const char xaxis, const double e,
194 const double b, const double a) {
195
196 bool keep = false;
197 SetupCanvas();
198 AddFunction(m_eMin, m_eMax, m_vMin, m_vMax, keep, "electric field [V/cm]",
199 "diffusion coefficient [#sqrt{cm}]", 1, xaxis, e, b, a);
200 keep = true;
201 AddFunction(m_eMin, m_eMax, m_vMin, m_vMax, keep, "electric field [V/cm]",
202 "diffusion coefficient [#sqrt{cm}]", 2, xaxis, e, b, a);
203
204 m_canvas->Update();
205}
206
207void ViewMedium::PlotHoleDiffusion(const char xaxis, const double e,
208 const double b, const double a) {
209
210 bool keep = false;
211 SetupCanvas();
212 AddFunction(m_eMin, m_eMax, m_vMin, m_vMax, keep, "electric field [V/cm]",
213 "diffusion coefficient [#sqrt{cm}]", 11, xaxis, e, b, a);
214 keep = true;
215 AddFunction(m_eMin, m_eMax, m_vMin, m_vMax, keep, "electric field [V/cm]",
216 "diffusion coefficient [#sqrt{cm}]", 12, xaxis, e, b, a);
217 m_canvas->Update();
218}
219
220void ViewMedium::PlotIonDiffusion(const char xaxis, const double e,
221 const double b, const double a) {
222
223 bool keep = false;
224 SetupCanvas();
225 AddFunction(m_eMin, m_eMax, m_vMin, m_vMax, keep, "electric field [V/cm]",
226 "diffusion coefficient [#sqrt{cm}]", 21, xaxis, e, b, a);
227 keep = true;
228 AddFunction(m_eMin, m_eMax, m_vMin, m_vMax, keep, "electric field [V/cm]",
229 "diffusion coefficient [#sqrt{cm}]", 22, xaxis, e, b, a);
230 m_canvas->Update();
231}
232
233void ViewMedium::PlotElectronTownsend(const char xaxis, const double e,
234 const double b, const double a) {
235
236 bool keep = false;
237 SetupCanvas();
238 AddFunction(m_eMin, m_eMax, 0., 0., keep, "electric field [V/cm]",
239 "Townsend coefficient [1/cm]", 3, xaxis, e, b, a);
240 m_canvas->Update();
241}
242
243void ViewMedium::PlotHoleTownsend(const char xaxis, const double e,
244 const double b, const double a) {
245
246 bool keep = false;
247 SetupCanvas();
248 AddFunction(m_eMin, m_eMax, 0., 0., keep, "electric field [V/cm]",
249 "Townsend coefficient [1/cm]", 13, xaxis, e, b, a);
250 m_canvas->Update();
251}
252
253void ViewMedium::PlotElectronAttachment(const char xaxis, const double e,
254 const double b, const double a) {
255
256 bool keep = false;
257 SetupCanvas();
258 AddFunction(m_eMin, m_eMax, 0., 0., keep, "electric field [V/cm]",
259 "Attachment coefficient [1/cm]", 4, xaxis, e, b, a);
260 m_canvas->Update();
261}
262
263void ViewMedium::PlotHoleAttachment(const char xaxis, const double e,
264 const double b, const double a) {
265
266 bool keep = false;
267 SetupCanvas();
268 AddFunction(m_eMin, m_eMax, 0., 0., keep, "electric field [V/cm]",
269 "Attachment coefficient [1/cm]", 14, xaxis, e, b, a);
270 m_canvas->Update();
271}
272
274
275 std::cerr << m_className << "::PlotElectronCrossSections:\n";
276 std::cerr << " Function not yet implemented.\n";
277 SetupCanvas();
278}
279
280void ViewMedium::SetupCanvas() {
281
282 if (m_canvas == 0) {
283 m_canvas = new TCanvas();
284 m_canvas->SetTitle("Medium View");
285 if (m_hasExternalCanvas) m_hasExternalCanvas = false;
286 }
287 m_canvas->cd();
288 gPad->SetLeftMargin(0.15);
289}
290
291void ViewMedium::AddFunction(const double xmin, const double xmax,
292 const double ymin, const double ymax,
293 const bool keep, const std::string xlabel,
294 const std::string ylabel, const int type,
295 const char xaxis, const double e, const double b,
296 const double a) {
297
298 // Make sure the medium pointer is set.
299 if (m_medium == 0) {
300 std::cerr << m_className << "::AddFunction:\n";
301 std::cerr << " Medium is not defined.\n";
302 return;
303 }
304
305 // Look for an unused function name.
306 int idx = 0;
307 std::string fname = "fMediumView_0";
308 while (gROOT->GetListOfFunctions()->FindObject(fname.c_str())) {
309 ++idx;
310 std::stringstream ss;
311 ss << "fMediumView_";
312 ss << idx;
313 fname = ss.str();
314 }
315 if (m_debug) {
316 std::cout << m_className << "::AddFunction:\n";
317 std::cout << " Adding function " << fname << "\n";
318 }
319 if (!keep) {
320 m_functions.clear();
321 m_nFunctions = 0;
322 m_graphs.clear();
323 m_nGraphs = 0;
324 }
325
326 // Set global variables used later on (effectively we will only use two)
327 m_efield = e;
328 m_bfield = b;
329 m_angle = a;
330
331 // Create a TF1 and add it to the list of functions.
332 TF1 fNew(fname.c_str(), this, &ViewMedium::EvaluateFunction, xmin, xmax, 2,
333 "ViewMedium", "EvaluateFunction");
334 fNew.SetNpx(1000);
335 m_functions.push_back(fNew);
336 ++m_nFunctions;
337
338 const std::string title = m_medium->GetName() + ";" + xlabel + ";" + ylabel;
339 m_functions.back().SetRange(xmin, xmax);
340 if ((fabs(ymax - ymin) > 0.)) {
341 m_functions.back().SetMinimum(ymin);
342 m_functions.back().SetMaximum(ymax);
343 }
344 m_functions.back().GetXaxis()->SetTitle(xlabel.c_str());
345 m_functions.back().GetXaxis()->SetTitleOffset(1.2);
346 m_functions.back().GetYaxis()->SetTitle(ylabel.c_str());
347 m_functions.back().SetTitle(title.c_str());
348 m_functions.back().SetParameter(0, type);
349 m_functions.back().SetParameter(1, xaxis);
350 // Set the color and marker style.
351 int color;
352 int marker = 20;
353 if (type == 2 || type == 4) {
355 } else if (type == 12 || type == 14 || type == 22) {
357 } else if (type < 10) {
359 } else if (type == 23) {
360 color = kGreen;
361 } else if (type == 24) {
362 color = kRed;
363 } else if (type < 20 || type == 25 || type == 26) {
365 } else {
367 }
368 m_functions.back().SetLineColor(color);
369 // Get the field grid.
370 std::vector<double> efields;
371 std::vector<double> bfields;
372 std::vector<double> bangles;
373 m_medium->GetFieldGrid(efields, bfields, bangles);
374 const int nEfields = efields.size();
375 const int nBfields = bfields.size();
376 const int nBangles = bangles.size();
377 bool withGraph = true;
378
379 if (nEfields <= 0 || nBfields <= 0 || nBangles <= 0) {
380 withGraph = false;
381 }
382
383 if (withGraph) {
384 int n = 0;
385 TGraph graph;
386 if (xaxis == 'e') { // plot with respect to E field
387 graph.Set(nEfields);
388 n = nEfields;
389 } else if (xaxis == 'b') { // plot wrt B field
390 graph.Set(nBfields);
391 n = nBfields;
392 } else if (xaxis == 'a') { // plot wrt angle
393 graph.Set(nBangles);
394 n = nBangles;
395 } else {
396 std::cerr << m_className << "::AddFunction:\n";
397 std::cerr << " Error specifying X-axis.\n";
398 std::cerr << " Invalid parameter type.\n";
399 return;
400 }
401 graph.SetMarkerStyle(marker);
402 graph.SetMarkerColor(color);
403 bool ok = true;
404
405 int epoint = -1;
406 int bpoint = -1;
407 int apoint = -1;
408 // if one of these stays -1, this means there is no corresponding point in
409 // the table
410
411 // search for matching point in table with a certain accuracy
412 for (int i = 0; i < n; ++i) {
413 if (fabs(efields[i] - m_efield) <= m_etolerance) {
414 epoint = i;
415 break;
416 }
417 }
418 for (int i = 0; i < n; ++i) {
419 if (fabs(bfields[i] - m_bfield) <= m_btolerance) {
420 bpoint = i;
421 break;
422 }
423 }
424 for (int i = 0; i < n; ++i) {
425 if (fabs(bangles[i] - m_angle) <= m_atolerance) {
426 apoint = i;
427 break;
428 }
429 }
430 if ((xaxis == 'e' && (bpoint == -1 || apoint == -1)) ||
431 (xaxis == 'b' && (epoint == -1 || apoint == -1)) ||
432 (xaxis == 'a' && (epoint == -1 || bpoint == -1)))
433 ok = false;
434
435 for (int i = 0; i < n; ++i) {
436 double value = 0.;
437 // auxiliary variables
438 double alongx = 0, alongy = 0., alongz = 0.;
439 if (!ok) {
440 withGraph = false;
441 break;
442 }
443 switch (type) {
444 case 0:
445 // Electron drift velocity along E
446 if (xaxis == 'e')
447 ok = m_medium->GetElectronVelocityE(i, bpoint, apoint, value);
448 else if (xaxis == 'b')
449 ok = m_medium->GetElectronVelocityE(epoint, i, apoint, value);
450 else if (xaxis == 'a')
451 ok = m_medium->GetElectronVelocityE(epoint, bpoint, i, value);
452 else
453 value = 0.;
454 value = m_medium->ScaleVelocity(value);
455 break;
456 case 1:
457 // Electron transverse diffusion
458 ok = m_medium->GetElectronTransverseDiffusion(i, bpoint, apoint,
459 value);
460 value = m_medium->ScaleDiffusion(value);
461 break;
462 case 2:
463 // Electron longitudinal diffusion
464 ok = m_medium->GetElectronLongitudinalDiffusion(i, bpoint, apoint,
465 value);
466 value = m_medium->ScaleDiffusion(value);
467 break;
468 case 3:
469 // Electron Townsend coefficient
470 ok = m_medium->GetElectronTownsend(i, bpoint, apoint, value);
471 value = m_medium->ScaleTownsend(exp(value));
472 break;
473 case 4:
474 // Electron attachment coefficient
475 ok = m_medium->GetElectronAttachment(i, bpoint, apoint, value);
476 value = m_medium->ScaleAttachment(exp(value));
477 break;
478 case 10:
479 // Hole drift velocity along E
480 ok = m_medium->GetHoleVelocityE(i, bpoint, apoint, value);
481 value = m_medium->ScaleVelocity(value);
482 break;
483 case 11:
484 // Hole transverse diffusion
485 ok = m_medium->GetHoleTransverseDiffusion(i, bpoint, apoint, value);
486 value = m_medium->ScaleDiffusion(value);
487 break;
488 case 12:
489 // Hole longitudinal diffusion
490 ok = m_medium->GetHoleLongitudinalDiffusion(i, bpoint, apoint, value);
491 value = m_medium->ScaleDiffusion(value);
492 break;
493 case 13:
494 // Hole Townsend coefficient
495 ok = m_medium->GetHoleTownsend(i, bpoint, apoint, value);
496 value = m_medium->ScaleTownsend(exp(value));
497 break;
498 case 14:
499 // Hole attachment coefficient
500 ok = m_medium->GetHoleAttachment(i, bpoint, apoint, value);
501 value = m_medium->ScaleAttachment(exp(value));
502 break;
503 case 20:
504 // Ion drift velocity
505 ok = m_medium->GetIonMobility(i, bpoint, apoint, value);
506 value *= m_medium->UnScaleElectricField(efields[i]);
507 break;
508 case 21:
509 // Ion transverse diffusion
510 ok = m_medium->GetIonTransverseDiffusion(i, bpoint, apoint, value);
511 value = m_medium->ScaleDiffusion(value);
512 break;
513 case 22:
514 // Ion longitudinal diffusion
515 ok = m_medium->GetIonLongitudinalDiffusion(i, bpoint, apoint, value);
516 value = m_medium->ScaleDiffusion(value);
517 break;
518 case 23:
519 // Electron drift velocity along B
520 if (xaxis == 'e')
521 ok = m_medium->ElectronVelocity(efields[i] * cos(bangles[apoint]),
522 efields[i] * sin(bangles[apoint]),
523 0, bfields[bpoint], 0, 0, value,
524 alongy, alongz);
525 else if (xaxis == 'b')
526 ok = m_medium->ElectronVelocity(
527 efields[epoint] * cos(bangles[apoint]),
528 efields[epoint] * sin(bangles[apoint]), 0, bfields[i], 0, 0,
529 value, alongy, alongz);
530 else if (xaxis == 'a') {
531 ok = m_medium->ElectronVelocity(efields[epoint] * cos(bangles[i]),
532 efields[epoint] * sin(bangles[i]),
533 0, bfields[bpoint], 0, 0, value,
534 alongy, alongz);
535 } else
536 value = 0.;
537 value = fabs(m_medium->ScaleVelocity(value));
538 break;
539 case 24:
540 // Electron drift velocity along ExB
541 if (xaxis == 'e')
542 ok = m_medium->ElectronVelocity(efields[i] * cos(bangles[apoint]),
543 efields[i] * sin(bangles[apoint]),
544 0, bfields[bpoint], 0, 0, alongx,
545 alongy, value);
546 else if (xaxis == 'b')
547 ok = m_medium->ElectronVelocity(
548 efields[epoint] * cos(bangles[apoint]),
549 efields[epoint] * sin(bangles[apoint]), 0, bfields[i], 0, 0,
550 alongx, alongy, value);
551 else if (xaxis == 'a')
552 ok = m_medium->ElectronVelocity(
553 m_efield * cos(bangles[i]), m_efield * sin(bangles[i]), 0,
554 m_bfield, 0, 0, alongx, alongy, value);
555 else
556 value = 0.;
557 value = fabs(m_medium->ScaleVelocity(value));
558 break;
559 case 25:
560 // Hole drift velocity along B
561 if (xaxis == 'e')
562 ok = m_medium->HoleVelocity(efields[i] * cos(bangles[apoint]),
563 efields[i] * sin(bangles[apoint]), 0,
564 bfields[bpoint], 0, 0, value, alongy,
565 alongz);
566 else if (xaxis == 'b')
567 ok = m_medium->HoleVelocity(efields[epoint] * cos(bangles[apoint]),
568 efields[epoint] * sin(bangles[apoint]),
569 0, bfields[i], 0, 0, value, alongy,
570 alongz);
571 else if (xaxis == 'a')
572 ok = m_medium->HoleVelocity(efields[epoint] * cos(bangles[i]),
573 efields[epoint] * sin(bangles[i]), 0,
574 bfields[bpoint], 0, 0, value, alongy,
575 alongz);
576 break;
577 case 26:
578 // Hole velocity along ExB
579 if (xaxis == 'e')
580 ok = m_medium->HoleVelocity(efields[i] * cos(bangles[apoint]),
581 efields[i] * sin(bangles[apoint]), 0,
582 bfields[bpoint], 0, 0, alongx, alongy,
583 value);
584 else if (xaxis == 'b')
585 ok = m_medium->HoleVelocity(efields[epoint] * cos(bangles[apoint]),
586 efields[epoint] * sin(bangles[apoint]),
587 0, bfields[i], 0, 0, alongx, alongy,
588 value);
589 else if (xaxis == 'a')
590 ok = m_medium->HoleVelocity(m_efield * cos(bangles[i]),
591 m_efield * sin(bangles[i]), 0, m_bfield,
592 0, 0, alongx, alongy, value);
593 else
594 value = 0.;
595 value = fabs(m_medium->ScaleVelocity(value));
596 break;
597 }
598 if (xaxis == 'e')
599 graph.SetPoint(i, m_medium->UnScaleElectricField(efields[i]), value);
600 else if (xaxis == 'b')
601 graph.SetPoint(i, bfields[i], value);
602 else if (xaxis == 'a')
603 graph.SetPoint(i, bangles[i], value);
604 }
605 if (ok) {
606 m_graphs.push_back(graph);
607 ++m_nGraphs;
608 } else {
609 std::cerr << m_className << "::AddFunction:\n";
610 std::cerr << " Error retrieving data table.\n";
611 std::cerr << " Suppress plotting of graph.\n";
612 }
613 }
614
615 if (keep && m_nFunctions > 1) {
616 m_functions[0].GetYaxis()->SetTitleOffset(1.5);
617 m_functions[0].Draw("");
618 for (int i = 1; i < m_nFunctions; ++i) {
619 m_functions[i].Draw("lsame");
620 }
621 } else {
622 m_functions.back().GetYaxis()->SetTitleOffset(1.5);
623 m_functions.back().Draw("");
624 }
625 if (m_nGraphs > 0) {
626 for (int i = 0; i < m_nGraphs; ++i) {
627 m_graphs[i].Draw("p");
628 }
629 }
630}
631
632double ViewMedium::EvaluateFunction(double* pos, double* par) {
633 // to be modified to include B and angle
634
635 if (m_medium == 0) return 0.;
636 int type = int(par[0]);
637 char xaxis = char(par[1]);
638 const double x = pos[0];
639 double y = 0.;
640
641 // Auxiliary variables
642 double value = 0., a = 0., b = 0., c = 0., alongx = 0., alongy = 0.,
643 alongz = 0.;
644
645 switch (type) {
646 case 0:
647 // Electron drift velocity
648 if (xaxis == 'e') { // plot with respect to E field
649 if (!m_medium->ElectronVelocity(x, 0, 0, m_bfield * cos(m_angle),
650 m_bfield * sin(m_angle), 0, a, b, c))
651 return 0.;
652 } else if (xaxis == 'b') { // plot wrt B field
653 if (!m_medium->ElectronVelocity(m_efield, 0, 0, x * cos(m_angle),
654 x * sin(m_angle), 0, a, b, c))
655 return 0.;
656 } else if (xaxis == 'a') { // plot wrt angle
657 if (!m_medium->ElectronVelocity(m_efield, 0, 0, m_bfield * cos(x),
658 m_bfield * sin(x), 0, a, b, c))
659 return 0.;
660 }
661 y = fabs(a);
662 break;
663 case 1:
664 // Electron transverse diffusion
665 if (!m_medium->ElectronDiffusion(x, 0, 0, 0, 0, 0, a, b)) return 0.;
666 y = b;
667 break;
668 case 2:
669 // Electron longitudinal diffusion
670 if (!m_medium->ElectronDiffusion(x, 0, 0, 0, 0, 0, a, b)) return 0.;
671 y = a;
672 break;
673 case 3:
674 // Electron Townsend coefficient
675 if (!m_medium->ElectronTownsend(x, 0, 0, 0, 0, 0, a)) return 0.;
676 y = a;
677 break;
678 case 4:
679 // Electron attachment coefficient
680 if (!m_medium->ElectronAttachment(x, 0, 0, 0, 0, 0, a)) return 0.;
681 y = a;
682 break;
683 case 10:
684 // Hole drift velocity
685 if (!m_medium->HoleVelocity(x, 0, 0, 0, 0, 0, a, b, c)) return 0.;
686 y = a;
687 break;
688 case 11:
689 // Hole transverse diffusion
690 if (!m_medium->HoleDiffusion(x, 0, 0, 0, 0, 0, a, b)) return 0.;
691 y = b;
692 break;
693 case 12:
694 // Hole longitudinal diffusion
695 if (!m_medium->HoleDiffusion(x, 0, 0, 0, 0, 0, a, b)) return 0.;
696 y = a;
697 break;
698 case 13:
699 // Hole Townsend coefficient
700 if (!m_medium->HoleTownsend(x, 0, 0, 0, 0, 0, a)) return 0.;
701 y = a;
702 break;
703 case 14:
704 // Hole attachment coefficient
705 if (!m_medium->HoleAttachment(x, 0, 0, 0, 0, 0, a)) return 0.;
706 y = a;
707 break;
708 case 20:
709 // Ion drift velocity
710 if (!m_medium->IonVelocity(x, 0, 0, 0, 0, 0, a, b, c)) return 0.;
711 y = fabs(a);
712 break;
713 case 21:
714 // Ion transverse diffusion
715 if (!m_medium->IonDiffusion(x, 0, 0, 0, 0, 0, a, b)) return 0.;
716 y = b;
717 break;
718 case 22:
719 // Ion longitudinal diffusion
720 if (!m_medium->IonDiffusion(x, 0, 0, 0, 0, 0, a, b)) return 0.;
721 y = a;
722 break;
723 case 23:
724 // Electron drift velocity along B
725 if (xaxis == 'e') { // plot with respect to E field
726 if (!m_medium->ElectronVelocity(x * cos(m_angle), x * sin(m_angle), 0,
727 m_bfield, 0, 0, value, alongy, alongz))
728 return 0.;
729 } else if (xaxis == 'b') { // plot wrt B field
730 if (!m_medium->ElectronVelocity(m_efield * cos(m_angle),
731 m_efield * sin(m_angle), 0, x, 0, 0,
732 value, alongy, alongz))
733 return 0.;
734 } else if (xaxis == 'a') { // plot wrt angle
735 if (!m_medium->ElectronVelocity(m_efield * cos(x), m_efield * sin(x), 0,
736 m_bfield, 0, 0, value, alongy, alongz))
737 return 0.;
738 }
739 y = fabs(value);
740 break;
741 case 24:
742 // Electron drift velocity along ExB
743 if (xaxis == 'e') { // plot with respect to E field
744 if (!m_medium->ElectronVelocity(x * cos(m_angle), x * sin(m_angle), 0,
745 m_bfield, 0, 0, alongx, alongy, value))
746 return 0.;
747 } else if (xaxis == 'b') { // plot wrt B field
748 if (!m_medium->ElectronVelocity(m_efield * cos(m_angle),
749 m_efield * sin(m_angle), 0, x, 0, 0,
750 alongx, alongy, value))
751 return 0.;
752 } else if (xaxis == 'a') { // plot wrt angle
753 if (!m_medium->ElectronVelocity(m_efield * cos(x), m_efield * sin(x), 0,
754 m_bfield, 0, 0, alongx, alongy, value))
755 return 0.;
756 }
757 y = fabs(value);
758 break;
759 case 25:
760 // Hole drift velocity along B
761 if (xaxis == 'e') { // plot with respect to E field
762 if (!m_medium->HoleVelocity(x * cos(m_angle), x * sin(m_angle), 0,
763 m_bfield, 0, 0, value, alongy, alongz))
764 return 0.;
765 } else if (xaxis == 'b') { // plot wrt B field
766 if (!m_medium->HoleVelocity(m_efield * cos(m_angle),
767 m_efield * sin(m_angle), 0, x, 0, 0, value,
768 alongy, alongz))
769 return 0.;
770 } else if (xaxis == 'a') { // plot wrt angle
771 if (!m_medium->HoleVelocity(m_efield * cos(x), m_efield * sin(x), 0,
772 m_bfield, 0, 0, value, alongy, alongz))
773 return 0.;
774 }
775 y = fabs(value);
776 break;
777 case 26:
778 // Hole drift velocity along ExB
779 if (xaxis == 'e') { // plot with respect to E field
780 if (!m_medium->HoleVelocity(x * cos(m_angle), x * sin(m_angle), 0,
781 m_bfield, 0, 0, alongx, alongy, value))
782 return 0.;
783 } else if (xaxis == 'b') { // plot wrt B field
784 if (!m_medium->HoleVelocity(m_efield * cos(m_angle),
785 m_efield * sin(m_angle), 0, x, 0, 0, alongx,
786 alongy, value))
787 return 0.;
788 } else if (xaxis == 'a') { // plot wrt angle
789 if (!m_medium->HoleVelocity(m_efield * cos(x), m_efield * sin(x), 0,
790 m_bfield, 0, 0, alongx, alongy, value))
791 return 0.;
792 }
793 y = fabs(value);
794 break;
795 default:
796 std::cerr << m_className << "::EvaluateFunction:\n";
797 std::cerr << " Unknown type of transport coefficient requested.\n";
798 std::cerr << " Program bug!\n";
799 return 0.;
800 }
801
802 return y;
803}
804}
DoubleAc cos(const DoubleAc &f)
Definition: DoubleAc.cpp:431
DoubleAc sin(const DoubleAc &f)
Definition: DoubleAc.cpp:383
DoubleAc exp(const DoubleAc &f)
Definition: DoubleAc.cpp:376
DoubleAc fabs(const DoubleAc &f)
Definition: DoubleAc.h:616
bool GetHoleVelocityE(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &v)
Definition: Medium.cc:2065
bool GetElectronTransverseDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dt)
Definition: Medium.cc:1992
virtual bool HoleTownsend(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &alpha)
Definition: Medium.cc:1079
virtual double ScaleDiffusion(const double &d) const
Definition: Medium.hh:258
bool GetIonLongitudinalDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dl)
Definition: Medium.cc:2256
virtual bool HoleVelocity(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &vx, double &vy, double &vz)
Definition: Medium.cc:773
bool GetElectronTownsend(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &alpha)
Definition: Medium.cc:2017
bool GetIonTransverseDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dt)
Definition: Medium.cc:2280
virtual double ScaleAttachment(const double &eta) const
Definition: Medium.hh:261
virtual bool ElectronVelocity(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &vx, double &vy, double &vz)
Definition: Medium.cc:217
virtual bool IonVelocity(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &vx, double &vy, double &vz)
Definition: Medium.cc:1211
virtual double UnScaleElectricField(const double &e) const
Definition: Medium.hh:256
virtual bool ElectronDiffusion(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &dl, double &dt)
Definition: Medium.cc:388
virtual double ScaleVelocity(const double &v) const
Definition: Medium.hh:257
void GetFieldGrid(std::vector< double > &efields, std::vector< double > &bfields, std::vector< double > &angles)
Definition: Medium.cc:1886
virtual bool ElectronTownsend(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &alpha)
Definition: Medium.cc:542
bool GetHoleTransverseDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dt)
Definition: Medium.cc:2161
virtual bool ElectronAttachment(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &eta)
Definition: Medium.cc:609
bool GetElectronLongitudinalDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dl)
Definition: Medium.cc:1967
bool GetHoleAttachment(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &eta)
Definition: Medium.cc:2209
virtual bool HoleDiffusion(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &dl, double &dt)
Definition: Medium.cc:928
bool GetHoleLongitudinalDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dl)
Definition: Medium.cc:2137
bool GetElectronAttachment(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &eta)
Definition: Medium.cc:2041
bool GetHoleTownsend(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &alpha)
Definition: Medium.cc:2185
virtual double ScaleTownsend(const double &alpha) const
Definition: Medium.hh:260
bool GetElectronVelocityE(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &v)
Definition: Medium.cc:1895
std::string GetName() const
Definition: Medium.hh:22
virtual bool HoleAttachment(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &eta)
Definition: Medium.cc:1144
virtual bool IonDiffusion(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &dl, double &dt)
Definition: Medium.cc:1268
bool GetIonMobility(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &mu)
Definition: Medium.cc:2233
double EvaluateFunction(double *pos, double *par)
Definition: ViewMedium.cc:632
void PlotElectronVelocity(const char xaxis, const double e, const double b, const double a)
Definition: ViewMedium.cc:121
void PlotHoleDiffusion(const char xaxis, const double e, const double b, const double a)
Definition: ViewMedium.cc:207
void PlotElectronTownsend(const char xaxis, const double e, const double b, const double a)
Definition: ViewMedium.cc:233
void SetMedium(Medium *m)
Definition: ViewMedium.cc:60
void SetElectricFieldRange(const double emin, const double emax)
Definition: ViewMedium.cc:71
void PlotElectronAttachment(const char xaxis, const double e, const double b, const double a)
Definition: ViewMedium.cc:253
void PlotElectronDiffusion(const char xaxis, const double e, const double b, const double a)
Definition: ViewMedium.cc:193
void PlotElectronCrossSections()
Definition: ViewMedium.cc:273
void SetCanvas(TCanvas *c)
Definition: ViewMedium.cc:49
void PlotHoleVelocity(const char xaxis, const double e, const double b, const double a)
Definition: ViewMedium.cc:152
void SetMagneticFieldRange(const double bmin, const double bmax)
Definition: ViewMedium.cc:83
void PlotIonVelocity(const char xaxis, const double e, const double b, const double a)
Definition: ViewMedium.cc:183
void PlotIonDiffusion(const char xaxis, const double e, const double b, const double a)
Definition: ViewMedium.cc:220
void SetBAngleRange(const double amin, const double amax)
Definition: ViewMedium.cc:95
void PlotHoleTownsend(const char xaxis, const double e, const double b, const double a)
Definition: ViewMedium.cc:243
void PlotHoleAttachment(const char xaxis, const double e, const double b, const double a)
Definition: ViewMedium.cc:263
PlottingEngineRoot plottingEngine