18 m_hasExternalCanvas(false),
37 m_className =
"ViewMedium";
46 if (!m_hasExternalCanvas && m_canvas != 0)
delete m_canvas;
52 if (!m_hasExternalCanvas && m_canvas != 0) {
57 m_hasExternalCanvas =
true;
63 std::cerr << m_className <<
"::SetMedium:\n";
64 std::cerr <<
" Medium pointer is null.\n";
73 if (emin >= emax || emin < 0.) {
74 std::cerr << m_className <<
"::SetElectricFieldRange:\n";
75 std::cerr <<
" Incorrect field range.\n";
85 if (bmin >= bmax || bmin < 0.) {
86 std::cerr << m_className <<
"::SetMagneticFieldRange:\n";
87 std::cerr <<
" Incorrect field range.\n";
97 if (amin >= amax || amin < 0.) {
98 std::cerr << m_className <<
"::SetBAngleRange:\n";
99 std::cerr <<
" Incorrect field range.\n";
109 if (vmin >= vmax || vmin < 0.) {
110 std::cerr << m_className <<
"::SetFunctionRange:\n";
111 std::cerr <<
" Incorrect range.\n";
122 const double b,
const double a) {
126 double min = 0., max = 0.;
127 std::string title =
"";
129 title =
"electric field [V/cm]";
132 }
else if (xaxis ==
'b') {
133 title =
"magnetic field [T]";
136 }
else if (xaxis ==
'a') {
137 title =
"magnetic field angle [rad]";
141 AddFunction(min, max, m_vMin, m_vMax, keep, title,
"drift velocity [cm/ns]",
144 AddFunction(min, max, m_vMin, m_vMax, keep, title,
"drift velocity [cm/ns]",
147 AddFunction(min, max, m_vMin, m_vMax, keep, title,
"drift velocity [cm/ns]",
153 const double b,
const double a) {
157 double min = 0., max = 0.;
158 std::string title =
"";
160 title =
"electric field [V/cm]";
163 }
else if (xaxis ==
'b') {
164 title =
"magnetic field [T]";
167 }
else if (xaxis ==
'a') {
168 title =
"magnetic field angle [rad]";
172 AddFunction(min, max, m_vMin, m_vMax, keep, title,
173 "drift velocity [cm/ns]", 10, xaxis, e, b, a);
175 AddFunction(min, max, m_vMin, m_vMax, keep, title,
176 "drift velocity [cm/ns]", 25, xaxis, e, b, a);
178 AddFunction(min, max, m_vMin, m_vMax, keep, title,
179 "drift velocity [cm/ns]", 26, xaxis, e, b, a);
184 const double b,
const double a) {
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);
194 const double b,
const double a) {
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);
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);
208 const double b,
const double a) {
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);
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);
221 const double b,
const double a) {
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);
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);
234 const double b,
const double a) {
238 AddFunction(m_eMin, m_eMax, 0., 0., keep,
"electric field [V/cm]",
239 "Townsend coefficient [1/cm]", 3, xaxis, e, b, a);
244 const double b,
const double a) {
248 AddFunction(m_eMin, m_eMax, 0., 0., keep,
"electric field [V/cm]",
249 "Townsend coefficient [1/cm]", 13, xaxis, e, b, a);
254 const double b,
const double a) {
258 AddFunction(m_eMin, m_eMax, 0., 0., keep,
"electric field [V/cm]",
259 "Attachment coefficient [1/cm]", 4, xaxis, e, b, a);
264 const double b,
const double a) {
268 AddFunction(m_eMin, m_eMax, 0., 0., keep,
"electric field [V/cm]",
269 "Attachment coefficient [1/cm]", 14, xaxis, e, b, a);
275 std::cerr << m_className <<
"::PlotElectronCrossSections:\n";
276 std::cerr <<
" Function not yet implemented.\n";
280void ViewMedium::SetupCanvas() {
283 m_canvas =
new TCanvas();
284 m_canvas->SetTitle(
"Medium View");
285 if (m_hasExternalCanvas) m_hasExternalCanvas =
false;
288 gPad->SetLeftMargin(0.15);
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,
300 std::cerr << m_className <<
"::AddFunction:\n";
301 std::cerr <<
" Medium is not defined.\n";
307 std::string fname =
"fMediumView_0";
308 while (gROOT->GetListOfFunctions()->FindObject(fname.c_str())) {
310 std::stringstream ss;
311 ss <<
"fMediumView_";
316 std::cout << m_className <<
"::AddFunction:\n";
317 std::cout <<
" Adding function " << fname <<
"\n";
333 "ViewMedium",
"EvaluateFunction");
335 m_functions.push_back(fNew);
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);
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);
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) {
361 }
else if (type == 24) {
363 }
else if (type < 20 || type == 25 || type == 26) {
368 m_functions.back().SetLineColor(color);
370 std::vector<double> efields;
371 std::vector<double> bfields;
372 std::vector<double> bangles;
374 const int nEfields = efields.size();
375 const int nBfields = bfields.size();
376 const int nBangles = bangles.size();
377 bool withGraph =
true;
379 if (nEfields <= 0 || nBfields <= 0 || nBangles <= 0) {
389 }
else if (xaxis ==
'b') {
392 }
else if (xaxis ==
'a') {
396 std::cerr << m_className <<
"::AddFunction:\n";
397 std::cerr <<
" Error specifying X-axis.\n";
398 std::cerr <<
" Invalid parameter type.\n";
401 graph.SetMarkerStyle(marker);
402 graph.SetMarkerColor(color);
412 for (
int i = 0; i < n; ++i) {
413 if (
fabs(efields[i] - m_efield) <= m_etolerance) {
418 for (
int i = 0; i < n; ++i) {
419 if (
fabs(bfields[i] - m_bfield) <= m_btolerance) {
424 for (
int i = 0; i < n; ++i) {
425 if (
fabs(bangles[i] - m_angle) <= m_atolerance) {
430 if ((xaxis ==
'e' && (bpoint == -1 || apoint == -1)) ||
431 (xaxis ==
'b' && (epoint == -1 || apoint == -1)) ||
432 (xaxis ==
'a' && (epoint == -1 || bpoint == -1)))
435 for (
int i = 0; i < n; ++i) {
438 double alongx = 0, alongy = 0., alongz = 0.;
448 else if (xaxis ==
'b')
450 else if (xaxis ==
'a')
522 efields[i] *
sin(bangles[apoint]),
523 0, bfields[bpoint], 0, 0, value,
525 else if (xaxis ==
'b')
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') {
532 efields[epoint] *
sin(bangles[i]),
533 0, bfields[bpoint], 0, 0, value,
543 efields[i] *
sin(bangles[apoint]),
544 0, bfields[bpoint], 0, 0, alongx,
546 else if (xaxis ==
'b')
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')
553 m_efield *
cos(bangles[i]), m_efield *
sin(bangles[i]), 0,
554 m_bfield, 0, 0, alongx, alongy, value);
563 efields[i] *
sin(bangles[apoint]), 0,
564 bfields[bpoint], 0, 0, value, alongy,
566 else if (xaxis ==
'b')
568 efields[epoint] *
sin(bangles[apoint]),
569 0, bfields[i], 0, 0, value, alongy,
571 else if (xaxis ==
'a')
573 efields[epoint] *
sin(bangles[i]), 0,
574 bfields[bpoint], 0, 0, value, alongy,
581 efields[i] *
sin(bangles[apoint]), 0,
582 bfields[bpoint], 0, 0, alongx, alongy,
584 else if (xaxis ==
'b')
586 efields[epoint] *
sin(bangles[apoint]),
587 0, bfields[i], 0, 0, alongx, alongy,
589 else if (xaxis ==
'a')
591 m_efield *
sin(bangles[i]), 0, m_bfield,
592 0, 0, alongx, alongy, 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);
606 m_graphs.push_back(graph);
609 std::cerr << m_className <<
"::AddFunction:\n";
610 std::cerr <<
" Error retrieving data table.\n";
611 std::cerr <<
" Suppress plotting of graph.\n";
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");
622 m_functions.back().GetYaxis()->SetTitleOffset(1.5);
623 m_functions.back().Draw(
"");
626 for (
int i = 0; i < m_nGraphs; ++i) {
627 m_graphs[i].Draw(
"p");
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];
642 double value = 0., a = 0., b = 0., c = 0., alongx = 0., alongy = 0.,
650 m_bfield *
sin(m_angle), 0, a, b, c))
652 }
else if (xaxis ==
'b') {
654 x *
sin(m_angle), 0, a, b, c))
656 }
else if (xaxis ==
'a') {
658 m_bfield *
sin(x), 0, a, b, c))
685 if (!m_medium->
HoleVelocity(x, 0, 0, 0, 0, 0, a, b, c))
return 0.;
690 if (!m_medium->
HoleDiffusion(x, 0, 0, 0, 0, 0, a, b))
return 0.;
695 if (!m_medium->
HoleDiffusion(x, 0, 0, 0, 0, 0, a, b))
return 0.;
700 if (!m_medium->
HoleTownsend(x, 0, 0, 0, 0, 0, a))
return 0.;
710 if (!m_medium->
IonVelocity(x, 0, 0, 0, 0, 0, a, b, c))
return 0.;
715 if (!m_medium->
IonDiffusion(x, 0, 0, 0, 0, 0, a, b))
return 0.;
720 if (!m_medium->
IonDiffusion(x, 0, 0, 0, 0, 0, a, b))
return 0.;
727 m_bfield, 0, 0, value, alongy, alongz))
729 }
else if (xaxis ==
'b') {
731 m_efield *
sin(m_angle), 0, x, 0, 0,
732 value, alongy, alongz))
734 }
else if (xaxis ==
'a') {
736 m_bfield, 0, 0, value, alongy, alongz))
745 m_bfield, 0, 0, alongx, alongy, value))
747 }
else if (xaxis ==
'b') {
749 m_efield *
sin(m_angle), 0, x, 0, 0,
750 alongx, alongy, value))
752 }
else if (xaxis ==
'a') {
754 m_bfield, 0, 0, alongx, alongy, value))
763 m_bfield, 0, 0, value, alongy, alongz))
765 }
else if (xaxis ==
'b') {
767 m_efield *
sin(m_angle), 0, x, 0, 0, value,
770 }
else if (xaxis ==
'a') {
772 m_bfield, 0, 0, value, alongy, alongz))
781 m_bfield, 0, 0, alongx, alongy, value))
783 }
else if (xaxis ==
'b') {
785 m_efield *
sin(m_angle), 0, x, 0, 0, alongx,
788 }
else if (xaxis ==
'a') {
790 m_bfield, 0, 0, alongx, alongy, value))
796 std::cerr << m_className <<
"::EvaluateFunction:\n";
797 std::cerr <<
" Unknown type of transport coefficient requested.\n";
798 std::cerr <<
" Program bug!\n";
DoubleAc cos(const DoubleAc &f)
DoubleAc sin(const DoubleAc &f)
DoubleAc exp(const DoubleAc &f)
DoubleAc fabs(const DoubleAc &f)
bool GetHoleVelocityE(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &v)
bool GetElectronTransverseDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dt)
virtual bool HoleTownsend(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &alpha)
virtual double ScaleDiffusion(const double &d) const
bool GetIonLongitudinalDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dl)
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)
bool GetElectronTownsend(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &alpha)
bool GetIonTransverseDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dt)
virtual double ScaleAttachment(const double &eta) const
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)
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)
virtual double UnScaleElectricField(const double &e) const
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)
virtual double ScaleVelocity(const double &v) const
void GetFieldGrid(std::vector< double > &efields, std::vector< double > &bfields, std::vector< double > &angles)
virtual bool ElectronTownsend(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &alpha)
bool GetHoleTransverseDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dt)
virtual bool ElectronAttachment(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &eta)
bool GetElectronLongitudinalDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dl)
bool GetHoleAttachment(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &eta)
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)
bool GetHoleLongitudinalDiffusion(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &dl)
bool GetElectronAttachment(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &eta)
bool GetHoleTownsend(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &alpha)
virtual double ScaleTownsend(const double &alpha) const
bool GetElectronVelocityE(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &v)
std::string GetName() const
virtual bool HoleAttachment(const double ex, const double ey, const double ez, const double bx, const double by, const double bz, double &eta)
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)
bool GetIonMobility(const unsigned int &ie, const unsigned int &ib, const unsigned int &ia, double &mu)
int GetRootColorElectron()
double EvaluateFunction(double *pos, double *par)
void PlotElectronVelocity(const char xaxis, const double e, const double b, const double a)
void PlotHoleDiffusion(const char xaxis, const double e, const double b, const double a)
void PlotElectronTownsend(const char xaxis, const double e, const double b, const double a)
void SetMedium(Medium *m)
void SetElectricFieldRange(const double emin, const double emax)
void PlotElectronAttachment(const char xaxis, const double e, const double b, const double a)
void PlotElectronDiffusion(const char xaxis, const double e, const double b, const double a)
void PlotElectronCrossSections()
void SetCanvas(TCanvas *c)
void PlotHoleVelocity(const char xaxis, const double e, const double b, const double a)
void SetMagneticFieldRange(const double bmin, const double bmax)
void PlotIonVelocity(const char xaxis, const double e, const double b, const double a)
void PlotIonDiffusion(const char xaxis, const double e, const double b, const double a)
void SetBAngleRange(const double amin, const double amax)
void PlotHoleTownsend(const char xaxis, const double e, const double b, const double a)
void PlotHoleAttachment(const char xaxis, const double e, const double b, const double a)
PlottingEngineRoot plottingEngine