Fixes for inconsistent types in BinarySearch
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTPCData.cxx
CommitLineData
d810d0de 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
915dabe1 3
d810d0de 4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
915dabe1 9
d810d0de 10#include "AliEveTPCData.h"
11
cb4245bb 12#include <EveDet/AliEveTPCSectorData.h>
915dabe1 13
14#include <AliSimDigits.h>
15#include <AliTPCParam.h>
16#include <AliTPCRawStream.h>
915dabe1 17#include <TTree.h>
d810d0de 18
915dabe1 19
57ffa5fb 20//______________________________________________________________________________
915dabe1 21//
22// A central manager for TPC data of an event. Can read digits (from
23// a tree: LoadDigits()) and raw-data (via AliRawReader: LoadRaw()).
24//
d810d0de 25// The sector data is stored in 36 AliEveTPCSectorData objects.
915dabe1 26// Sectors 0 - 17: +z side, 18 - 35: -z side.
27// No separation of inner/outer segments, use row numbers for addressing.
28//
092578a7 29// Threshold application and pedestal subtraction can be performed at
30// load time: use SetLoadThreshold(thresh) and SetLoadPedestal(ped).
31//
32// For raw-data (loaded using LoadRaw) pedestals can be calculated
51346b82 33// automatically per pad. Use SetAutoPedestal(kTRUE) to activate it.
092578a7 34// You might still want to set load threshold (default iz zero).
35//
915dabe1 36
d810d0de 37ClassImp(AliEveTPCData)
915dabe1 38
d810d0de 39AliEveTPCData::AliEveTPCData() :
915dabe1 40 fSectors(36), fSectorBlockSize(65536),
d6433e5d 41 fLoadThreshold(0), fLoadPedestal(0), fAutoPedestal(kFALSE)
915dabe1 42{
a97abca8 43 // Constructor.
44
d810d0de 45 AliEveTPCSectorData::InitStatics();
915dabe1 46}
47
d810d0de 48AliEveTPCData::~AliEveTPCData()
915dabe1 49{
a97abca8 50 // Destructor, deletes all sector-data.
51
092578a7 52 DeleteAllSectors();
915dabe1 53}
54
57ffa5fb 55/******************************************************************************/
915dabe1 56
d810d0de 57void AliEveTPCData::CreateSector(Int_t sector)
915dabe1 58{
a97abca8 59 // Create sector-data for sector if it does not exist already.
60
61 if (fSectors[sector] == 0)
d810d0de 62 fSectors[sector] = new AliEveTPCSectorData(sector, fSectorBlockSize);
915dabe1 63}
64
d810d0de 65void AliEveTPCData::CreateAllSectors()
915dabe1 66{
a97abca8 67 // Create all 36 sectors.
68
69 for (Int_t s=0; s<36; ++s)
915dabe1 70 CreateSector(s);
71}
72
d810d0de 73void AliEveTPCData::DropAllSectors()
092578a7 74{
a97abca8 75 // Drop data of all existing sectors.
76
77 for (Int_t s=0; s<36; ++s) {
78 if (fSectors[s] != 0)
092578a7 79 fSectors[s]->DropData();
80 }
81}
82
d810d0de 83void AliEveTPCData::DeleteAllSectors()
092578a7 84{
a97abca8 85 // Delete all sector-data.
86
87 for (Int_t s=0; s<36; ++s) {
092578a7 88 delete fSectors[s];
89 fSectors[s] = 0;
90 }
91}
92
57ffa5fb 93/******************************************************************************/
915dabe1 94
d810d0de 95AliEveTPCSectorData* AliEveTPCData::GetSectorData(Int_t sector, Bool_t spawnSectors)
915dabe1 96{
a97abca8 97 // Get sector-data for sector. If spawnSectors is true, the
98 // sector-data is created if it does not exist already.
99
100 if (sector < 0 || sector > 35) return 0;
101 if (fSectors[sector] == 0 && spawnSectors)
915dabe1 102 CreateSector(sector);
103 return fSectors[sector];
104}
105
57ffa5fb 106/******************************************************************************/
915dabe1 107
d810d0de 108void AliEveTPCData::LoadDigits(TTree* tree, Bool_t spawnSectors)
915dabe1 109{
110 // Load data from TTree of AliSimDigits.
111 // If spawnSectors is false only sectors that have been created previously
112 // via CreateSector() are loaded.
113 // If spawnSectors is true sectors are created if data for them is encountered.
114
115 AliSimDigits digit, *digitPtr = &digit;
116 tree->GetBranch("Segment")->SetAddress(&digitPtr);
51346b82 117
915dabe1 118 Int_t sector, row, pad, curPad;
119 Short_t time, signal;
120 Bool_t inFill = kFALSE;
d810d0de 121 AliEveTPCSectorData* secData = 0;
915dabe1 122
123 Int_t numEnt = (Int_t) tree->GetEntries();
124 for (Int_t ent=0; ent<numEnt; ent++) {
125 tree->GetEntry(ent);
d810d0de 126 AliEveTPCSectorData::GetParam().AdjustSectorRow(digit.GetID(), sector, row);
a97abca8 127 if (sector >= 36) {
915dabe1 128 sector -= 36;
d810d0de 129 row += AliEveTPCSectorData::GetInnSeg().GetNRows();
915dabe1 130 }
131 secData = GetSectorData(sector, spawnSectors);
a97abca8 132 if (secData == 0)
915dabe1 133 continue;
134
a97abca8 135 if (digit.First() == kFALSE)
915dabe1 136 continue;
137 curPad = -1;
138 do {
139 pad = digit.CurrentColumn();
140 time = digit.CurrentRow();
141 signal = digit.CurrentDigit();
142
a97abca8 143 if (pad != curPad) {
144 if (inFill)
d6433e5d 145 secData->EndPad(fAutoPedestal, fLoadThreshold);
915dabe1 146 secData->BeginPad(row, pad, kFALSE);
147 curPad = pad;
148 inFill = kTRUE;
149 }
a97abca8 150 if (fAutoPedestal) {
8bb2a8e9 151 secData->RegisterData(time, signal);
152 } else {
153 signal -= fLoadPedestal;
a97abca8 154 if (signal >= fLoadThreshold)
8bb2a8e9 155 secData->RegisterData(time, signal);
156 }
915dabe1 157
158 } while (digit.Next());
a97abca8 159 if (inFill) {
d6433e5d 160 secData->EndPad(fAutoPedestal, fLoadThreshold);
915dabe1 161 inFill = kFALSE;
162 }
163 }
164}
165
d810d0de 166void AliEveTPCData::LoadRaw(AliTPCRawStream& input, Bool_t spawnSectors, Bool_t warn)
915dabe1 167{
168 // Load data from AliTPCRawStream.
169 // If spawnSectors is false only sectors that have been created previously
170 // via CreateSector() are loaded.
171 // If spawnSectors is true sectors are created if data for them is encountered.
172
d810d0de 173 static const TEveException eH("AliEveTPCData::LoadRaw ");
915dabe1 174
d6433e5d 175 Int_t sector = -1, row = -1, pad = -1, rowOffset = 0;
092578a7 176 Short_t time, signal;
177 Bool_t inFill = kFALSE;
178 Short_t lastTime = 9999;
179 Bool_t lastTimeWarn = kFALSE;
d810d0de 180 AliEveTPCSectorData* secData = 0;
915dabe1 181
75a20dc1 182 Short_t threshold = fLoadThreshold;
183
915dabe1 184 while (input.Next()) {
185 if (input.IsNewSector()) {
a97abca8 186 if (inFill) {
75a20dc1 187 secData->EndPad(fAutoPedestal, threshold);
915dabe1 188 inFill = kFALSE;
189 }
190 sector = input.GetSector();
a97abca8 191 if (sector >= 36) {
915dabe1 192 sector -= 36;
d810d0de 193 rowOffset = AliEveTPCSectorData::GetInnSeg().GetNRows();
915dabe1 194 } else {
195 rowOffset = 0;
196 }
197 secData = GetSectorData(sector, spawnSectors);
198 }
199 if (secData == 0)
200 continue;
201
202 if (input.IsNewPad()) {
a97abca8 203 if (inFill) {
75a20dc1 204 secData->EndPad(fAutoPedestal, threshold);
915dabe1 205 inFill = kFALSE;
206 }
207 row = input.GetRow() + rowOffset;
208 pad = input.GetPad();
209
a97abca8 210 if (pad >= AliEveTPCSectorData::GetNPadsInRow(row)) {
211 if (warn) {
915dabe1 212 Warning(eH.Data(), "pad out of range (row=%d, pad=%d, maxpad=%d).",
d810d0de 213 row, pad, AliEveTPCSectorData::GetNPadsInRow(row));
915dabe1 214 }
215 continue;
216 }
217
d810d0de 218 AliEveTPCSectorData::PadRowHack* prh = secData->GetPadRowHack(row, pad);
a97abca8 219 if (prh != 0) {
75a20dc1 220 threshold = prh->fThrExt + Short_t(prh->fThrFac*fLoadThreshold);
221 } else {
222 threshold = fLoadThreshold;
223 }
224
915dabe1 225 secData->BeginPad(row, pad, kTRUE);
092578a7 226 inFill = kTRUE;
227 lastTime = 1024; lastTimeWarn = kFALSE;
915dabe1 228 }
229
d6433e5d 230 time = input.GetTime();
231 signal = input.GetSignal();
a97abca8 232 if (time >= lastTime) {
233 if (lastTimeWarn == kFALSE) {
234 if (warn)
5987168b 235 Warning(eH.Data(), "time out of order (row=%d, pad=%d, time=%d, lastTime=%d).",
236 row, pad, time, lastTime);
092578a7 237 lastTimeWarn = kTRUE;
238 }
239 continue;
240 }
241 lastTime = time;
a97abca8 242 if (fAutoPedestal) {
d6433e5d 243 secData->RegisterData(time, signal);
244 } else {
8bb2a8e9 245 signal -= fLoadPedestal;
a97abca8 246 if (signal > threshold)
8bb2a8e9 247 secData->RegisterData(time, signal);
d6433e5d 248 }
915dabe1 249 }
250
a97abca8 251 if (inFill) {
75a20dc1 252 secData->EndPad(fAutoPedestal, threshold);
915dabe1 253 inFill = kFALSE;
254 }
255}