This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
root:storemcnumbers [2009/01/07 14:29] – decianm | root:storemcnumbers [2009/01/07 15:16] (current) – decianm | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Storing Monte Carlo numbers in a file ====== | + | ====== Storing Monte Carlo particle |
===== Idea ===== | ===== Idea ===== | ||
- | When analyzing background using Monte Carlo truth information, | + | When analyzing |
The following script loops through the whole tree, calculates the percentage of the respective particle and saves the output in a textfile. It needs as input the tree with the truth-information (e.g. in an nTuple) and the name of the variable. Furthermore, | The following script loops through the whole tree, calculates the percentage of the respective particle and saves the output in a textfile. It needs as input the tree with the truth-information (e.g. in an nTuple) and the name of the variable. Furthermore, | ||
Line 8: | Line 8: | ||
The code was written for a [[addclasstoroot|class which was added to ROOT]]. It should be straightforward to use it in a macro. | The code was written for a [[addclasstoroot|class which was added to ROOT]]. It should be straightforward to use it in a macro. | ||
- | Add the following | + | ==== .hh File ==== |
+ | |||
+ | Add the following | ||
< | < | ||
void storeMCNumbers(TTree* tree, const char* variablename, | void storeMCNumbers(TTree* tree, const char* variablename, | ||
</ | </ | ||
+ | The last argument in the prototype gives the default name of the textfile, that is used as an output. | ||
+ | ==== .cc File ==== | ||
+ | Add the following method to your **.cc-File** (mind the '' | ||
< | < | ||
- | void ana:: | + | void yourclass:: |
| | ||
// -------------------------------------------------------------------------------- | // -------------------------------------------------------------------------------- | ||
// -- Simple method to read out a histogram containing PID-numbers for particles (x-axis) and their | // -- Simple method to read out a histogram containing PID-numbers for particles (x-axis) and their | ||
// -- frequency (y-axis) | // -- frequency (y-axis) | ||
- | // -- Needed inputs are: The tree containing the information, a name for the histogram | + | // -- Needed inputs are: The tree containing the information |
- | // -- and the name of the variable in the tree | + | // -- tree. Optionally, |
// -------------------------------------------------------------------------------- | // -------------------------------------------------------------------------------- | ||
Line 37: | Line 41: | ||
sprintf(out, | sprintf(out, | ||
tree-> | tree-> | ||
- | // | ||
- | // | ||
| | ||
- | // -- Draw the histogram (is this needed?) | ||
- | //TCanvas *c = new TCanvas(); | ||
- | // | ||
// -- Declare a multimap to automatically sort the PID-numbers according to their frequency in % | // -- Declare a multimap to automatically sort the PID-numbers according to their frequency in % | ||
Line 57: | Line 56: | ||
} | } | ||
| | ||
- | // -- Open a file " | + | // -- Open a file to save the output |
+ | // -- Note: The " | ||
fstream PIDfile(filename, | fstream PIDfile(filename, | ||
| | ||
Line 79: | Line 79: | ||
PIDfile.close(); | PIDfile.close(); | ||
delete histo; | delete histo; | ||
- | //delete c; | ||
| | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ===== Notes ===== | ||
+ | If the output-file already exists, the output will be appended. This is useful if you call the method several times for different particles and want to store everything in one file. If you don't like this behaviour, delete the '' |