# Problems about ViewField

**URL:** <https://root-forum.cern.ch/t/problems-about-viewfield/54462>\
**Category:** Garfield++\
**Created:** [April 13, 2023, 7:54am UTC](https://root-forum.cern.ch/t/problems-about-viewfield/54462 "2023-04-13T07:54:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zql21](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/zql21/32/33487_2.png) [@zql21](https://root-forum.cern.ch/u/zql21)\
**Post date:** [April 13, 2023, 7:54am UTC](https://root-forum.cern.ch/t/problems-about-viewfield/54462/1 "2023-04-13T07:54:46Z")

</div>

I use ComponentConstant to create a uniform electric field along the z direction and us ViewField for visualization to ensure that I have established the uniform electric field.But the view result is blank.How can I visualize the uniform electric field?  
This is my code.

```auto
int main(int argc, char *argv[])
{
    TApplication app("app", &argc, argv);
    // Set gas
    MediumMagboltz gas;
    gas.SetTemperature(293.15);
    gas.SetPressure(760.);
    gas.SetComposition("Ar", 0.94, "CO2", 0.03, "H2O", 0.03, "O2", 20.9, "N2", 78.1);
    gas.Initialise(true); // prepares the table of microscopic scattering rates
    gas.LoadGasFile("gas_293_1atm_10-100000nE20.gas");
    const string ionpath = std::getenv("GARFIELD_INSTALL");
    gas.LoadIonMobility(ionpath + "/share/Garfield/Data/IonMobility_Ar+_Ar.txt");

    ComponentConstant cmp;
    constexpr double xlength = 10.; // cm
    constexpr double ylength = 10.;
    constexpr double zlength = 10.;
    cmp.SetArea(0., 0., 0., xlength, ylength, zlength);
    cmp.SetMedium(&gas);
    cmp.SetElectricField(0., 0., 1000.);

    ViewField fieldView;
    constexpr bool plotField = true;
    if (plotField)
    {
        fieldView.SetComponent(&cmp);
        fieldView.SetPlane(0, -1, 0, 0, 0, 0); //viewing plane (xz plane).
        fieldView.SetArea(0., 0, 0, xlength, ylength, zlength); //plot limits
        TCanvas *cf = new TCanvas("cf", "", 600, 600);
        cf->SetLeftMargin(0.16);
        fieldView.SetCanvas(cf);
        fieldView.PlotContour("e");
    }
    app.Run(true);
}

```

This is the result.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/5/b/5be84977a29a27b416837108ec35c369260b2315.png)  
Looking forward to your reply, thank you very much！

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [April 13, 2023, 8:16am UTC](https://root-forum.cern.ch/t/problems-about-viewfield/54462/2 "2023-04-13T08:16:08Z")

</div>

The plot looks correct to me, it shows a constant value of 1000 V/cm. For a uniform field, a contour plot of the field is not very instructive…

---

<div class="post-metadata">

**Author:** ![zql21](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/zql21/32/33487_2.png) [@zql21](https://root-forum.cern.ch/u/zql21)\
**Post date:** [April 13, 2023, 8:24am UTC](https://root-forum.cern.ch/t/problems-about-viewfield/54462/3 "2023-04-13T08:24:29Z")

</div>

> [@hschindl](#):
>
> The plot looks correct to me, it shows a constant value of 1000 V/cm. For a uniform field, a contour plot of the field is not very instructive…

1. Emm, you mean the result is right? But I see nothing
2. How to show the uniform electric field is instructive ?
3. in Examples I see fieldView.PlotFieldLines ( )

```auto
std::vector<double> xf;
std::vector<double> yf;
std::vector<double> zf;
fieldView.EqualFluxIntervals(xmin, 0, 0.99 * zmax, xmax, 0, 0.99 * zmax, xf, yf, zf, 20);
fieldView.PlotFieldLines(xf, yf, zf, true, false);

```

if I want to PlotFieldLines to show the uniform field, how should I modify the parameters of EqualFluxIntervals()? I don 't quite understand how to use EqualFluxIntervals.

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [April 13, 2023, 12:31pm UTC](https://root-forum.cern.ch/t/problems-about-viewfield/54462/4 "2023-04-13T12:31:45Z")

</div>

> [@zql21](#):
>
> Emm, you mean the result is right? But I see nothing

What do you mean? The plot shows a constant value. What did you expect to see from a contour plot of a uniform field?

If you want to see a gradient, you could plot the contours of the potential instead of the electric field.

`EqualFluxIntervals` is a helper function for choosing the starting points for a field line plot. You specify the starting point, end point, and the number of points, and the function will return you the coordinates of a set of points with a spacing corresponding to the density of electric field lines. You can then pass the coordinates of these points to the function `PlotFieldLines` to be used as starting points.

---

<div class="post-metadata">

**Author:** ![zql21](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/zql21/32/33487_2.png) [@zql21](https://root-forum.cern.ch/u/zql21)\
**Post date:** [April 13, 2023, 1:07pm UTC](https://root-forum.cern.ch/t/problems-about-viewfield/54462/5 "2023-04-13T13:07:02Z")

</div>

Oh,I got it ! I mistakenly thought I was drawing the potential.Thank you for your patient explanation

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 27, 2023, 1:07pm UTC](https://root-forum.cern.ch/t/problems-about-viewfield/54462/6 "2023-04-27T13:07:28Z")

</div>

Closed on April 27, 2023, 1:07pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
