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

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.

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

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…

1 Like

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

Hi Rana,

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

Hi Yus,

Screenshot from 2024-05-11 17-24-27

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.

Hi,

I don’t get it. If your code is

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

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

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