2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
4 /**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
10 #include "AliEveTPCData.h"
12 #include <Alieve/AliEveTPCSectorData.h>
14 #include <AliSimDigits.h>
15 #include <AliTPCParam.h>
16 #include <AliTPCRawStream.h>
20 //______________________________________________________________________
23 // A central manager for TPC data of an event. Can read digits (from
24 // a tree: LoadDigits()) and raw-data (via AliRawReader: LoadRaw()).
26 // The sector data is stored in 36 AliEveTPCSectorData objects.
27 // Sectors 0 - 17: +z side, 18 - 35: -z side.
28 // No separation of inner/outer segments, use row numbers for addressing.
30 // Threshold application and pedestal subtraction can be performed at
31 // load time: use SetLoadThreshold(thresh) and SetLoadPedestal(ped).
33 // For raw-data (loaded using LoadRaw) pedestals can be calculated
34 // automatically per pad. Use SetAutoPedestal(kTRUE) to activate it.
35 // You might still want to set load threshold (default iz zero).
38 ClassImp(AliEveTPCData)
40 AliEveTPCData::AliEveTPCData() :
41 fSectors(36), fSectorBlockSize(65536),
42 fLoadThreshold(0), fLoadPedestal(0), fAutoPedestal(kFALSE)
44 AliEveTPCSectorData::InitStatics();
47 AliEveTPCData::~AliEveTPCData()
52 /**************************************************************************/
54 void AliEveTPCData::CreateSector(Int_t sector)
56 if(fSectors[sector] == 0)
57 fSectors[sector] = new AliEveTPCSectorData(sector, fSectorBlockSize);
60 void AliEveTPCData::CreateAllSectors()
62 for(Int_t s=0; s<36; ++s)
66 void AliEveTPCData::DropAllSectors()
68 for(Int_t s=0; s<36; ++s) {
70 fSectors[s]->DropData();
74 void AliEveTPCData::DeleteAllSectors()
76 for(Int_t s=0; s<36; ++s) {
82 /**************************************************************************/
84 AliEveTPCSectorData* AliEveTPCData::GetSectorData(Int_t sector, Bool_t spawnSectors)
86 if(sector < 0 || sector > 35) return 0;
87 if(fSectors[sector] == 0 && spawnSectors)
89 return fSectors[sector];
92 /**************************************************************************/
94 void AliEveTPCData::LoadDigits(TTree* tree, Bool_t spawnSectors)
96 // Load data from TTree of AliSimDigits.
97 // If spawnSectors is false only sectors that have been created previously
98 // via CreateSector() are loaded.
99 // If spawnSectors is true sectors are created if data for them is encountered.
101 AliSimDigits digit, *digitPtr = &digit;
102 tree->GetBranch("Segment")->SetAddress(&digitPtr);
104 Int_t sector, row, pad, curPad;
105 Short_t time, signal;
106 Bool_t inFill = kFALSE;
107 AliEveTPCSectorData* secData = 0;
109 Int_t numEnt = (Int_t) tree->GetEntries();
110 for (Int_t ent=0; ent<numEnt; ent++) {
112 AliEveTPCSectorData::GetParam().AdjustSectorRow(digit.GetID(), sector, row);
115 row += AliEveTPCSectorData::GetInnSeg().GetNRows();
117 secData = GetSectorData(sector, spawnSectors);
121 if(digit.First() == kFALSE)
125 pad = digit.CurrentColumn();
126 time = digit.CurrentRow();
127 signal = digit.CurrentDigit();
131 secData->EndPad(fAutoPedestal, fLoadThreshold);
132 secData->BeginPad(row, pad, kFALSE);
137 secData->RegisterData(time, signal);
139 signal -= fLoadPedestal;
140 if(signal >= fLoadThreshold)
141 secData->RegisterData(time, signal);
144 } while (digit.Next());
146 secData->EndPad(fAutoPedestal, fLoadThreshold);
152 void AliEveTPCData::LoadRaw(AliTPCRawStream& input, Bool_t spawnSectors, Bool_t warn)
154 // Load data from AliTPCRawStream.
155 // If spawnSectors is false only sectors that have been created previously
156 // via CreateSector() are loaded.
157 // If spawnSectors is true sectors are created if data for them is encountered.
159 static const TEveException eH("AliEveTPCData::LoadRaw ");
161 Int_t sector = -1, row = -1, pad = -1, rowOffset = 0;
162 Short_t time, signal;
163 Bool_t inFill = kFALSE;
164 Short_t lastTime = 9999;
165 Bool_t lastTimeWarn = kFALSE;
166 AliEveTPCSectorData* secData = 0;
168 Short_t threshold = fLoadThreshold;
170 while (input.Next()) {
171 if (input.IsNewSector()) {
173 secData->EndPad(fAutoPedestal, threshold);
176 sector = input.GetSector();
179 rowOffset = AliEveTPCSectorData::GetInnSeg().GetNRows();
183 secData = GetSectorData(sector, spawnSectors);
188 if (input.IsNewPad()) {
190 secData->EndPad(fAutoPedestal, threshold);
193 row = input.GetRow() + rowOffset;
194 pad = input.GetPad();
196 if(pad >= AliEveTPCSectorData::GetNPadsInRow(row)) {
198 Warning(eH.Data(), "pad out of range (row=%d, pad=%d, maxpad=%d).",
199 row, pad, AliEveTPCSectorData::GetNPadsInRow(row));
204 AliEveTPCSectorData::PadRowHack* prh = secData->GetPadRowHack(row, pad);
206 threshold = prh->fThrExt + Short_t(prh->fThrFac*fLoadThreshold);
208 threshold = fLoadThreshold;
211 secData->BeginPad(row, pad, kTRUE);
213 lastTime = 1024; lastTimeWarn = kFALSE;
216 time = input.GetTime();
217 signal = input.GetSignal();
218 if(time >= lastTime) {
219 if(lastTimeWarn == kFALSE) {
221 Warning(eH.Data(), "time out of order (row=%d, pad=%d, time=%d, lastTime=%d).",
222 row, pad, time, lastTime);
223 lastTimeWarn = kTRUE;
229 secData->RegisterData(time, signal);
231 signal -= fLoadPedestal;
232 if(signal > threshold)
233 secData->RegisterData(time, signal);
238 secData->EndPad(fAutoPedestal, threshold);