# Attaching ComponentConstant electric field to Sensor

**URL:** <https://root-forum.cern.ch/t/attaching-componentconstant-electric-field-to-sensor/64093>\
**Category:** Garfield++\
**Created:** [September 1, 2025, 4:01am UTC](https://root-forum.cern.ch/t/attaching-componentconstant-electric-field-to-sensor/64093 "2025-09-01T04:01:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wjsdms0721](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/e5b9ba/32.png) [@wjsdms0721](https://root-forum.cern.ch/u/wjsdms0721)\
**Post date:** [September 1, 2025, 4:01am UTC](https://root-forum.cern.ch/t/attaching-componentconstant-electric-field-to-sensor/64093/1 "2025-09-01T04:01:12Z")

</div>

Hi,

I am designing TPC using Garfield and installing sensor for it.

However, even though I used `fSensorDrift->AddComponent(fComponentConstantDrift);` to attach component to sensor, sensor does not have same electric field to component.

This is electric field setting for component and a series of process to output it.

> 251 fComponentConstantDrift = new Garfield::ComponentConstant();  
> 252 fComponentConstantDrift-SetMedium(fMediumMagboltzDrift);  
> 253 fComponentConstantDrift-\>SetElectricField(-440, 0, 0);

> 324 std::cout \<\< “====== E field Output (Component) ======” \<\< std::endl;  
> 325 fComponentConstantDrift-\>ElectricField(8, 0, 0, ex, ey, ez, v, medium, status);  
> 326 std::cout \<\< “Drift Zone Centre (8, 0, 0)” \<\< std::endl;  
> 327 std::cout \<\< “Ex = " \<\< ex \<\< " V/cm” \<\< std::endl;  
> 328 std::cout \<\< “Ey = " \<\< ey \<\< " V/cm” \<\< std::endl;  
> 329 std::cout \<\< “Ez = " \<\< ez \<\< " V/cm” \<\< std::endl;  
> 330 fComponentConstantItf-\>ElectricField(17.05, 0, 0, ex, ey, ez, v, medium, status);  
> 331 std::cout \<\< “Interface Zone Centre (17.05, 0, 0)” \<\< std::endl;  
> 332 std::cout \<\< “Ex = " \<\< ex \<\< " V/cm” \<\< std::endl;  
> 333 std::cout \<\< “Ey = " \<\< ey \<\< " V/cm” \<\< std::endl;  
> 334 std::cout \<\< “Ez = " \<\< ez \<\< " V/cm” \<\< std::endl;  
> 335 fComponentConstantEL-\>ElectricField(18.455, 0, 0, ex, ey, ez, v, medium, status);  
> 336 std::cout \<\< “EL Zone Centre (18.455, 0, 0)” \<\< std::endl;  
> 337 std::cout \<\< “Ex = " \<\< ex \<\< " V/cm” \<\< std::endl;  
> 338 std::cout \<\< “Ey = " \<\< ey \<\< " V/cm” \<\< std::endl;  
> 339 std::cout \<\< “Ez = " \<\< ez \<\< " V/cm” \<\< std::endl;

> 325 ====== E field Output (Component) ======  
> 326 Drift Zone Centre (8, 0, 0)  
> 327 Ex = -440 V/cm  
> 328 Ey = 0 V/cm  
> 329 Ez = 0 V/cm  
> 330 Interface Zone Centre (17.05, 0, 0)  
> 331 Ex = -471 V/cm  
> 332 Ey = 0 V/cm  
> 333 Ez = 0 V/cm  
> 334 EL Zone Centre (18.455, 0, 0)  
> 335 Ex = -14000 V/cm  
> 336 Ey = 0 V/cm  
> 337 Ez = 0 V/cm

while this is sensor setting that is not showing electric field in component.

> 254 fSensorDrift = new Garfield::Sensor();  
> 255 fSensorDrift-\>Clear();  
> 256 fSensorDrift-\>AddComponent(fComponentConstantDrift);  
> 257 fSensorDrift-\>SetArea(0, 16, -6, 6, -6, 6);  
> 258 fSensorDrift-\>SetTimeWindow(0., 2e5, 40000);

> 346 std::cout \<\< “====== E field Output (Sensor) ======” \<\< std::endl;  
> 347 fSensorDrift-\>ElectricField(8, 0, 0, ex, ey, ez, v, medium, status);  
> 348 std::cout \<\< “Drift Zone Centre (8, 0, 0)” \<\< std::endl;  
> 349 std::cout \<\< “Ex = " \<\< ex \<\< " V/cm” \<\< std::endl;  
> 350 std::cout \<\< “Ey = " \<\< ey \<\< " V/cm” \<\< std::endl;  
> 351 std::cout \<\< “Ez = " \<\< ez \<\< " V/cm” \<\< std::endl;  
> 352 fSensorItf-\>ElectricField(17.05, 0, 0, ex, ey, ez, v, medium, status);  
> 353 std::cout \<\< “Interface Zone Centre (17.05, 0, 0)” \<\< std::endl;  
> 354 std::cout \<\< “Ex = " \<\< ex \<\< " V/cm” \<\< std::endl;  
> 355 std::cout \<\< “Ey = " \<\< ey \<\< " V/cm” \<\< std::endl;  
> 356 std::cout \<\< “Ez = " \<\< ez \<\< " V/cm” \<\< std::endl;  
> 357 fSensorEL-\>ElectricField(18.455, 0, 0, ex, ey, ez, v, medium, status);  
> 358 std::cout \<\< “EL Zone Centre (18.455, 0, 0)” \<\< std::endl;  
> 359 std::cout \<\< “Ex = " \<\< ex \<\< " V/cm” \<\< std::endl;  
> 360 std::cout \<\< “Ey = " \<\< ey \<\< " V/cm” \<\< std::endl;  
> 361 std::cout \<\< “Ez = " \<\< ez \<\< " V/cm” \<\< std::endl;

> 342 ====== E field Output (Sensor) ======  
> 343 Drift Zone Centre (8, 0, 0)  
> 344 Ex = 0 V/cm  
> 345 Ey = 0 V/cm  
> 346 Ez = 0 V/cm  
> 347 Interface Zone Centre (17.05, 0, 0)  
> 348 Ex = 0 V/cm  
> 349 Ey = 0 V/cm  
> 350 Ez = 0 V/cm  
> 351 EL Zone Centre (18.455, 0, 0)  
> 352 Ex = 0 V/cm  
> 353 Ey = 0 V/cm  
> 354 Ez = 0 V/cm

Is there any problem in my source code? I attached my whole code for this process and am looking forward to receiving your answer!

[GarfieldPhysics.cc](https://root-forum.cern.ch/uploads/short-url/1GVTXSCR635CmXROENE5lrEhKXK.cc) (18.2 KB)

---

<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:** [September 1, 2025, 4:38am UTC](https://root-forum.cern.ch/t/attaching-componentconstant-electric-field-to-sensor/64093/2 "2025-09-01T04:38:43Z")

</div>

Hi,

you need to set the extent of the active region in the `ComponentConstant`object (`SetArea`).

---

<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:** [September 1, 2025, 4:59am UTC](https://root-forum.cern.ch/t/attaching-componentconstant-electric-field-to-sensor/64093/3 "2025-09-01T04:59:52Z")

</div>

Unrelated to you question: I saw that in the file you attached (`GarfieldPhysics.cc`) you create three distinct `MediumMagboltz` objects. Not sure this is necessary (also the field grid you set looks not quite right).

---

<div class="post-metadata">

**Author:** ![wjsdms0721](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/e5b9ba/32.png) [@wjsdms0721](https://root-forum.cern.ch/u/wjsdms0721)\
**Post date:** [September 1, 2025, 8:20am UTC](https://root-forum.cern.ch/t/attaching-componentconstant-electric-field-to-sensor/64093/4 "2025-09-01T08:20:45Z")

</div>

Thanks for your notice!

I am designing TPC with three region using Garfield so that I made three different MediumMagboltz. Transporting particle between regions will be handled by another file.

Also, I tried both

> fComponentConstantDrift-\>SetArea(0, 16, -6, 6, -6, 6);  
> fSensor-\>SetArea(fComponentConstantDrift);

and

> fComponentConstantDrift-\>SetArea(0, 16, -6, 6, -6, 6);  
> fSensor-\>SetArea(0, 16, -6, 6, -6, 6)

but it keeps same issue. Is there anything I am missing?

---

<div class="post-metadata">

**Author:** ![wjsdms0721](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/e5b9ba/32.png) [@wjsdms0721](https://root-forum.cern.ch/u/wjsdms0721)\
**Post date:** [September 1, 2025, 8:26am UTC](https://root-forum.cern.ch/t/attaching-componentconstant-electric-field-to-sensor/64093/5 "2025-09-01T08:26:05Z")

</div>

Well, does it make sense that applying same electric field directly to `fSensorDrift` using `fSensorDrift->SetElectricField()`? I have seen this class while watching garfield site but I am afraid of simulating separately using two electric field in `fMediumMagboltzDrift` and `fSensorDrift`.

---

<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:** [September 8, 2025, 2:45pm UTC](https://root-forum.cern.ch/t/attaching-componentconstant-electric-field-to-sensor/64093/6 "2025-09-08T14:45:22Z")

</div>

Hi,  
the arguments of `SetArea` are `xmin, ymin, zmin, xmax, ymax, zmax`, while in your code the sequence looks more like `xmin, xmax, ymin, ymax, zmin, zmax`. Can you check?

---

<div class="post-metadata">

**Author:** ![wjsdms0721](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/e5b9ba/32.png) [@wjsdms0721](https://root-forum.cern.ch/u/wjsdms0721)\
**Post date:** [September 9, 2025, 8:29am UTC](https://root-forum.cern.ch/t/attaching-componentconstant-electric-field-to-sensor/64093/7 "2025-09-09T08:29:58Z")

</div>

Hi.

Thanks to your answer, I finally solved the issue!  
And your advice about input for max and min was really helpful!  
🙂

---

<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:** [September 23, 2025, 8:30am UTC](https://root-forum.cern.ch/t/attaching-componentconstant-electric-field-to-sensor/64093/8 "2025-09-23T08:30:58Z")

</div>

Closed on September 23, 2025, 8:30am UTC

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