# GetRandom2

**URL:** <https://root-forum.cern.ch/t/getrandom2/60279>\
**Category:** Newbie\
**Created:** [July 20, 2024, 2:41pm UTC](https://root-forum.cern.ch/t/getrandom2/60279 "2024-07-20T14:41:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![liz](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/liz/32/36077_2.png) [@liz](https://root-forum.cern.ch/u/liz)\
**Post date:** [July 20, 2024, 2:41pm UTC](https://root-forum.cern.ch/t/getrandom2/60279/1 "2024-07-20T14:41:02Z")

</div>

Hello, I have a file containing the values of px, py, pz and E for a particle. I organized them in histogram as you can see in the following code:

```auto
void read_file(){
  TH1F* hE = new TH1F("hE"," energy",100,0,0);
  TH1F* hth = new TH1F("hth"," theta",100,0,0);
  TH2F* hpth = new TH2F("hpth"," p-theta",100,0,0,100,0,0);
  TH2F* hpcth = new TH2F("hpcth"," p-costheta",100,0,0,100,0,0);

  ifstream f(data.txt");
 double p=0,px=0,py=0,pz=0,E=0,th=0,cth=0;
 do{
   f>>px>>py>>pz>>E;
   p=sqrt(px*px+py*py+pz*pz);
   th=TMath::ACos(pz/p);
   cth=pz/p;
   hE->Fill(p);
   hth->Fill(th);
   hpth->Fill(p,th);
   hpcth->Fill(p,cth);
 }while(f);

```

I have been instructed to creat a loop and use

```auto
h2->GetRandom2(x,y);
h2bis->Fill(x,y)

```

Then I should put the x y z px py pz in a text file because I’ll need them for another simulation.

However I do not understand exactly what I’m supposed to do or why and I also don’t know what GetRandom does. I’ve tried looking up some examples but found nothing.

Does anybody have an idea of what I’m supposed to do?  
Thanks in advance ☹

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [July 21, 2024, 3:55am UTC](https://root-forum.cern.ch/t/getrandom2/60279/2 "2024-07-21T03:55:30Z")

</div>

[https://root.cern/doc/master/classTH2.html#a883f419e1f6899f9c4255b458d2afe2e](https://root.cern/doc/master/classTH2.html#a883f419e1f6899f9c4255b458d2afe2e)  
[https://root-forum.cern.ch/search?q=getrandom2](https://root-forum.cern.ch/search?q=getrandom2)
