# MAXWtFld on ComponentNeBEM3d

**URL:** <https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968>\
**Category:** Garfield++\
**Created:** [August 3, 2025, 3:31am UTC](https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968 "2025-08-03T03:31:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabrielribcesario](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gabrielribcesario/32/38927_2.png) [@gabrielribcesario](https://root-forum.cern.ch/u/gabrielribcesario)\
**Post date:** [August 3, 2025, 3:31am UTC](https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968/1 "2025-08-03T03:31:50Z")

</div>

Hello,

I was simulating a MWPC with crossed wire planes using the ComponentNeBEM3d and realized there was a coded limit on the number of weighting fields (`#define MAXWtFld 11` in neBEM.h). Is there an underlying reason for this other than performance issues, or can I safely increase this number? It would be very helpful I were able to use something other than a FEM solver for this particular application.

Sincerely,  
Gabriel

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 4, 2025, 6:36am UTC](https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968/2 "2025-08-04T06:36:27Z")

</div>

I guess @hschindl can help you.

---

<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:** [August 5, 2025, 5:49am UTC](https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968/3 "2025-08-05T05:49:12Z")

</div>

Hi, sorry for the late reply! You can safely increase the value, it will just increase the memory footprint a bit.

---

<div class="post-metadata">

**Author:** ![gabrielribcesario](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gabrielribcesario/32/38927_2.png) [@gabrielribcesario](https://root-forum.cern.ch/u/gabrielribcesario)\
**Post date:** [August 5, 2025, 7:12pm UTC](https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968/4 "2025-08-05T19:12:17Z")

</div>

Thank you for your answer, I’m very glad to hear that.

I tried increasing the number but now I’m getting segmentation faults when `MAXWtFld > 56`, even though there doesn’t seem to be a large memory allocation involved when `MAXWtFld == 56`. I rebuilt Garfield with the `-g` flag and the debugger tells me that the segfault comes from incrementing the m\_wfields `std::map`:

```auto
ComponentNeBem3d::Initialise:
    Prepared weighting field for readout group "wire0".
1625 m_wfields[label] = id;
(gdb) 

Thread 1 "forum" received signal SIGSEGV, Segmentation fault.
0x00007ffff52c658e in std::_Rb_tree_decrement(std::_Rb_tree_node_base*) () from /lib/x86_64-linux-gnu/libstdc++.so.6

```

I’ve attached a short example that reproduces the error for me after editing the neBEM.h header. The segfault occurs for me even if there is only one labeled primitive (`size_t nWire = 1`). Please let me know if you can’t reproduce it.

[forum.cpp](https://root-forum.cern.ch/uploads/short-url/5kwitZQMlmYF0YsOZTKEz6mKk60.cpp) (1.7 KB)

**EDIT:** I managed to find a (temporary) solution for this. After compiling my program with AddressSanitizer, I discovered a buffer overflow in the `ComponentNeBem3d::InitValues()` function. In the ComponentNeBem3d.hh file (lines 322 to 326):

```auto
/* ... */
  unsigned int m_optWtFldFastVol[11];
  unsigned int m_optCreateWtFldFastPF[11];
  unsigned int m_optReadWtFldFastPF[11];
  unsigned int m_versionWtFldFV[11];
  unsigned int m_nbBlocksWtFldFV[11];
/* ... */

```

These arrays have size 11 instead of size MAXWtFld, leading to the buffer overflow previously described. The problem has a pretty simple fix:

```auto
#include "neBEM.h" // for MAXWtFld
/* ... */
  unsigned int m_optWtFldFastVol[MAXWtFld];
  unsigned int m_optCreateWtFldFastPF[MAXWtFld];
  unsigned int m_optReadWtFldFastPF[MAXWtFld];
  unsigned int m_versionWtFldFV[MAXWtFld];
  unsigned int m_nbBlocksWtFldFV[MAXWtFld];
/* ... */

```

This also implies in the `neBEM.h` header being installed in the project’s `CMAKE_INSTALL_INCLUDEDIR`

Sincerely,  
Gabriel

---

<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:** [August 19, 2025, 7:12pm UTC](https://root-forum.cern.ch/t/maxwtfld-on-componentnebem3d/63968/5 "2025-08-19T19:12:33Z")

</div>

Closed on August 19, 2025, 7:12pm UTC

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