more plots
[u/mrichter/AliRoot.git] / EVE / Alieve / TPCData.cxx
CommitLineData
915dabe1 1// $Header$
2
3#include "TPCData.h"
4
5#include <Alieve/TPCSectorData.h>
6
7#include <AliSimDigits.h>
8#include <AliTPCParam.h>
9#include <AliTPCRawStream.h>
10#include <AliTPCRawStreamOld.h>
11#include <TTree.h>
12
13using namespace Reve;
14using namespace Alieve;
15
16//______________________________________________________________________
17// TPCData
18//
19// A central manager for TPC data of an event. Can read digits (from
20// a tree: LoadDigits()) and raw-data (via AliRawReader: LoadRaw()).
21//
22// The sector data is stored in 36 TPCSectorData objects.
23// Sectors 0 - 17: +z side, 18 - 35: -z side.
24// No separation of inner/outer segments, use row numbers for addressing.
25//
092578a7 26// Threshold application and pedestal subtraction can be performed at
27// load time: use SetLoadThreshold(thresh) and SetLoadPedestal(ped).
28//
29// For raw-data (loaded using LoadRaw) pedestals can be calculated
30// automatically per pad. Use SetAutoPedestal(kTRUE) to activate it.
31// You might still want to set load threshold (default iz zero).
32//
915dabe1 33
2aef44c1 34ClassImp(TPCData)
915dabe1 35
36TPCData::TPCData() :
37 fSectors(36), fSectorBlockSize(65536),
d6433e5d 38 fLoadThreshold(0), fLoadPedestal(0), fAutoPedestal(kFALSE)
915dabe1 39{
40 TPCSectorData::InitStatics();
41}
42
43TPCData::~TPCData()
44{
092578a7 45 DeleteAllSectors();
915dabe1 46}
47
48/**************************************************************************/
49
50void TPCData::CreateSector(Int_t sector)
51{
52 if(fSectors[sector] == 0)
53 fSectors[sector] = new TPCSectorData(sector, fSectorBlockSize);
54}
55
56void TPCData::CreateAllSectors()
57{
58 for(Int_t s=0; s<36; ++s)
59 CreateSector(s);
60}
61
092578a7 62void TPCData::DropAllSectors()
63{
64 for(Int_t s=0; s<36; ++s) {
65 if(fSectors[s] != 0)
66 fSectors[s]->DropData();
67 }
68}
69
70void TPCData::DeleteAllSectors()
71{
72 for(Int_t s=0; s<36; ++s) {
73 delete fSectors[s];
74 fSectors[s] = 0;
75 }
76}
77
915dabe1 78/**************************************************************************/
79
80TPCSectorData* TPCData::GetSectorData(Int_t sector, Bool_t spawnSectors)
81{
82 if(sector < 0 || sector > 35) return 0;
83 if(fSectors[sector] == 0 && spawnSectors)
84 CreateSector(sector);
85 return fSectors[sector];
86}
87
88/**************************************************************************/
89
90void TPCData::LoadDigits(TTree* tree, Bool_t spawnSectors)
91{
92 // Load data from TTree of AliSimDigits.
93 // If spawnSectors is false only sectors that have been created previously
94 // via CreateSector() are loaded.
95 // If spawnSectors is true sectors are created if data for them is encountered.
96
97 AliSimDigits digit, *digitPtr = &digit;
98 tree->GetBranch("Segment")->SetAddress(&digitPtr);
99
100 Int_t sector, row, pad, curPad;
101 Short_t time, signal;
102 Bool_t inFill = kFALSE;
103 TPCSectorData* secData = 0;
104
105 Int_t numEnt = (Int_t) tree->GetEntries();
106 for (Int_t ent=0; ent<numEnt; ent++) {
107 tree->GetEntry(ent);
108 Alieve::TPCSectorData::GetParam().AdjustSectorRow(digit.GetID(), sector, row);
109 if(sector >= 36) {
110 sector -= 36;
111 row += TPCSectorData::GetInnSeg().GetNRows();
112 }
113 secData = GetSectorData(sector, spawnSectors);
114 if(secData == 0)
115 continue;
116
117 if(digit.First() == kFALSE)
118 continue;
119 curPad = -1;
120 do {
121 pad = digit.CurrentColumn();
122 time = digit.CurrentRow();
123 signal = digit.CurrentDigit();
124
125 if(pad != curPad) {
126 if(inFill)
d6433e5d 127 secData->EndPad(fAutoPedestal, fLoadThreshold);
915dabe1 128 secData->BeginPad(row, pad, kFALSE);
129 curPad = pad;
130 inFill = kTRUE;
131 }
132 if(signal > fLoadThreshold)
b56d8877 133 secData->RegisterData(time, signal - fLoadPedestal);
915dabe1 134
135 } while (digit.Next());
136 if(inFill) {
d6433e5d 137 secData->EndPad(fAutoPedestal, fLoadThreshold);
915dabe1 138 inFill = kFALSE;
139 }
140 }
141}
142
5987168b 143void TPCData::LoadRaw(AliTPCRawStream& input, Bool_t spawnSectors, Bool_t warn)
915dabe1 144{
145 // Load data from AliTPCRawStream.
146 // If spawnSectors is false only sectors that have been created previously
147 // via CreateSector() are loaded.
148 // If spawnSectors is true sectors are created if data for them is encountered.
149
150 static const Exc_t eH("TPCData::LoadRaw ");
151
d6433e5d 152 Int_t sector = -1, row = -1, pad = -1, rowOffset = 0;
092578a7 153 Short_t time, signal;
154 Bool_t inFill = kFALSE;
155 Short_t lastTime = 9999;
156 Bool_t lastTimeWarn = kFALSE;
915dabe1 157 TPCSectorData* secData = 0;
158
159 while (input.Next()) {
160 if (input.IsNewSector()) {
161 if(inFill) {
d6433e5d 162 secData->EndPad(fAutoPedestal, fLoadThreshold);
915dabe1 163 inFill = kFALSE;
164 }
165 sector = input.GetSector();
166 if(sector >= 36) {
167 sector -= 36;
168 rowOffset = TPCSectorData::GetInnSeg().GetNRows();
169 } else {
170 rowOffset = 0;
171 }
172 secData = GetSectorData(sector, spawnSectors);
173 }
174 if (secData == 0)
175 continue;
176
177 if (input.IsNewPad()) {
178 if(inFill) {
d6433e5d 179 secData->EndPad(fAutoPedestal, fLoadThreshold);
915dabe1 180 inFill = kFALSE;
181 }
182 row = input.GetRow() + rowOffset;
183 pad = input.GetPad();
184
185 if(pad >= TPCSectorData::GetNPadsInRow(row)) {
186 if(warn) {
187 Warning(eH.Data(), "pad out of range (row=%d, pad=%d, maxpad=%d).",
188 row, pad, TPCSectorData::GetNPadsInRow(row));
189 }
190 continue;
191 }
192
193 secData->BeginPad(row, pad, kTRUE);
092578a7 194 inFill = kTRUE;
195 lastTime = 1024; lastTimeWarn = kFALSE;
915dabe1 196 }
197
d6433e5d 198 time = input.GetTime();
199 signal = input.GetSignal();
092578a7 200 if(time >= lastTime) {
201 if(lastTimeWarn == kFALSE) {
5987168b 202 if(warn)
203 Warning(eH.Data(), "time out of order (row=%d, pad=%d, time=%d, lastTime=%d).",
204 row, pad, time, lastTime);
092578a7 205 lastTimeWarn = kTRUE;
206 }
207 continue;
208 }
209 lastTime = time;
d6433e5d 210 if(fAutoPedestal) {
211 secData->RegisterData(time, signal);
212 } else {
213 if(signal > fLoadThreshold)
214 secData->RegisterData(time, signal - fLoadPedestal);
215 }
915dabe1 216 }
217
218 if(inFill) {
d6433e5d 219 secData->EndPad(fAutoPedestal, fLoadThreshold);
915dabe1 220 inFill = kFALSE;
221 }
222}