StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StjMCParticleListWriter.cxx
1 // $Id: StjMCParticleListWriter.cxx,v 1.4 2008/08/04 06:10:46 tai Exp $
2 #include "StjMCParticleListWriter.h"
3 
4 #include <TDirectory.h>
5 #include <TTree.h>
6 
7 #include <iostream>
8 
10 
11 using namespace std;
12 
13 StjMCParticleListWriter::StjMCParticleListWriter(const char* treeName, TDirectory* file)
14  : _file(file)
15 {
16  _file->cd();
17  _tree = new TTree(treeName, treeName);
18  _tree->SetAutoSave(kMaxLong64);
19  _tree->SetMaxTreeSize(kMaxLong64);
20 
21  _tree->Branch("eventId" , &_eventId , "eventId/I" );
22  _tree->Branch("nMCParticles" , &_nMCParticles , "nMCParticles/I" );
23  _tree->Branch("mcparticleId" , _mcparticleId , "mcparticleId[nMCParticles]/I" );
24  _tree->Branch("status" , _status , "status[nMCParticles]/I" );
25  _tree->Branch("pdg" , _pdg , "pdg[nMCParticles]/I" );
26  _tree->Branch("pt" , _pt , "pt[nMCParticles]/D" );
27  _tree->Branch("eta" , _eta , "eta[nMCParticles]/D" );
28  _tree->Branch("phi" , _phi , "phi[nMCParticles]/D" );
29  _tree->Branch("m" , _m , "m[nMCParticles]/D" );
30  _tree->Branch("e" , _e , "e[nMCParticles]/D" );
31  _tree->Branch("firstMotherId" , _firstMotherId , "firstMotherId[nMCParticles]/I" );
32  _tree->Branch("lastMotherId" , _lastMotherId , "lastMotherId[nMCParticles]/I" );
33  _tree->Branch("firstDaughterId" , _firstDaughterId , "firstDaughterId[nMCParticles]/I" );
34  _tree->Branch("lastDaughterId" , _lastDaughterId , "lastDaughterId[nMCParticles]/I" );
35  _tree->Branch("vertexZ" , &_vertexZ , "vertexZ/D" );
36  _tree->Branch("runNumber" , &_runNumber , "runNumber/I" );
37 }
38 
39 void StjMCParticleListWriter::Fill(const StjMCParticleList& theList)
40 {
41  if(theList.empty()) return;
42 
43  _runNumber = theList[0].runNumber;
44  _eventId = theList[0].eventId;
45  _vertexZ = theList[0].vertexZ;
46 
47  _nMCParticles = theList.size();
48  for(int i = 0; i < _nMCParticles; ++i) {
49  const StjMCParticle& particle = theList[i];
50  _mcparticleId[i] = particle.mcparticleId;
51  _pdg[i] = particle.pdg;
52  _firstMotherId[i] = particle.firstMotherId;
53  _lastMotherId[i] = particle.lastMotherId;
54  _firstDaughterId[i] = particle.firstDaughterId;
55  _lastDaughterId[i] = particle.lastDaughterId;
56  _pt[i] = particle.pt;
57  _eta[i] = particle.eta;
58  _phi[i] = particle.phi;
59  _m[i] = particle.m;
60  _e[i] = particle.e;
61  _status[i] = particle.status;
62  }
63 
64  _tree->Fill();
65 }
66 
67 void StjMCParticleListWriter::Finish()
68 {
69  _tree->BuildIndex("runNumber", "eventId");
70 }