# How to simulate a beam of particles?

**URL:** <https://root-forum.cern.ch/t/how-to-simulate-a-beam-of-particles/44789>\
**Category:** Garfield++\
**Created:** [May 9, 2021, 4:48am UTC](https://root-forum.cern.ch/t/how-to-simulate-a-beam-of-particles/44789 "2021-05-09T04:48:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henry\_Billiot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/henry_billiot/32/25659_2.png) [@Henry\_Billiot](https://root-forum.cern.ch/u/Henry_Billiot)\
**Post date:** [May 9, 2021, 4:48am UTC](https://root-forum.cern.ch/t/how-to-simulate-a-beam-of-particles/44789/1 "2021-05-09T04:48:21Z")

</div>

Hi,

As the title suggests, I’m looking for a way to simulate a beam going through a proportional counter. Based on what I know about Garfield so far, it seems like the only way to do this is by calling NewTrack() as many times as you need. Is there a more efficient way to do this?

---

<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:** [May 9, 2021, 12:23pm UTC](https://root-forum.cern.ch/t/how-to-simulate-a-beam-of-particles/44789/2 "2021-05-09T12:23:09Z")

</div>

Hi,  
calling `NewTrack` multiple times is indeed the way to go.

---

<div class="post-metadata">

**Author:** ![Henry\_Billiot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/henry_billiot/32/25659_2.png) [@Henry\_Billiot](https://root-forum.cern.ch/u/Henry_Billiot)\
**Post date:** [May 12, 2021, 5:00am UTC](https://root-forum.cern.ch/t/how-to-simulate-a-beam-of-particles/44789/3 "2021-05-12T05:00:19Z")

</div>

Hi @hschindl ,

I have a follow-up question. At the moment, this is how I am simulating a track from the incident beam:

```auto
  TrackHeed track;
  track.SetSensor(&sensor);
  track.SetParticle("proton");
  track.SetKineticEnergy(20.e6);

  double xc = 0., yc = 0., zc = 0., tc = 0., ec = 0., extra = 0.;
  int nc = 0;
  std::vector<double> electrons;
  double xe = 0., ye = 0., ze = 0., te = 0., ee = 0.;
  double dx = 0., dy = 0., dz = 0.;
  int left=0, right = 0;
  int NofProton = 100;  
  for (int i = 0; i < NofProton; i++) {
    // Simulate a track
    track.NewTrack(-x, 1.0, -x, 100., 1., 0., 1.); //45 degrees
		while (track.GetCluster(xc, yc, zc, tc, nc, ec, extra)) {
			for (int k = 0; k < nc; ++k) {
			  track.GetElectron(k, xe, ye, ze, te, ee, dx, dy, dz);
			  electrons.push_back(xe);
			  electrons.push_back(ye);
			  electrons.push_back(ze);
			  electrons.push_back(te);
			}
		}
  }

```

When NofProton = 1, I get a rather straight track, like below:  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/e/c/ec8f6bad35cd0872fd55b7fefa232474af5d020b.png)

However, when NofProton = 100, the track becomes this  
 ![image](https://root-forum.cern.ch/uploads/default/original/3X/e/1/e12c4edffe002c52f288a90c65b97449edda2194.png)

Can you please explain to me why this is happening?

Note: each tick mark corresponds to 1 cm.

---

<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:** [May 12, 2021, 6:30am UTC](https://root-forum.cern.ch/t/how-to-simulate-a-beam-of-particles/44789/4 "2021-05-12T06:30:23Z")

</div>

Hi,  
nice plot! I think it’s just statistical fluctuations and the little sprigs you see on the plot are the secondaries created by delta electrons.

---

<div class="post-metadata">

**Author:** ![Henry\_Billiot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/henry_billiot/32/25659_2.png) [@Henry\_Billiot](https://root-forum.cern.ch/u/Henry_Billiot)\
**Post date:** [May 12, 2021, 7:28am UTC](https://root-forum.cern.ch/t/how-to-simulate-a-beam-of-particles/44789/5 "2021-05-12T07:28:25Z")

</div>

Hi,

That makes sense! Thanks.

---

<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:** [May 26, 2021, 7:28am UTC](https://root-forum.cern.ch/t/how-to-simulate-a-beam-of-particles/44789/6 "2021-05-26T07:28:31Z")

</div>

Closed on May 26, 2021, 7:28am UTC

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