You should have Root installed on your computer to produce the plots and view the results. To test this, simply run root -l
in a terminal. If Root is missing, go to http://root.cern.ch/drupal/content/downloading-root, download the latest version, and follow the instructions on this page http://root.cern.ch/drupal/content/installing-root-source.
The following templates are a starting point for your code. You will create two programs: one to generate the events and one to run the Kalman filter on them.
Copy/paste the following code in a file called generation.cpp
:
#include <iostream>
#include "TFile.h"
#include "TRandom3.h"
#include "TTree.h"
int generation() {
// Create a file
TFile* file = new TFile("myfile.root", "recreate");
// Create the random number generator
TRandom3* generator = new TRandom3(0);
// Create a root Tree
TTree* tree = new TTree("events", "My events");
// Create the variables that will go in the tree
double gaus;
double poisson;
double uniform[2];
tree->Branch("gaus", &gaus);
tree->Branch("poisson", &poisson);
tree->Branch("uniform", uniform, "uniform[2]/D");
// Generate 10000 "events"
for (unsigned int event = 0; event < 10000; ++event) {
// Pick random values
gaus = generator->Gaus(0., 4.);
poisson = generator->Poisson(4);
uniform[0] = generator->Uniform(1., 5.);
uniform[1] = generator->Uniform(-5., -1.);
// Fill the tree
tree->Fill();
// Print something
std::cout << "Event n" << event << " done!" << std::endl;
}
// Write the tree
tree->Write();
// Close the file
file->Close();
return 0;
}
and the following code in a file called kalman.cpp
:
#include <vector>
#include "TFile.h"
#include "TTree.h"
#include "TH1D.h"
#include "TString.h"
int kalman() {
// Create a file
TFile* file = new TFile("myfile.root", "update");
// Get the tree
TTree* tree = (TTree*) file->Get("events");
// Create a vector
std::vector< TH1D* > th1ds;
// Automatically create histograms
for (unsigned int i = 0; i < 10; ++i) {
TString title = "HISTO_"; title += i + 1; title += "_A";
th1ds.push_back(new TH1D(title, title, 100, 0., 0.));
}
// Manually create histograms
th1ds.push_back(new TH1D("hist_gaus", "Gaussian distribution;X;Number of events", 100, -10., 10.));
th1ds.push_back(new TH1D("hist_poisson", "Poisson distribution;X;Number of events", 100, 0., 20.));
th1ds.push_back(new TH1D("hist_uniform", "Uniform distribution;X;Number of events", 100, -6., 6.));
// Create the variables for the tree
double gaus;
double poisson;
double uniform[2];
// Link the variables to the tree
tree->SetBranchAddress("gaus", &gaus);
tree->SetBranchAddress("poisson", &poisson);
tree->SetBranchAddress("uniform", uniform);
// Loop over the "events"
for (unsigned int event = 0; event < tree->GetEntries(); ++event) {
// Get the i th value of the three
tree->GetEntry(event);
for (unsigned int i = 0; i < 1; ++i) th1ds.at(i)->Fill(0);
// Fill the histograms
th1ds.at(10)->Fill(gaus);
th1ds.at(11)->Fill(poisson);
th1ds.at(12)->Fill(uniform[0]);
th1ds.at(12)->Fill(uniform[1]);
}
// Write all the histograms
for (unsigned int i = 0; i < th1ds.size(); ++i) th1ds.at(i)->Write();
// Close the file
file->Close();
return 0;
}
To run those templates, launch root (root -l
) and execute .X generation.cpp
and .X kalman.cpp+
(the + is important when you run the second file!).
Once you have run these commands, a new root file called myfile.root
will be created. To view its content, run root -l
in a terminal. Once root has launched, run TBrowser t
which will open a graphical interface. Using the latter, open the file to view the events (added by generation.cpp) and the histograms (added by kalman.cpp).
Let us consider $ n = 10 $ detection layers with a thickness $ s = 0.1 $ $ X_0 $ and a detection precision (RMS of a Gaussian distribution) $ \sigma = 20 $ $ \mu m $, spaced by a distance $ d = 10 $ cm and placed as represented in the figure bellow. Muons are propagated from an randomly chosen $ y_0 $ with an varying initial angle $ \alpha $ and an initial impulsion of 1, 10, or 100 $ GeV $ $ c^{-1} $. At each detection site, the particles are subject to multiple scattering which modifies their trajectories, but they are not affected by energy losses.
You will have to perform the following tasks:
If you finished your simulation, you can complicate things by doing one or multiple things listed bellow: