Now that I successfully have a way to gather the energy values that Dr. Eno wants, and have set the geometry of the calorimeter, I can start collecting information on the resolution (rms/mean) of the calorimeter for different particle energies. I collected the following for some negatively charged pions:
30 GeV:
50 GeV:
And here is a plot (made in Excel for speed, but will be making plots in root too)
In order to calculate the ratio of average edep in hcal passive / average edep in hcal active, I had been using the values calculated during each runs and taking their average for each individual run. To make sure that this number made sense Professor Eno wanted us to calculate the (theoretical) correction value. I used information about the makeup of the detector, as well as http://pdg.lbl.gov/2011/AtomicNuclearProperties/ to get information on the nuclear interaction lengths of the various materials that made up the hcal. Here is my work:
HCAL is made of plastic BC418 (primarily polyethylene) as scintillators and absorbers that are aluminum and iron
Plastic BC418 - (Polyethylene?) - default HCAL has 15 layers of tile, each layer is 3mm thick
Total thickness of scintillator is thus 4.5 cm
/88.18 = 0.0510
Aluminum - default HCAL has 3 layers of abs1, each layer is 130mm thick
Total thickness of abs1 is thus 39 cm
/39.7=0.9824
Iron - default HCAL has 11 layers of abs2, each layer is 84mm thick
Total thickness of abs2 is thus 92.4 cm
/16.77=5.5098
(0.9824+5.5098)/0.0510 = 127.2
This is in the realm of the ratios that my group and I got running pions, which suggests that nothing terrible is going wrong...
Professor Eno wanted us to gather the energy by taking: energy deposited in ECAL + energy deposited in HCAL active layer * (AVERAGE energy in HCAL passive / AVERAGE energy in HCAL active). So I needed to add this as a branch to the tree.
First, I tried adding to the existing tree, but this was problematic because I needed to first fill the branches with the energy in ECAL, HCAL active, HCAL passive, etc, then calculate the correction ratio (passive/active), and then fill the branch with the values. This meant I was calling fill 2x too many and was ending up with 2x as many entries in my branch as particles fired!
I solved this by just making another TTree and writing to this:
In our meeting with Professor Eno, we discovered that there were some parts of the detector that were still not widened, such as the services layers (wires), as well as that when we expanded the hcal the tile layers did not seem to spread throughout the full volume of the HCAL.
To resolve the problem with the services layer, I went into the DetectorConstruction.cc file and changed the dimensions of the services from 100 mm to 3000 mm:
To resolve the problem with the tiles, I changed a couple variables in the DetectorConstruction.cc:
In the DetectorConstruction.cc file, there is a variable NECAL_CRYST that you can change to change the number of crystals in the ECAL. However, this is annoying to experiment with as every time you change something in the source code you have to rebuild (cmake/make) everything. So I decided to instead make it a value I can read in using the configuration file. Here are the changes I made:
In template.cfg, the configuration file, I added a line at the end:
necal_crystals = 50000
In DetectorConstruction.hh, I added a new variable, G4int necal_crystals;
Finally, in DetectorConstruction.hh, I added some code to read in the value from the configuration file and NECAL_CRYST to the read-in value:
The reason I couldn't just read the value from the configuration file into NECAL_CRYST is that it needs to be a constant and that was not allowed by config.readInto
In the current calorimeter, there was a lot of energy escaping out the sides because the calorimeter was very narrow. This didn't reflect the setup that we would get in the full calorimeter, where most of the energy would escape out the back instead of the sides, so we wanted to increase the geometry of the calorimeter in order to limit the energy escaping. However, we also needed to make sure that we kept the segmentation the same while doing this, to maintain the properties of the detector. Below is an image showing the energy escaping out of the sides (rather than primarily the ends) of the detector:
Increasing the width of the HCAL was straightforward, as there is a variable for this in the configuration file. Also in the configuration file is a variable for the HCAL tile width, so we know that the segmentation of the HCAL is being preserved even when we change its width.
Energy is still escaping... but this time it is not escaping from sides of hcal, only from ends.
In order to add new branches, I did the following:
In CreateTree.cc:
In CreateTree.hh:
In SteppingAction.cc:
While we were getting the energy in the HCAL tiles, we also wanted to learn more about the energy deposited in the other parts of the calorimeter, like the HCAL absorbers and the solenoid. To do this, we needed to add branches to the data tree that is generated when we run the code. I did this and shared the directions with some groupmates:
You need to modify three files, CreateTree.cc, CreateTree.hh, and SteppingAction.cc
In CreateTree.cc (in the CreateTree method), you need to add a branch for whatever data you want to add. For example, I added a branch for absorber like this: "this -> GetTree() -> Branch("depositedEnergyHCAL_abs", &this->depositedEnergyHCAL_abs, "depositedEnergyHCAL_abs/F");"
In the Clear() method, you'll also want to add functionality to clear the branch, a line like this: "depositedEnergyHCAL_abs = 0.;"
In CreateTree.hh, you'll want to add a variable associated with this, like: "float depositedEnergyHCAL_abs;"
Finally, in SteppingAction.cc (in the UserSteppingAction method) you'll want to do something like this:
You can find the strings specifying different parts of the detector in the DetectorConstruction.cc file
One thing that was missing from the code we were given was code to record the energy deposited in the hcal (which is what we are particularly interested in since we think it will have very poor resolution. When we ran the code, we got something that looked like this for the hcal energy deposited:
My first clue in addressing this problem came from the spew when I "make" a build:
As you can see, there are some variables related to the hcal that are not being used in the DetectorConstruction.cc. So I went into DetectorConstruction.cc...
There are places in the code where some of these values are trying to be used! (see for hcalTilePV below). So this might mean that we are never entering the if statements or for loops.
To test my hypothesis, I added some cout statements:
I added cout << "hcal_width is " << hcal_width << endl; to check whether the if statements would be entered
When I ran, the spew told me: "HCAL width is 0.01".
So that's why it wasn't recording any energy deposit! Looking in the template.cfg file, I found:
... and realized my work had been for nothing and that I should have just read the template file...
So, I changed hcal_width value to 500 and did some runs. Now there were values in the depositedEnergyHCAL plot!
Professor Eno helped us figure out how to do runs without the visualizations. Here is what worked:
In CEPC_CaloTiming.cc, change the line regarding the execution of the gps instructions file to:
UImanager -> ApplyCommand("/control/execute "+gps_instructions_file);
In template.cfg you need to change gps_instructions_file =gps/gps.mac to
gps_instructions_file =gps.mac
Then I rebuilt, and was finally able to get some runs without the visualization popping up!
Some histograms were also generated...
Professor Eno asked us to start by running some 5-10 GeV pions. However, I soon found that the process for running things was difficult. In initial experiments with commands made a macro file, myMac.mac, containing:
/gps/energy 5 GeV
/gps/particle pi+
/gps/pos/type Plane
/gps/pos/shape Square
/gps/pos/centre 0 0 -1900 mm
/gps/direction 0 0 1
/run/beamOn 10
This code would set properties of the particle source (gps), specifying to run a 5 GeV pi+ and also specifying details of the shape, position, and direction of the particle generator.
I initially tried running the command: $./CEPC_Calotiming template.cfg myMac.mac, hoping it would execute similarly to in the B4a example we first worked on, but instead the program made an output file myMac.mac.root.
I got output:
<A lot of stuff about the detector setup>
ERROR: Can not open a macro file </afs/cern.ch/work/m/mlucchin/CEPC_CaloTiming/gps/gps.mac>. Set macro path with "/control/macroPath" if needed.
Writing tree to file myMac.mac.root ...
Obviously, this was not what I wanted.
I went into the visualization again by doing: $./CEPC_Calotiming template.cfg
Then, from the command place in the visual, did: /control/macroPath . (to add my current directory as a place to look for macros) and then /control/execute myMacro.mac
### Run :: 2 started ...
---> Begin of Event: 0
---> Begin of Event: 1
---> Begin of Event: 2
---> Begin of Event: 3
---> Begin of Event: 4
---> Begin of Event: 5
---> Begin of Event: 6
---> Begin of Event: 7
---> Begin of Event: 8
---> Begin of Event: 9
number of event = 10 User=2.33s Real=3.56s Sys=0s
WARNING: 10 events have been kept for refreshing and/or reviewing.
"/vis/reviewKeptEvents" to review them.
Then, as suggested, I did /vis/reviewKeptEvents, and saw this in the visualization:
After initial difficulties, Prof. Eno helped make the code we were given and out environment for Geant4/root/cmake compatible. She told us to do:
source /cvmfs/sft.cern.ch/lcg/contrib/gcc/4.8.4/x86_64-slc6/setup.csh
source /cvmfs/geant4.cern.ch/geant4/10.2/x86_64-slc6-gcc48-opt/CMake-setup.csh
setenv CXX `which g++`
setenv CC `which gcc`
setenv PATH /cvmfs/sft.cern.ch/lcg/contrib/CMake/3.11.1/Linux-x86_64/bin:${PATH}
source /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/5.34.36/x86_64-slc6-gcc48-opt/root/bin/thisroot.csh
(This can be put into a .csh file to make setting up the environment easier in the future). The one issue I had with this was that, for some reason, when I sourced the last command (for root) using a file, my $ROOTSYS variable did not set correctly, which meant that the cepc_calotiming code couldn't find some of the headers it needed. When I ran the last source command in the code above seperately, in the terminal, it set the variable correctly. It would be nice to figure out why this happened but overall it's not critical to the project, so I will put it aside for later.
Professor Eno also had us modify the CMakeLists.txt file, as seen here: https://umdcrystalcal-z641067.slack.com/files/UFXCPC554/FGVCEAERE/cmakelists.txt
After these modifications, I got a successful run by doing:
mkdir build_cepc
cd build_cepc
cmake -DGeant4_DIR=/cvmfs/geant4.cern.ch/geant4/10.2/x86_64-slc6-gcc48-opt/lib64/Geant4-10.2.0/ ../cepc_calotiming
make
cp ../cepc_calotiming/template.cfg
./CEPC_Calotiming template.cfg
I also took a look at the visualization of the calorimeter using a vis.mac file the Princeton postdoc (Marco Lucchini) had provided:
As I mentioned below, the postdoc who wrote the code did so on lxplus and had some scripts to set things up that thus don't work on the cluster (only on lxplus).
When I first cmake-d the code I got an error that certain header files (like TString.h and TCint.h) could not be found. So I did find -name TCint.h from my home directory and found in my CMSSW!
So I copied the TCint.h, and the .h files that it required, into the cepc_calotiming/include directory.
Then I did:
mkdir cepc_build
cd cepc_build
cmake -DGeant4_DIR=/cvmfs/geant4.cern.ch/geant4/10.5/x86_64-slc6-gcc63-opt/lib64/GEANT4-10.5.0 ../cepc_calotiming
make
All of these were successfully executed. There were some warnings after the make command about variables that were set but never used, but as this should not cause I crash I continued.
Then I did:
./CEPC_calotiming
And the program crashed:
I moved my files to the /data/users/lenafranklin/ directory so that Prof. Eno and others could take a look.
Professor Eno shared with us the code worked on by a Princeton postdoc of a possible design for a CEPC calorimeter. The major modification that will have to be made for this code initially before we can actually work on it is adapting it to work on the T3 Cluster environment. Many libraries, etc, the code references are on lxplus.
The issue of losing so much energy due to detector made us want to have a way to track the amount of energy escaping from the calorimeter. Even when we dramatically increased the size of the calorimeter, there was frequently still energy escaping. For example, in the run below with a very large calorimeter, running a 5 GeV pion still let around 0.75 GeV escape:
The first thing I did to attempt to solve this was to make modifications in the B4aSteppingAction.cc file. In the code snippet below, I added the block else {fEventAction->AddEsc(edep);} block of code. As you can see in the second if and elseif statement, this code adds the energy of a particle based on the part of the detector it is in, either the absorber or gap. By adding the else statement, I hoped to record the energy of particles when which exited the calorimeter. However, all of this would rely on the hope that particles exiting the world volume of the calorimeter deposited all their energy on exit. (The material outside of the calorimeter is made to simulate a void or vacuum, so their would be little energy deposited through actual interaction, to get an idea of the energy deposited, the particle would have to deposit their energy as they exited the world.)
In order to implement this, I also had to make modifications by adding a histogram and ntuple (process described below) and had to add a AddEsc() function in the B4aSteppingAction.hh file.
However, this did not work. The values I got from this were very small (on the scale of 10^-15 eV), which indicates that the particle does not deposit all their energy as it exist the world, and the only energy I was gathering in the AddEsc() function was the very very small amount of energy deposited as the particle went through the vacuum material ("galactic" in Geant). We needed to try a different method.
When I first made plots of Resolution vs Energy and Mean vs Energy, I got some strange results for charged pions:
Resolution should be decreasing with energy, but this did not happen... Professor Eno suggested it might be because energy is leaking out of the calorimeter. To investigate this, I added some code to the B4a source code to create and display a histogram with the sum of the energy deposited in the absorber and the gap. This way, if energy was escaping, we could tell. Indeed, we saw that energy was escaping from the calorimeter.
To solve this I made the calorimeter larger. I increased the layers from 20 to 200 and increased its size to 400 cm. This was done in the B4DetectorConstruction.cc file, and the modified code snippet can be seen below:
Indeed, after running this, the energy was more contained in the calorimeter.
I wrote some code to extract the data from the log files I generated with my script (see 2/24/2019 entry) and plot this data in order to get the plots that Prof. Eno asked for.
#include <TCanvas.h>
#include <TStyle.h>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdlib.h>
using namespace std;
// a helper method for formatting Geant4 spew into arrays
char *removeSpaces(char *str)
{
int i = 0, j = 0;
while (str[i])
{
if (str[i] != ' ')
str[j++] = str[i];
i++;
}
str[j] = '\0';
return str;
}
int fillarr() {
string line;
// the file with the (important) spew from Geant4 runs
ifstream infile("B4aLogpi-.txt");
// some vectors to read in spew
vector<string> meanString;
vector<string> rmsString;
vector<string> energyString;
// make sure file open was successful
if (!infile)
{
cout << "unable to open logfile";
}
// for every line in the logfile
while (getline(infile, line))
{
istringstream iss(line);
string sub = line.substr(0, 12);
if (line.substr(0, 4).compare("Run ")==0){
energyString.push_back(line.substr(6, 4));
}
if (sub.compare( " EGap : mean")==0)
{
meanString.push_back(line.substr(15, 7));
rmsString.push_back(line.substr(32, 7));
// countEntries++;
}
}
// make some arrays
// here is an annoying thing but a problem for later - have to manually enter
// theSize because my attempts to get the size of the energyString vector all
// return 0 for some reason...
static const int theSize = 8;
Double_t Energy[theSize];
Double_t Mean[theSize];
Double_t RMS[theSize];
Double_t Resolution[theSize];
cout << "Energy\t\tMean\t\tRMS\t\tResolution\n";
for (int i = 0; i < theSize; i++)
{
// parse through the vectors we generated from the logfiles, remove all spaces
// so that they can be converted to doubles and added to the appropriate array
string s = energyString.at(i);
cout << i << endl;
static const int n = s.length();
char char_array[n+1];
strcpy(char_array, s.c_str());
removeSpaces(char_array);
double d = strtod(char_array, NULL);
Energy[i] = d;
// for mean...
s = meanString.at(i);
char char_array2[n+1];
strcpy(char_array2, s.c_str());
removeSpaces(char_array2);
d = strtod(char_array2, NULL);
Mean[i] = d;
// for rms
s = rmsString.at(i);
char char_array3[n+1];
strcpy(char_array3, s.c_str());
removeSpaces(char_array3);
d = strtod(char_array3, NULL);
RMS[i] = d;
// for resolution
Resolution[i] = RMS[i]/Mean[i];
}
// make some graphs and draw them
TGraph *graph1 = new TGraph(i, Energy, Mean);
graph1->SetTitle("Scale (Mean vs Energy) for pi-");
TCanvas *c1 = new TCanvas("c1", "Mean vs Energy", 200, 10, 600, 400);
graph1->Draw("AC*");
TGraph *graph2 = new TGraph(i, Energy, Resolution);
graph2->SetTitle("Resolution vs Energy for pi-");
TCanvas* c2 = new TCanvas("c2", "Resolution vs Energy", 200, 10, 600, 400);
graph2->Draw("AC*");
TGraph *graph3 = new TGraph(i, Energy, RMS);
TCanvas* c3 = new TCanvas("c3", "RMS vs Energy", 200, 10, 600, 400);
graph3->SetTitle("RMS vs Energy");
graph3->Draw("AC*");
for (int j = 0; j < theSize; j++){
cout << Energy[j] << "\t\t" << Mean[j] << "\t\t" << RMS[j] << "\t\t" << Resolution[j] << endl;
}
return 0;
}
Prof. Eno asked us to make six plots:
Energy Scale Vs Particle Energy for electrons, charged pions, neutrons (5 energies atleast per graph)
Energy resolution Vs Particle Energy for electrons, charged pions, neutrons (5 energies atleast per graph)
To automate this process I bit, I wrote a script to perform Geant runs for me and write the necessary data to a text file:
cd CMSSW......
cmsenv
root
I renamed the file so it would not be overwritten and opened in root
TFile* file = TFile::Open("~/junk/defaultDetectorConstruction/500MeVElectrons.root");
Then to see the objects in the file:
.ls
I got output:
I also fit a gaussian to some of my data, as seen below, and then got the following output, also below:
I worked through some of the examples and exercises Prof. Eno has at https://sites.google.com/a/physics.umd.edu/physhonr268n/exercises#TOC-GEANT
Prof. Eno gave me some sources to learn more about the project. Here, I have included the links she provided me as well as my own notes as I went over the sources:
Prof. Eno asked us to calculate for the B4a example:
Energy Scale Vs Particle Energy for electrons, charged pions, neutrons (5 energies at least per graph)
Energy resolution Vs Particle Energy for electrons, charged pions, neutrons (5 energies at least per graph)
To automate this task, I thought I would write a script to do multiple runs for me. Here is the finished script:
Running Geant4 example B4a generates a root file B4.root. We can open in root:
I modified the B4a example to get a sense for Geant4
Created a new macro:
cd junk/B4a-build
emacs myRun.mac
Then, in the macro:
# initialize
/run/initialize
# set the particle to a muon
/gun/particle/mu+
# set the energy of the particle
/gun/energy/ 500 MeV
# do 1000 runs (1000 particles will be shot)
/run/beamOn 1000
# exit
exit
I then ran the example several times, changing the particle I was using and the energy of the particle. Here is one of the histograms I generated:
Then, I modified some detector properties in the B4DetectorConstruction.cc file:
http://ias.ust.hk/program/shared_doc/2019/201901hep/program/20190117_2042_am_Paolo%20Giacomelli.pdf (Introduction to CEPC)
https://www.sciencedirect.com/science/article/pii/S0168900211005572 (EM calorimetry)
1. General Introduction
calorimeters absorb energy from incident particle and produce signals w/amplitudes proportional to the particle's energy
the energy is absorbed due to a cascade process (secondary particle production)
the number of secondary particles produced (n) is on average proportional to the energy of the incident particle (Eo)
the resolution of the calorimeter is grows with root n
depth (of the calorimeter) needed to contain the cascade grows only logarithmically with energy
as opposed to mag spectrometer, whose lengths needs to increase linearly w/momentum
this means calorimeters are v powerful for high energy physics
calorimeter is most practical method of detection/energy measurement for neutral particles
2. General Principles
Electrons travelling through matter lose energy through radiation of photons (bremsstrahlung)
mean rate of energy loss varies ~linearly w energy
bremsstrahlung occurs in the electric field of atomic nuclei
amplitude is approx proportional to Z
energy lost per unit depth is -dE/dx ~= E/Xo (Xo is radiation length, based on rate of loss in a specific material)
bremsstrahlung also occurs when incident electrons interact w/ electrons in material
When photons have enough energy, they interact with matter through pair production
Energy is also lost by electrons through ionization
Above an ionization minimum, the rate of loss due to ionization rises logarithmically with energy
this in unlike the rate of energy loss through bremsstrahlung, which rises ~linearly with energy
The critical energy (energy lost due to ionization = energy lost due to bremsstrahlung)
Ec = 550/Z MeV (approximation valid for Z > 12)
2.2 EM Cascades
high energy photon/electron generates EM cascade through bremsstralung and pair production
average energy of each newly produced particle in the cascade decreases until the energy falls to the critical energy, then the electron stops
2.3 Shower Containment
an important thing to consider in calorimeter design is the size of showers (both laterally and longitudinally) in the chosen absorber medium
there are a couple different parametrizations that have been developed to represent containment depth (see Equations pdf)
rms spread in energy leaking from back of absorber is ~1/2 leakage
transverse spread of cascade is from (mostly) the scattering of electrons
3. Energy Resolution
3.1 Introduction
2 types of calorimeters
sampling:
a dense absorber (high Z, like lead, copper., etc.), interwoved with activelayer (silicon, plastic, etc.)
homogeneous
single medium
https://www.sciencedirect.com/science/article/pii/S0168900211019851 (Hadron calorimetry)
Geant:
Connected to T3 cluster via Putty
Made sure to download Xming and select SSH > X11 > Enable X11 forwarding
Then ssh-ed to the cluster
Prof. Eno provided the following commands:
source /cvmfs/sft.cern.ch/lcg/contrib/gcc/6.3/x86_64-slc6/setup.csh
source /cvmfs/geant4.cern.ch/geant4/10.5/x86_64-slc6-gcc63-opt-MT/CMake-setup.csh
setenv CXX `which g++`
setenv CC `which gcc`
setenv PATH /cvmfs/sft.cern.ch/lcg/contrib/CMake/3.11.1/Linux-x86_64/bin:${PATH}
cp -R /cvmfs/geant4.cern.ch/geant4/10.5/share/examples/basic/B4/B4a .
mkdir build
cd build
cmake -DGeant4_DIR=/cvmfs/geant4.cern.ch/geant4/10.5/x86_64-slc6-gcc63-opt/lib64/GEANT4-10.5.0 ../B4a
make
./exampleB4a
Myself and the other member of my group met with professor Eno to discuss the basics of our work for the next semester. We will be helping with some potential calorimeter designs for a proposed future project (the CEPC).
***************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
$ ls (and $ ls -l) - list the files in the current directory (list files one per line)
$ pwd - print working directory
$ mkdir [new_Directory] - makes a new directory
$ rmdir [Directory] - removes an empty directory
$ touch [new_file] - Creates a new file in the current directory
$ wget [URL] - downloads content from the web
$ mv [file] [destination] - move a file to a different directory
Basic Usage Steps:
Go to the File Icon and "Open Files from Web"
Can adjust the view with the zoom buttons and different view types (orthographic, etc.)
From the tutorial video:
Get rid of Tracks (reco)
Turn on ecal barrel to see the border of the inner detector
Turn on Missing Et (PF)
In the example, different colored tracks represent different particles:
Green - electron or positron
Purple - missing energy, often a neutrino
Red - muons
You can click on tracks to get some information about them. Use shift + click to get invariant mass
#!/bin/tcsh
# here we can put some comments
# this is a trivial script but can serve as an example
# a script can take inputs. These are assigned variable names $1, $2 etc
# based on their position
# here we create an environmental variable ARG and assign to it the value of the first input
set ARG=$1
# here as a bug statement we echo out the value to the screen
echo $ARG
# here we have it look for all the files in / and its subdirectories that
# contain somewhere in the file name the string we inputted
find / -name "*$ARG*" -print
This script takes in an argument (when I ran it in the screenshot above, for example the argument is "cms"). Then it assigns the value of the variable ARG to whatever argument was input and prints out the contents of the variable ARG.
This script replaces all instances of a certain word in a text file with a different word:
My script:
#!/bin/tcsh ( set oldtxt=$1 #set the variable oldtxt to the first input
set newtxt=$2 #set the variable newtxt to the second input
set ARG=$3 #set the file name to the third input
sed -i -e 's/'"$oldtxt"'/'"$newtxt"'/g' $ARG #replace all instances of oldtxt withing ARG to newtxt
cat $ARG #print new file to the screen - did this more for testing purposes when writing the script
I saved the script, ran chmod.
I created a text file and inserted some text (the output of the first cat text.txt below)
Then I ran tcsh replaceword.tcsh was is text.txt
And got the text but with all the “was” replaced with “is.”
First script:
#include <iostream> //the include command inserts the contents of a secondary file into the file, in particlular iostream provides basic input/output functions
using namespace std; //a namespace is a place that contains definitions for functions, variables, etc. The std namespace includes functions like cout
int main() { //main method, executed when program is run
cout <<"Hello World!" << endl; //Print hello world to screen followed by end line (endl)
return 0; //Exit the program
}
Then I gave commands in terminal:
g++ main.cpp (g++ compiles the C++ code into a form the computer can understand, but nothing was printed to the terminal after this command)
./a.out (this command made the output of the main.cpp program print to the terminal, the command is used to print the "assembler output")
Versions 4.4.4 and 4.4.7 are used.
The version being used can also be found with $ g++ -dumpspecs
The folder for the 4.4.4 version has the following files
The file /usr/include/math.h includes "Declarations for math functions."
Note: iostream provides basic input/output functions, the namespace std provides definitions for useful functions and variables, like cout
When I compile and run assembler output:
hello world
i = 2
a = 3.3
a*i = 6
Note: iostream provides basic input/output functions, the namespace std provides definitions for useful functions and variables, like cout
Output:
n is 10
n is now 9
n is now 10
prop is 1
prop is 0
prop is 1
Note: iostream provides basic input/output functions, the namespace std provides definitions for useful functions and variables, like cout
I took the following code, written using a while loop:
Note: iostream provides basic input/output functions, the namespace std provides definitions for useful functions and variables, like cout
Then, I rewrote the code to perform the same function, only using for loops instead of while loops:
You can see that each result in the same output:
The following code demonstrates use of if and else statements. Another logic statement is the "else if", which is used after an if statement. If the if statement evaluates to false, the condition of the else if will be checked next.
The basic structure of such statements is:
if (condition) {
do stuff;
}
else if (another condition) {
do different stuff;
}
else {
do different different stuff;
}
Note that while using else if or else statements is not necessary to make the code work, there needs to be an if statement first to then use an else if or else.
Note: iostream provides basic input/output functions, the namespace std provides definitions for useful functions and variables, like cout
The output is:
n is 10
Some information on pointers:
When you store a variable, you are storing the value of the variable at some memory address
In C++, &variable_name will return the location that variable_name is being stored at
If you declare a variable as equal to the memory address of another variable, then the first variable "points" to the location of the second variable:
i.e.: int a_pointer = &an_int;
Specifying the type of value of the pointer (int, double, etc) is important! Otherwise the program can't interpret the data stored in the memory location.
Calling a_pointer will return the memory location of an_int
Calling *a_pointer lets you access the value stored in the memory that a_pointer points to
Note: iostream provides basic input/output functions, the namespace std provides definitions for useful functions and variables, like cout
These programs demonstrate some key features of using pointers. The comments on each line of code provide more information:
What do you need for an accelerator?
Something to accelerate - a proton. You can get these by stripping electrons from hydrogen gas.
Linac - a linear accelerator. This uses an electric field to accelerate the proton in a straight line.
Circular accelerator - to move the protons in a circle, you need to use both electric and magnetic fields. Uses RF cavities to energize the protons.
Here is some code demonstrating the use of arrays in C++, including comments on what the code does:
#include <iostream>
using namespace std;
int main() {
//define an array ii
int ii[3] = {1,2,3};
//define an integer j
int j=0;
//while the integer j is less than 3, we print out " ii of ", the value of j, and the value stored in the jth position of ii. Then j is incremented.
while (j<3) {
cout <<" ii of "<<j<<" is "<<ii[j]<<endl;
j++;
}
//define a 2D array LL, with 2 rows and 3 columns
int LL[2][3] = {1,2,3,4,5,6};
//define and integer j=0, integer k
j=0;
int k;
//while the value of j is less than 2: set k=0
//then enter the inner while loop: while, print out " LL of ", the value of j, the value of k, and the value in the jth row and kth col of LL
while (j<2) {
k=0;
while (k<3) {
cout<<" LL of "<<j<<" "<<k<<" is "<<LL[j][k]<<endl;
k++; //increment k
} //end of inner loop
j++; //increment j
} //end of outer loop
return 0; //return 0 to main method
} //end main method
Some key points to remember about arrays:
The indices start at 0, not 1
The code below demonstrates how to use the ofstream class to write to text files.
This is an example of some code, MAIN.cpp, that uses the function from another file, dotprod.cpp:
MAIN.cpp:
/* MAIN.CPP */
#include <iostream>
#include <fstream>
// include the program dotprod.cpp so that we can find the dot_prod function
#include "dotprod.cpp"
using namespace std;
int main () {
// declare the vectors
double vector1[3];
double vector2[3];
// open the input file
ifstream infile;
infile.open("vectors.txt");
// store the input in the vectors and print the vectors for the user
infile>>vector1[0]>>vector1[1]>>vector1[2];
cout<<" Vector 1 is ("<<vector1[0]<<","<<vector1[1]<<","<<vector1[2]<<")"<<endl;
infile>>vector2[0]>>vector2[1]>>vector2[2];
cout<<" Vector 2 is ("<<vector2[0]<<","<<vector2[1]<<","<<vector2[2]<<")"<<endl;
// close the input file
infile.close();
// call the dot_prod function from dotprod.cpp
dot_prod(vector1,vector2);
return 0;
}
dotprod.cpp:
Recap!
Physics:
Standard model
Confirmed by many predictions
Describes fundamental particles and forces
Fundamental particles:
Leptons
Electron - electron, muon, tau
Neutrino - electron neutrino, muon neutrino, tau neutrino
Quarks
Up, charm top
Down, strange, bottom
Forces
Gravity (?)
Strong nuclear
Weak nuclear
EM
EM and weak are now combined "electroweak"
Higgs boson
Mass, spin, charge - properties of particles
Relativity
4-vectors
Space-time 4 vector s = (t, x, y, z)
Magnitude of s squared is t^2 - |d^2|
Momentum-energy
Magnitude p^2 = E^2 - P^2
Invariant mass (rest mass) stays constant no matter the frame
Relativistic mass = gamma x rest mass x c^2
Units
Natural units:
c = h = 1
c -> speed of light
h -> Planck's constant
Energy is in eV
Mass is in eV/c -> c is 1 so mass is in eV
Breit-Wigner
Models unstable particles (resonances)
Detectors
Beam pipe
Tracker
Calorimeter
EM calorimeter
Hadron calorimeter
Muon chamber
Solenoid
Formula for motion in a magnetic field
Computing:
Linux - an OS
Root
Shell scripting - helpful for automating things
C++
Variables, types, loops, conditionals,
What sort of particles do we see in a detector?
Muons
Electrons - produce tracks in the tracker, activity in the EM calorimeter
Photon - no track in the tracker, but activity in the EM calorimeter
Hadrons - if they are charged, will have at track, will deposit energy in hadronic calorimeter
Proton
Neutron
Pions
Kaons
Channels are individual wires coming out of the detector, around 80 million at LHC
How do we know how many neutrinos there are?
Energy and momentum must be conserved
You can tell how much total energy was lost to neutrinos, but not how many neutrinos were created
Monte Carlo:
Simulated randomness
Set up Mad Graph system on VM.
Future classes schedule:
Nov. 6, Nov. 8: C++ class Lorentz vector
Nov. 13: Python
Nov 15: LZ Presentation + Review for Test
Nov. 20: Test
Nov. 29 - Dec. 6: Presentations
Setting up a space to work with Mad Graph, extracting Mad Grah from the tar file
mkdir MCProduction
mv ~/Downloads/MG5_aMC_v2.6.0.tar.gz MCProduction/
cd MCProduction/
tar -xvzf MG5_aMC_v2.6.0.tar.gz
To start madgraph
./bin/mg5_aMC
Generating some processes
Listing the processes, displaying particles
MG5_aMC>display processes
MG5_aMC>display particles
MG5_aMC>display multiparticles
Adding a process
Creating process outputs and generating events:
MG5_aMC>output MY_FIRST_MG5_RUN
MG5_aMC> launch MY_FIRST_MG5_RUN
Access the results in this place and unzip them:
MY_FIRST_MG5_RUN/Events/run_01/ unweighted_events.lhe.gz
gunzip unweighted_events.lhe.gz
Then I downloaded lhe2root.py from the class website
Run the lhe2root.py program and run in root.
python lhe2root.py MY_FIRST_MG5_RUN/Events/run_01/unweighted_events.lhe MY_FIRST_MG5_RUN.root
root -l MY_FIRST_MG5_RUN.root
Now we get some results! There is a root file and there are some plots, such as:
HW 9.pdf - see this for the coding exercises
Click to view full code/output
From GitHub, I obtained the Python code for the deepdream AI, which looks for features in images and amplifies them (even if the features aren't really there to begin with at all...). I uploaded the deep_dream.py program and an image (clouds.jpg) to my Google Drive, and then in Colaboratory ran:
An image produced using deepdream.py
This was the original image: