# How to store the entries and plot for different time values using for lop

**URL:** <https://root-forum.cern.ch/t/how-to-store-the-entries-and-plot-for-different-time-values-using-for-lop/59299>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [May 10, 2024, 5:15pm UTC](https://root-forum.cern.ch/t/how-to-store-the-entries-and-plot-for-different-time-values-using-for-lop/59299 "2024-05-10T17:15:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rana](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rana/32/36242_2.png) [@Rana](https://root-forum.cern.ch/u/Rana)\
**Post date:** [May 10, 2024, 5:15pm UTC](https://root-forum.cern.ch/t/how-to-store-the-entries-and-plot-for-different-time-values-using-for-lop/59299/1 "2024-05-10T17:15:29Z")

</div>

Dear All,

I am trying to loop over time and store the value of entries after every time interval of 1.2e9 secs, and plot for beam run after every 1.2e9 secs, however what I am getting is a cumulative plot for all the entries, and what I am looking for is a fragmented plot for each beam run and to register each entries. I am attaching the block of the for loop I implemented.

```auto
for (double t=0; t<RecoHitPos[nHit][3];t+=1.2e9)
            		
            		{
            
            			if (RecoHitPos[nHit][0] != -999) 
				
			{
			
				cout<<"	RecoHitPos[nHit][3]"<<RecoHitPos[nHit][3]<<endl;
				
            			h2D_spill->Fill(RecoHitPos[nHit][2],RecoHitPos[nHit][0]);
}
}
}

```

What should I do to get a plot that way and store all the values of entries for each run?

Best,  
Rana

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 10, 2024, 7:36pm UTC](https://root-forum.cern.ch/t/how-to-store-the-entries-and-plot-for-different-time-values-using-for-lop/59299/2 "2024-05-10T19:36:58Z")

</div>

Hi Rana,

the `t` variable is only used on the first line. What is the point of the loop if `t` is not used inside the loop? Each iteration will be exactly the same…

---

<div class="post-metadata">

**Author:** ![Rana](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rana/32/36242_2.png) [@Rana](https://root-forum.cern.ch/u/Rana)\
**Post date:** [May 11, 2024, 4:57am UTC](https://root-forum.cern.ch/t/how-to-store-the-entries-and-plot-for-different-time-values-using-for-lop/59299/3 "2024-05-11T04:57:21Z")

</div>

> [@Rana](#):
>
> `if (RecoHitPos[nHit][0] != -999) `

Hi Yus,  
I want to actually some conditon for t inside the if {}, but I am not being able to understand what condition to I put that gives me the result after every the fixed time interval,  
I tried this too :  
if (RecoHitPos[iHit][0] != -999) {  
for (double t=0; t\<RecoHitPos[iHit][3];t+=1.2e12)

```
        		{
			cout<<"	t"<<t<<endl;
			
        			h2D_spill->Fill(RecoHitPos[iHit][2],RecoHitPos[iHit][0]);

```

}

but the it won’t loop over and returns to be zero only, howevwe if I do a cout with RecoHitPos[iHit][3] then it loops over all the values. Is the for loop correct in terms of of assigning the t value to an array?

Best,  
R

```auto

```

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 11, 2024, 7:52am UTC](https://root-forum.cern.ch/t/how-to-store-the-entries-and-plot-for-different-time-values-using-for-lop/59299/4 "2024-05-11T07:52:46Z")

</div>

Hi Rana,

> [@Rana](#):
>
> Is the for loop correct in terms of of assigning the t value to an array?

what is the value of `RecoHitPos[iHit][3]`?

---

<div class="post-metadata">

**Author:** ![Rana](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rana/32/36242_2.png) [@Rana](https://root-forum.cern.ch/u/Rana)\
**Post date:** [May 11, 2024, 9:27pm UTC](https://root-forum.cern.ch/t/how-to-store-the-entries-and-plot-for-different-time-values-using-for-lop/59299/5 "2024-05-11T21:27:59Z")

</div>

Hi Yus,

![Screenshot from 2024-05-11 17-24-27](https://root-forum.cern.ch/uploads/default/original/3X/9/5/953c4d4868072a23a01337d87faa83323abe082d.png)

for (double t=0; t\<RecoHitPos[iHit][3];t+=1.2e14)

```
        		{cout<<"	RecoHitPos[iHit][3]"<<RecoHitPos[iHit][3]<<endl;
			//cout<<"	t"<<t<<endl;}

```

the time starts from 0 ns to 1.416e+11 ns.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 11, 2024, 9:53pm UTC](https://root-forum.cern.ch/t/how-to-store-the-entries-and-plot-for-different-time-values-using-for-lop/59299/6 "2024-05-11T21:53:44Z")

</div>

Hi,

I don’t get it. If your code is

```auto
for (double t=0; t<RecoHitPos[iHit][3];t+=1.2e14)
    cout<<"	RecoHitPos[iHit][3]"<<RecoHitPos[iHit][3]<<endl;

```

, then how come `RecoHitPos[iHit][3]` changes inside that loop? Or is there another loop over something else outside this one? Please also show the values of `t` and `iHit` with something like

```auto
for (double t=0; t<RecoHitPos[iHit][3];t+=1.2e14)
    cout<<"t = " << t << ", iHit = " << iHit << ", RecoHitPos[iHit][3]" << RecoHitPos[iHit][3] << endl;

```

---

<div class="post-metadata">

**Author:** ![Rana](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rana/32/36242_2.png) [@Rana](https://root-forum.cern.ch/u/Rana)\
**Post date:** [May 15, 2024, 7:34pm UTC](https://root-forum.cern.ch/t/how-to-store-the-entries-and-plot-for-different-time-values-using-for-lop/59299/7 "2024-05-15T19:34:36Z")

</div>

Hi Yus, I fixed it. Thanks a lot, I wronged in a for loop.
