]>
Commit | Line | Data |
---|---|---|
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 | ||
13 | using namespace Reve; | |
14 | using 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 | 34 | ClassImp(TPCData) |
915dabe1 | 35 | |
36 | TPCData::TPCData() : | |
37 | fSectors(36), fSectorBlockSize(65536), | |
d6433e5d | 38 | fLoadThreshold(0), fLoadPedestal(0), fAutoPedestal(kFALSE) |
915dabe1 | 39 | { |
40 | TPCSectorData::InitStatics(); | |
41 | } | |
42 | ||
43 | TPCData::~TPCData() | |
44 | { | |
092578a7 | 45 | DeleteAllSectors(); |
915dabe1 | 46 | } |
47 | ||
48 | /**************************************************************************/ | |
49 | ||
50 | void TPCData::CreateSector(Int_t sector) | |
51 | { | |
52 | if(fSectors[sector] == 0) | |
53 | fSectors[sector] = new TPCSectorData(sector, fSectorBlockSize); | |
54 | } | |
55 | ||
56 | void TPCData::CreateAllSectors() | |
57 | { | |
58 | for(Int_t s=0; s<36; ++s) | |
59 | CreateSector(s); | |
60 | } | |
61 | ||
092578a7 | 62 | void TPCData::DropAllSectors() |
63 | { | |
64 | for(Int_t s=0; s<36; ++s) { | |
65 | if(fSectors[s] != 0) | |
66 | fSectors[s]->DropData(); | |
67 | } | |
68 | } | |
69 | ||
70 | void 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 | ||
80 | TPCSectorData* 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 | ||
90 | void 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 | } | |
8bb2a8e9 | 132 | if(fAutoPedestal) { |
133 | secData->RegisterData(time, signal); | |
134 | } else { | |
135 | signal -= fLoadPedestal; | |
136 | if(signal >= fLoadThreshold) | |
137 | secData->RegisterData(time, signal); | |
138 | } | |
915dabe1 | 139 | |
140 | } while (digit.Next()); | |
141 | if(inFill) { | |
d6433e5d | 142 | secData->EndPad(fAutoPedestal, fLoadThreshold); |
915dabe1 | 143 | inFill = kFALSE; |
144 | } | |
145 | } | |
146 | } | |
147 | ||
5987168b | 148 | void TPCData::LoadRaw(AliTPCRawStream& input, Bool_t spawnSectors, Bool_t warn) |
915dabe1 | 149 | { |
150 | // Load data from AliTPCRawStream. | |
151 | // If spawnSectors is false only sectors that have been created previously | |
152 | // via CreateSector() are loaded. | |
153 | // If spawnSectors is true sectors are created if data for them is encountered. | |
154 | ||
155 | static const Exc_t eH("TPCData::LoadRaw "); | |
156 | ||
d6433e5d | 157 | Int_t sector = -1, row = -1, pad = -1, rowOffset = 0; |
092578a7 | 158 | Short_t time, signal; |
159 | Bool_t inFill = kFALSE; | |
160 | Short_t lastTime = 9999; | |
161 | Bool_t lastTimeWarn = kFALSE; | |
915dabe1 | 162 | TPCSectorData* secData = 0; |
163 | ||
75a20dc1 | 164 | Short_t threshold = fLoadThreshold; |
165 | ||
915dabe1 | 166 | while (input.Next()) { |
167 | if (input.IsNewSector()) { | |
168 | if(inFill) { | |
75a20dc1 | 169 | secData->EndPad(fAutoPedestal, threshold); |
915dabe1 | 170 | inFill = kFALSE; |
171 | } | |
172 | sector = input.GetSector(); | |
173 | if(sector >= 36) { | |
174 | sector -= 36; | |
175 | rowOffset = TPCSectorData::GetInnSeg().GetNRows(); | |
176 | } else { | |
177 | rowOffset = 0; | |
178 | } | |
179 | secData = GetSectorData(sector, spawnSectors); | |
180 | } | |
181 | if (secData == 0) | |
182 | continue; | |
183 | ||
184 | if (input.IsNewPad()) { | |
185 | if(inFill) { | |
75a20dc1 | 186 | secData->EndPad(fAutoPedestal, threshold); |
915dabe1 | 187 | inFill = kFALSE; |
188 | } | |
189 | row = input.GetRow() + rowOffset; | |
190 | pad = input.GetPad(); | |
191 | ||
192 | if(pad >= TPCSectorData::GetNPadsInRow(row)) { | |
193 | if(warn) { | |
194 | Warning(eH.Data(), "pad out of range (row=%d, pad=%d, maxpad=%d).", | |
195 | row, pad, TPCSectorData::GetNPadsInRow(row)); | |
196 | } | |
197 | continue; | |
198 | } | |
199 | ||
75a20dc1 | 200 | TPCSectorData::PadRowHack* prh = secData->GetPadRowHack(row, pad); |
201 | if(prh != 0) { | |
75a20dc1 | 202 | threshold = prh->fThrExt + Short_t(prh->fThrFac*fLoadThreshold); |
203 | } else { | |
204 | threshold = fLoadThreshold; | |
205 | } | |
206 | ||
915dabe1 | 207 | secData->BeginPad(row, pad, kTRUE); |
092578a7 | 208 | inFill = kTRUE; |
209 | lastTime = 1024; lastTimeWarn = kFALSE; | |
915dabe1 | 210 | } |
211 | ||
d6433e5d | 212 | time = input.GetTime(); |
213 | signal = input.GetSignal(); | |
092578a7 | 214 | if(time >= lastTime) { |
215 | if(lastTimeWarn == kFALSE) { | |
5987168b | 216 | if(warn) |
217 | Warning(eH.Data(), "time out of order (row=%d, pad=%d, time=%d, lastTime=%d).", | |
218 | row, pad, time, lastTime); | |
092578a7 | 219 | lastTimeWarn = kTRUE; |
220 | } | |
221 | continue; | |
222 | } | |
223 | lastTime = time; | |
d6433e5d | 224 | if(fAutoPedestal) { |
225 | secData->RegisterData(time, signal); | |
226 | } else { | |
8bb2a8e9 | 227 | signal -= fLoadPedestal; |
75a20dc1 | 228 | if(signal > threshold) |
8bb2a8e9 | 229 | secData->RegisterData(time, signal); |
d6433e5d | 230 | } |
915dabe1 | 231 | } |
232 | ||
233 | if(inFill) { | |
75a20dc1 | 234 | secData->EndPad(fAutoPedestal, threshold); |
915dabe1 | 235 | inFill = kFALSE; |
236 | } | |
237 | } |