StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StjTrackListWriter.cxx
1 // $Id: StjTrackListWriter.cxx,v 1.4 2008/08/04 06:10:47 tai Exp $
2 #include "StjTrackListWriter.h"
3 
4 #include <TDirectory.h>
5 #include <TTree.h>
6 
7 #include <iostream>
8 
9 ClassImp(StjTrackListWriter)
10 
11 using namespace std;
12 
13 StjTrackListWriter::StjTrackListWriter(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("nTracks" , &_nTracks , "nTracks/I" );
23  _tree->Branch("pt" , _pt , "pt[nTracks]/D" );
24  _tree->Branch("eta" , _eta , "eta[nTracks]/D" );
25  _tree->Branch("phi" , _phi , "phi[nTracks]/D" );
26  _tree->Branch("exitEta" , _exitEta , "exitEta[nTracks]/D" );
27  _tree->Branch("exitPhi" , _exitPhi , "exitPhi[nTracks]/D" );
28  _tree->Branch("trackId" , _trackId , "trackId[nTracks]/S" );
29  _tree->Branch("flag" , _flag , "flag[nTracks]/S" );
30  _tree->Branch("nHits" , _nHits , "nHits[nTracks]/s" );
31  _tree->Branch("charge" , _charge , "charge[nTracks]/S" );
32  _tree->Branch("nHitsPoss" , _nHitsPoss , "nHitsPoss[nTracks]/s" );
33  _tree->Branch("nHitsDedx" , _nHitsDedx , "nHitsDedx[nTracks]/s" );
34  _tree->Branch("nHitsFit" , _nHitsFit , "nHitsFit[nTracks]/s" );
35  _tree->Branch("nSigmaPion" , _nSigmaPion , "nSigmaPion[nTracks]/D" );
36  _tree->Branch("Tdca" , _Tdca , "Tdca[nTracks]/D" );
37  _tree->Branch("dcaZ" , _dcaZ , "dcaZ[nTracks]/D" );
38  _tree->Branch("dcaD" , _dcaD , "dcaD[nTracks]/D" );
39  _tree->Branch("BField" , &_BField , "BField/D" );
40  _tree->Branch("bemcRadius" , &_bemcRadius , "bemcRadius/D" );
41  _tree->Branch("dEdx" , _dEdx , "dEdx[nTracks]/D" );
42  _tree->Branch("trackIndex" , _trackIndex , "trackIndex[nTracks]/I" );
43  _tree->Branch("exitDetectorId", _exitDetectorId , "exitDetectorId[nTracks]/I");
44  _tree->Branch("exitTowerId" , _exitTowerId , "exitTowerId[nTracks]/I" );
45  _tree->Branch("vertexZ" , &_vertexZ , "vertexZ/D" );
46  _tree->Branch("detectorId" , &_detectorId , "detectorId/I" );
47  _tree->Branch("runNumber" , &_runNumber , "runNumber/I" );
48 }
49 
50 void StjTrackListWriter::Fill(const StjTrackList& trackList)
51 {
52  if(trackList.empty()) return;
53 
54  _runNumber = trackList[0].runNumber;
55  _eventId = trackList[0].eventId;
56  _detectorId = trackList[0].detectorId;
57  _vertexZ = trackList[0].vertexZ;
58 
59  _BField = trackList[0].BField;
60  _bemcRadius = trackList[0].bemcRadius;
61 
62  _nTracks = trackList.size();
63  for(int i = 0; i < _nTracks; ++i) {
64  const StjTrack& track = trackList[i];
65  _pt[i] = track.pt;
66  _eta[i] = track.eta;
67  _phi[i] = track.phi;
68  _flag[i] = track.flag;
69  _nHits[i] = track.nHits;
70  _charge[i] = track.charge;
71  _nHitsPoss[i] = track.nHitsPoss;
72  _nHitsDedx[i] = track.nHitsDedx;
73  _nHitsFit[i] = track.nHitsFit;
74  _nSigmaPion[i] = track.nSigmaPion;
75  _Tdca[i] = track.Tdca;
76  _dcaZ[i] = track.dcaZ;
77  _dcaD[i] = track.dcaD;
78  _exitDetectorId[i] = track.exitDetectorId;
79  _exitTowerId[i] = track.exitTowerId;
80  _exitEta[i] = track.exitEta;
81  _exitPhi[i] = track.exitPhi;
82  _dEdx[i] = track.dEdx;
83  _trackIndex[i] = track.trackIndex;
84  _trackId[i] = track.id;
85  }
86 
87  _tree->Fill();
88 }
89 
90 void StjTrackListWriter::Finish()
91 {
92  _tree->BuildIndex("runNumber", "eventId");
93 }