]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Alieve/TPCData.cxx
Merge from EVE-dev to HEAD.
[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
75a20dc1 159 Short_t threshold = fLoadThreshold;
160
915dabe1 161 while (input.Next()) {
162 if (input.IsNewSector()) {
163 if(inFill) {
75a20dc1 164 secData->EndPad(fAutoPedestal, threshold);
915dabe1 165 inFill = kFALSE;
166 }
167 sector = input.GetSector();
168 if(sector >= 36) {
169 sector -= 36;
170 rowOffset = TPCSectorData::GetInnSeg().GetNRows();
171 } else {
172 rowOffset = 0;
173 }
174 secData = GetSectorData(sector, spawnSectors);
175 }
176 if (secData == 0)
177 continue;
178
179 if (input.IsNewPad()) {
180 if(inFill) {
75a20dc1 181 secData->EndPad(fAutoPedestal, threshold);
915dabe1 182 inFill = kFALSE;
183 }
184 row = input.GetRow() + rowOffset;
185 pad = input.GetPad();
186
187 if(pad >= TPCSectorData::GetNPadsInRow(row)) {
188 if(warn) {
189 Warning(eH.Data(), "pad out of range (row=%d, pad=%d, maxpad=%d).",
190 row, pad, TPCSectorData::GetNPadsInRow(row));
191 }
192 continue;
193 }
194
75a20dc1 195 TPCSectorData::PadRowHack* prh = secData->GetPadRowHack(row, pad);
196 if(prh != 0) {
75a20dc1 197 threshold = prh->fThrExt + Short_t(prh->fThrFac*fLoadThreshold);
198 } else {
199 threshold = fLoadThreshold;
200 }
201
915dabe1 202 secData->BeginPad(row, pad, kTRUE);
092578a7 203 inFill = kTRUE;
204 lastTime = 1024; lastTimeWarn = kFALSE;
915dabe1 205 }
206
d6433e5d 207 time = input.GetTime();
208 signal = input.GetSignal();
092578a7 209 if(time >= lastTime) {
210 if(lastTimeWarn == kFALSE) {
5987168b 211 if(warn)
212 Warning(eH.Data(), "time out of order (row=%d, pad=%d, time=%d, lastTime=%d).",
213 row, pad, time, lastTime);
092578a7 214 lastTimeWarn = kTRUE;
215 }
216 continue;
217 }
218 lastTime = time;
d6433e5d 219 if(fAutoPedestal) {
220 secData->RegisterData(time, signal);
221 } else {
75a20dc1 222 if(signal > threshold)
d6433e5d 223 secData->RegisterData(time, signal - fLoadPedestal);
224 }
915dabe1 225 }
226
227 if(inFill) {
75a20dc1 228 secData->EndPad(fAutoPedestal, threshold);
915dabe1 229 inFill = kFALSE;
230 }
231}