# Problem about PlotFieldLines()

**URL:** <https://root-forum.cern.ch/t/problem-about-plotfieldlines/62642>\
**Category:** Garfield++\
**Created:** [January 12, 2025, 2:05pm UTC](https://root-forum.cern.ch/t/problem-about-plotfieldlines/62642 "2025-01-12T14:05:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wxj-imp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/b5e925/32.png) [@wxj-imp](https://root-forum.cern.ch/u/wxj-imp)\
**Post date:** [January 12, 2025, 2:05pm UTC](https://root-forum.cern.ch/t/problem-about-plotfieldlines/62642/1 "2025-01-12T14:05:32Z")

</div>

Dear Experts  
i got some problem in ploting electric lines about mwpc,i add gate wires between the anodes,but i can’t see any field lines from anodes to gate wires(anodes:+1300V,gate wires:0V),my code is above,and i printed the information of cells。if i want to plot field lines of anodes to gate wires,how can i do?

```auto
#include <cstdlib>
#include <iostream>
#include <vector>
#include <cstring>
#include <TROOT.h>
#include <TApplication.h>
#include "TCanvas.h"
#include "Garfield/MediumMagboltz.hh"
#include "Garfield/ComponentAnalyticField.hh"
#include "Garfield/Sensor.hh"
#include "Garfield/TrackHeed.hh"
#include "Garfield/DriftLineRKF.hh"
#include "Garfield/ViewField.hh"
#include "Garfield/ViewCell.hh"
#include "Garfield/ViewDrift.hh"
#include "Garfield/FundamentalConstants.hh"
#include "Garfield/Random.hh"
#include "Garfield/ViewMedium.hh"
#include "Garfield/ComponentFieldMap.hh"

using namespace Garfield;
using namespace std;

int main(int argc, char* argv[])
{
	//visualization
	TApplication app("app",&argc,argv);

	//Switch between cathod_gap(true) or sense_gap(false)
	//bool flag = true;

	//set distance of sense wires[cm] 
	constexpr double gap_sense = 2;

	//set wire diameters[cm]
	constexpr double sense_dia = 0.0025; //sense
    constexpr double gate_dia = 0.01; //gate

	//Voltages Setting[V]
	constexpr double vs = 1300.; //sense
    constexpr double vg = 0.; //gate

	//set gas
	const int ncoll = 10;
	MediumMagboltz gas;
	gas.SetComposition("argon",90,"methane",10);
	gas.SetTemperature(293.15);
	gas.SetPressure(637.55);
	gas.GenerateGasTable(ncoll);
	gas.WriteGasFile("ar_90_ch4_10.gas");
	gas.LoadGasFile("ar_90_ch4_10.gas");
	auto installdir = std::getenv("GARFIELD_INSTALL");
	
	//read the ion mobility table from file
	if(!installdir)
	{std::cerr << "GARFIELD_INSTALL variable not set.\n";
	return 1;
	}
	const std::string path = installdir;
	gas.LoadIonMobility(path + "/share/Garfield/Data/IonMobility_Ar+_Ar.txt");

	//set the electricfield
	ComponentAnalyticField cmp;
	cmp.SetMedium(&gas);

	//add cathod wires
	constexpr double xc = 0.;
	constexpr double yc = 0.;
	
	//make a sensor
	Sensor sensor;
	sensor.AddComponent(&cmp);

    string sense_prefix = "sense";
    for(int j = 0;j <= 6;j++)
	{
	//add Sense wires
	cmp.AddWire(xc+1+j*gap_sense,yc+1,sense_dia,vs,"sense",70.,55.,19.35,1);
    string sense_str = sense_prefix+std::to_string(j);
    sensor.AddElectrode(&cmp,sense_str.c_str());
    cmp.AddReadout(sense_str.c_str());
	}

    string gate_prefix = "gate";
    for(int j = 0;j <= 5;j++)
	{
	//add gate wires
	cmp.AddWire(xc+2+j*gap_sense,yc+1,gate_dia,vg,"gate",70.,100.,8.62,1);
    string gate_str = gate_prefix+std::to_string(j);
    sensor.AddElectrode(&cmp,gate_str.c_str());
    cmp.AddReadout(gate_str.c_str());
	}

	//add the plane
	cmp.AddPlaneY(0.,0.,"pad_window");
	cmp.AddPlaneY(2.,0.,"pad_window");
    sensor.AddElectrode(&cmp,"window1");
    cmp.AddReadout("window1");
    sensor.AddElectrode(&cmp,"window2");
    cmp.AddReadout("window2");

	//plot the cell
	TCanvas *c1 = new TCanvas("c1","c1",800,600);
	ViewCell cellView;
	cellView.SetComponent(&cmp);
	cellView.SetArea(0.,0.,14,2.);
	cellView.SetCanvas(c1);
	cellView.Plot2d();
	c1 -> Update();

	sensor.SetArea(0.,0.,0.,14.,2.,0.);

	//plot iopotential contours
	ViewField fieldView;
	//TCanvas *c2 = new TCanvas("c2","c2",600,600);
	fieldView.SetComponent(&cmp);
	fieldView.SetArea(0.,0.,14,2.);
	fieldView.SetVoltageRange(0.,1300.);
	fieldView.SetCanvas(c1);
    fieldView.SetNumberOfContours(30);
	fieldView.PlotContour("v");
	//fieldView.Plot("e","colz");
	//c2 -> Update();

	c1 -> Update();

    vector<double> x0;
    vector<double> y0;
    vector<double> z0;

    vector<double> x1;
    vector<double> y1;
    vector<double> z1;

    fieldView.SetElectricFieldRange(-10000.,10000.);

    fieldView.EqualFluxIntervals(0.,2.,0.,14.,2.,0.,x0,y0,z0,100);
    fieldView.PlotFieldLines(x0,y0,z0,true,false);

    fieldView.EqualFluxIntervals(0.,0.,0.,14.,0.,0.,x1,y1,z1,100);
    fieldView.PlotFieldLines(x1,y1,z1,true,false);

    c1->Update();

	cellView.SetComponent(&cmp);
	cellView.SetArea(0.,0.,14,2.);
	cellView.SetCanvas(c1);
	cellView.Plot2d();
	c1 -> Update();

	cmp.PrintCell();

	app.Run(true);
}

```

 ![屏幕截图 2025-01-12 220042](https://root-forum.cern.ch/uploads/default/original/3X/c/f/cfd5be69eb1560f02631db4daea9912ff6773caa.png)  
 ![屏幕截图 2025-01-12 220308](https://root-forum.cern.ch/uploads/default/original/3X/9/7/9745837fa67ab6acb02ce2ef305a7de6843d5b96.png)

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [January 12, 2025, 4:07pm UTC](https://root-forum.cern.ch/t/problem-about-plotfieldlines/62642/2 "2025-01-12T16:07:54Z")

</div>

Hello,

I am adding @hschindl in the loop.

Best,  
D

---

<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:** [January 12, 2025, 5:10pm UTC](https://root-forum.cern.ch/t/problem-about-plotfieldlines/62642/3 "2025-01-12T17:10:06Z")

</div>

Hi,

if I understood your question correctly, you would like to plot field lines starting from a sense wire? To do that, you can do something like this:

```auto
 std::vector<double> x2;
 std::vector<double> y2;
 std::vector<double> z2;
 const int nLines = 20;
 // Distribute the starting points of the field lines around the sense wire
 // (at a small distance from the wire surface).
 const double dphi = TwoPi / nLines;
 const double r2 = 0.5 * sense_dia + 1.e-4;
 for (int i = 0; i < nLines; ++i) {
   x2.push_back(1. + gap_sense + r2 * cos(i * dphi));
   y2.push_back(1. + r2 * sin(i * dphi));
   z2.push_back(0.);
}
fieldView.PlotFieldLines(x2, y2, z2, false, false);

```

---

<div class="post-metadata">

**Author:** ![wxj-imp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/b5e925/32.png) [@wxj-imp](https://root-forum.cern.ch/u/wxj-imp)\
**Post date:** [January 13, 2025, 5:33am UTC](https://root-forum.cern.ch/t/problem-about-plotfieldlines/62642/4 "2025-01-13T05:33:41Z")

</div>

thank you，i solve the problem with your solution 😀

---

<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:** [January 27, 2025, 5:33am UTC](https://root-forum.cern.ch/t/problem-about-plotfieldlines/62642/5 "2025-01-27T05:33:51Z")

</div>

Closed on January 27, 2025, 5:33am UTC

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