StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StjTowerEnergyListWriter.cxx
1 // $Id: StjTowerEnergyListWriter.cxx,v 1.4 2008/08/04 06:10:46 tai Exp $
2 #include "StjTowerEnergyListWriter.h"
3 
4 #include <TDirectory.h>
5 #include <TTree.h>
6 
7 #include <iostream>
8 
10 
11 using namespace std;
12 
13 StjTowerEnergyListWriter::StjTowerEnergyListWriter(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("nTowers" , &_nTowers , "nTowers/I" );
23  _tree->Branch("energy" , _energy , "energy[nTowers]/D" );
24  _tree->Branch("towerId" , _towerId , "towerId[nTowers]/I" );
25  _tree->Branch("towerEta" , _towerEta , "towerEta[nTowers]/D" );
26  _tree->Branch("towerPhi" , _towerPhi , "towerPhi[nTowers]/D" );
27  _tree->Branch("adc" , _adc , "adc[nTowers]/i" );
28  _tree->Branch("pedestal" , _pedestal , "pedestal[nTowers]/D" );
29  _tree->Branch("rms" , _rms , "rms[nTowers]/D" );
30  _tree->Branch("towerR" , _towerR , "towerR[nTowers]/D" );
31  _tree->Branch("vertexX" , &_vertexX , "vertexX/D" );
32  _tree->Branch("vertexY" , &_vertexY , "vertexY/D" );
33  _tree->Branch("vertexZ" , &_vertexZ , "vertexZ/D" );
34  _tree->Branch("status" , _status , "status[nTowers]/I" );
35  _tree->Branch("detectorId" , &_detectorId , "detectorId/I" );
36  _tree->Branch("runNumber" , &_runNumber , "runNumber/I" );
37 }
38 
39 void StjTowerEnergyListWriter::Fill(const StjTowerEnergyList& energyList)
40 {
41  if(energyList.empty()) return;
42 
43  _runNumber = energyList[0].runNumber;
44  _eventId = energyList[0].eventId;
45  _detectorId = energyList[0].detectorId;
46 
47  _vertexX = energyList[0].vertexX;
48  _vertexY = energyList[0].vertexY;
49  _vertexZ = energyList[0].vertexZ;
50 
51  _nTowers = energyList.size();
52  for(int i = 0; i < _nTowers; ++i) {
53  const StjTowerEnergy& tower = energyList[i];
54  _towerId[i] = tower.towerId;
55  _towerR[i] = tower.towerR;
56  _towerEta[i] = tower.towerEta;
57  _towerPhi[i] = tower.towerPhi;
58  _energy[i] = tower.energy;
59  _adc[i] = tower.adc;
60  _pedestal[i] = tower.pedestal;
61  _rms[i] = tower.rms;
62  _status[i] = tower.status;
63  }
64 
65  _tree->Fill();
66 }
67 
68 void StjTowerEnergyListWriter::Finish()
69 {
70  _tree->BuildIndex("runNumber", "eventId");
71 }