5 #include <Alieve/TPCSectorData.h>
7 #include <AliSimDigits.h>
8 #include <AliTPCParam.h>
9 #include <AliTPCRawStream.h>
13 using namespace Alieve;
15 //______________________________________________________________________
18 // A central manager for TPC data of an event. Can read digits (from
19 // a tree: LoadDigits()) and raw-data (via AliRawReader: LoadRaw()).
21 // The sector data is stored in 36 TPCSectorData objects.
22 // Sectors 0 - 17: +z side, 18 - 35: -z side.
23 // No separation of inner/outer segments, use row numbers for addressing.
25 // Threshold application and pedestal subtraction can be performed at
26 // load time: use SetLoadThreshold(thresh) and SetLoadPedestal(ped).
28 // For raw-data (loaded using LoadRaw) pedestals can be calculated
29 // automatically per pad. Use SetAutoPedestal(kTRUE) to activate it.
30 // You might still want to set load threshold (default iz zero).
36 fSectors(36), fSectorBlockSize(65536),
37 fLoadThreshold(0), fLoadPedestal(0), fAutoPedestal(kFALSE)
39 TPCSectorData::InitStatics();
47 /**************************************************************************/
49 void TPCData::CreateSector(Int_t sector)
51 if(fSectors[sector] == 0)
52 fSectors[sector] = new TPCSectorData(sector, fSectorBlockSize);
55 void TPCData::CreateAllSectors()
57 for(Int_t s=0; s<36; ++s)
61 void TPCData::DropAllSectors()
63 for(Int_t s=0; s<36; ++s) {
65 fSectors[s]->DropData();
69 void TPCData::DeleteAllSectors()
71 for(Int_t s=0; s<36; ++s) {
77 /**************************************************************************/
79 TPCSectorData* TPCData::GetSectorData(Int_t sector, Bool_t spawnSectors)
81 if(sector < 0 || sector > 35) return 0;
82 if(fSectors[sector] == 0 && spawnSectors)
84 return fSectors[sector];
87 /**************************************************************************/
89 void TPCData::LoadDigits(TTree* tree, Bool_t spawnSectors)
91 // Load data from TTree of AliSimDigits.
92 // If spawnSectors is false only sectors that have been created previously
93 // via CreateSector() are loaded.
94 // If spawnSectors is true sectors are created if data for them is encountered.
96 AliSimDigits digit, *digitPtr = &digit;
97 tree->GetBranch("Segment")->SetAddress(&digitPtr);
99 Int_t sector, row, pad, curPad;
100 Short_t time, signal;
101 Bool_t inFill = kFALSE;
102 TPCSectorData* secData = 0;
104 Int_t numEnt = (Int_t) tree->GetEntries();
105 for (Int_t ent=0; ent<numEnt; ent++) {
107 Alieve::TPCSectorData::GetParam().AdjustSectorRow(digit.GetID(), sector, row);
110 row += TPCSectorData::GetInnSeg().GetNRows();
112 secData = GetSectorData(sector, spawnSectors);
116 if(digit.First() == kFALSE)
120 pad = digit.CurrentColumn();
121 time = digit.CurrentRow();
122 signal = digit.CurrentDigit();
126 secData->EndPad(fAutoPedestal, fLoadThreshold);
127 secData->BeginPad(row, pad, kFALSE);
132 secData->RegisterData(time, signal);
134 signal -= fLoadPedestal;
135 if(signal >= fLoadThreshold)
136 secData->RegisterData(time, signal);
139 } while (digit.Next());
141 secData->EndPad(fAutoPedestal, fLoadThreshold);
147 void TPCData::LoadRaw(AliTPCRawStream& input, Bool_t spawnSectors, Bool_t warn)
149 // Load data from AliTPCRawStream.
150 // If spawnSectors is false only sectors that have been created previously
151 // via CreateSector() are loaded.
152 // If spawnSectors is true sectors are created if data for them is encountered.
154 static const Exc_t eH("TPCData::LoadRaw ");
156 Int_t sector = -1, row = -1, pad = -1, rowOffset = 0;
157 Short_t time, signal;
158 Bool_t inFill = kFALSE;
159 Short_t lastTime = 9999;
160 Bool_t lastTimeWarn = kFALSE;
161 TPCSectorData* secData = 0;
163 Short_t threshold = fLoadThreshold;
165 while (input.Next()) {
166 if (input.IsNewSector()) {
168 secData->EndPad(fAutoPedestal, threshold);
171 sector = input.GetSector();
174 rowOffset = TPCSectorData::GetInnSeg().GetNRows();
178 secData = GetSectorData(sector, spawnSectors);
183 if (input.IsNewPad()) {
185 secData->EndPad(fAutoPedestal, threshold);
188 row = input.GetRow() + rowOffset;
189 pad = input.GetPad();
191 if(pad >= TPCSectorData::GetNPadsInRow(row)) {
193 Warning(eH.Data(), "pad out of range (row=%d, pad=%d, maxpad=%d).",
194 row, pad, TPCSectorData::GetNPadsInRow(row));
199 TPCSectorData::PadRowHack* prh = secData->GetPadRowHack(row, pad);
201 threshold = prh->fThrExt + Short_t(prh->fThrFac*fLoadThreshold);
203 threshold = fLoadThreshold;
206 secData->BeginPad(row, pad, kTRUE);
208 lastTime = 1024; lastTimeWarn = kFALSE;
211 time = input.GetTime();
212 signal = input.GetSignal();
213 if(time >= lastTime) {
214 if(lastTimeWarn == kFALSE) {
216 Warning(eH.Data(), "time out of order (row=%d, pad=%d, time=%d, lastTime=%d).",
217 row, pad, time, lastTime);
218 lastTimeWarn = kTRUE;
224 secData->RegisterData(time, signal);
226 signal -= fLoadPedestal;
227 if(signal > threshold)
228 secData->RegisterData(time, signal);
233 secData->EndPad(fAutoPedestal, threshold);