User Tools

Site Tools


root:storemcnumbers

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
root:storemcnumbers [2009/01/07 14:39] decianmroot:storemcnumbers [2009/01/07 15:16] (current) decianm
Line 1: Line 1:
-====== Storing Monte Carlo numbers in a file ======+====== Storing Monte Carlo particle numbers in a file ======
 ===== Idea ===== ===== Idea =====
-When analyzing background using Monte Carlo truth information, it may be useful to check the real identity of a particle that was considered a Kaon, a Muon, etc.+When analyzing signal or background using Monte Carlo truth information, it may be useful to check the real identity of a particle that was considered a Kaon, a Muon, etc.
  
 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 name of the output-file can be specified. 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 name of the output-file can be specified.
Line 18: Line 18:
  
 ==== .cc File ==== ==== .cc File ====
-Add the following method to your **.cc-File**+Add the following method to your **.cc-File** (mind the ''yourclass''!):
 <code> <code>
-void ana::storeMCNumbers(TTree* tree, const char* variablename, const char* filename ){+void yourclass::storeMCNumbers(TTree* tree, const char* variablename, const char* filename ){
      
   // --------------------------------------------------------------------------------   // --------------------------------------------------------------------------------
Line 57: Line 57:
      
   // -- Open a file to save the output   // -- Open a file to save the output
 +  // -- Note: The "ios::app" appends the output at the end of the existing file!
   fstream PIDfile(filename, ios::out | ios::app);   fstream PIDfile(filename, ios::out | ios::app);
      
Line 81: Line 82:
 } }
 </code> </code>
 +
 +===== 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 ''| ios::app'' in the code.
root/storemcnumbers.1231335583.txt.gz · Last modified: 2009/01/07 14:39 by decianm