ARRAYS AND VECTORS IN C++
How are these lemenst distributed in rows and colums?
- the LL[2][3] specifies a matrix with two rows and three columns, so the {1, 2, 3, 4, 5, 6} is divided so it is a matrix that looks like:
1 2 3
4 5 6
- when defining a 2-dimensional array:
(example from https://www.geeksforgeeks.org/multidimensional-arrays-c-cpp/)
complicated example (w/o braces):
int x[3][4] = {0, 1 ,2 ,3 ,4 , 5 , 6 , 7 , 8 , 9 , 10 , 11}
simpler example (with braces):
int x[3][4] = {{0,1,2,3}, {4,5,6,7}, {8,9,10,11}};
this makes the array easier to index and thus easier to call an index in the array within a program
READING DATA FROM A FILE
VECTORS AND COMBINING CODE FROM DIFFERENT FILES
RANDOM NUMBERS
- 1st run: including the & symbol, 2nd run: removing the & symbol
- without the & symbol, the generator will print the same random number for each iteration - the & symbol ensures that inew can be redefined
Put a cout statement into the code that makes it print the first 10 “random” numbers it generates. Run the executable a couple of times. What do you notice? (This is why they are called pseudo-random numbers.)
- the output is the same (I ran it two more times and got the same 10 numbers) - this is because the random number generator has a set seed, so it will generate the same 10 random numbers each time
Try changing the seed (it should be odd and large). What happens then?
- the seed was changed to 2203 - the generator will still generate the same 10 numbers each time, but it will generate different numbers
Now try changing the number of times you call the random number generator from 1000 to other numbers (say, 10, 100, 100000, etc). What do you notice about the contents of the histogram?
- the contents of the histogram even out - with enough generations, the number generator will generate roughly the same number of events in each bin
CALORIMETER PROBLEM
NOTE: there is an intentional mistake in the code.
Look at the .C file. This is root code, so you will run it on the root prompt as
root -l resolutions.C
Set N=1 and run it. From this "data", what would you guess the mass of the mother particle is? And, how far would you guess the true mother mass could be from this measured value?
- From this data, the mass would appear to be ~60 GeV, but the mass should be ~91 GeV, so the measured mass is ~30 GeV from the true mass
Now change N to 10. What do you find?
- The mass peaks at ~81 GeV, which is only ~10 GeV off from the true value
Change N to 100? What do you find?
- The mass peaks around 75 GeV, which is about 15GeV off from the true value
Change N to 1000. What do you find?
- The mass peaks around 85-90 GeV, which is very close to the true value (increasing the number of iterations would produce a mass closer to 91 GeV)
Now open secretparameters.txt and change the first number in it to 1. Repeat with N=1,10,100,1000. What have you learned?
- The data skews – the plot will eventually peak at 1, with enough iterations
1:
10:
100:
1000:
In Class:
Google "ROOT gRandom->Rndm()" and find what Rndm() function does. ?
- The Rndm() function generates a uniform distribution of random numbers between 0 and 1
Add another histogram for transverse momentum (p_T = sqrt(P_x^2 + P_y^2
(N = 10000)