]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/TPCData.cxx
Put black-listed classes out of Alieve namespace.
[u/mrichter/AliRoot.git] / EVE / Alieve / TPCData.cxx
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 <TTree.h>
11 using namespace Alieve;
12
13 //______________________________________________________________________
14 // TPCData
15 //
16 // A central manager for TPC data of an event.  Can read digits (from
17 // a tree: LoadDigits()) and raw-data (via AliRawReader: LoadRaw()).
18 //
19 // The sector data is stored in 36 TPCSectorData objects.
20 // Sectors 0 - 17: +z side, 18 - 35: -z side.
21 // No separation of inner/outer segments, use row numbers for addressing.
22 //
23 // Threshold application and pedestal subtraction can be performed at
24 // load time: use SetLoadThreshold(thresh) and SetLoadPedestal(ped).
25 //
26 // For raw-data (loaded using LoadRaw) pedestals can be calculated
27 // automatically per pad. Use SetAutoPedestal(kTRUE) to activate it. 
28 // You might still want to set load threshold (default iz zero).
29 //
30
31 ClassImp(TPCData)
32
33 TPCData::TPCData() :
34   fSectors(36), fSectorBlockSize(65536),
35   fLoadThreshold(0), fLoadPedestal(0), fAutoPedestal(kFALSE)
36 {
37   TPCSectorData::InitStatics();
38 }
39
40 TPCData::~TPCData()
41 {
42   DeleteAllSectors();
43 }
44
45 /**************************************************************************/
46
47 void TPCData::CreateSector(Int_t sector)
48 {
49   if(fSectors[sector] == 0)
50     fSectors[sector] = new TPCSectorData(sector, fSectorBlockSize);
51 }
52
53 void TPCData::CreateAllSectors()
54 {
55   for(Int_t s=0; s<36; ++s)
56     CreateSector(s);
57 }
58
59 void TPCData::DropAllSectors()
60 {
61   for(Int_t s=0; s<36; ++s) {
62     if(fSectors[s] != 0)
63       fSectors[s]->DropData();
64   }
65 }
66
67 void TPCData::DeleteAllSectors()
68 {
69   for(Int_t s=0; s<36; ++s) {
70     delete fSectors[s];
71     fSectors[s] = 0;
72   }
73 }
74
75 /**************************************************************************/
76
77 TPCSectorData* TPCData::GetSectorData(Int_t sector, Bool_t spawnSectors)
78 {
79   if(sector < 0 || sector > 35) return 0;
80   if(fSectors[sector] == 0 && spawnSectors)
81     CreateSector(sector);
82   return fSectors[sector];
83 }
84
85 /**************************************************************************/
86
87 void TPCData::LoadDigits(TTree* tree, Bool_t spawnSectors)
88 {
89   // Load data from TTree of AliSimDigits.
90   // If spawnSectors is false only sectors that have been created previously
91   // via CreateSector() are loaded.
92   // If spawnSectors is true sectors are created if data for them is encountered.
93
94   AliSimDigits digit, *digitPtr = &digit;
95   tree->GetBranch("Segment")->SetAddress(&digitPtr);
96   
97   Int_t sector, row, pad, curPad;
98   Short_t time, signal;
99   Bool_t  inFill = kFALSE;
100   TPCSectorData* secData = 0;
101
102   Int_t numEnt = (Int_t) tree->GetEntries();
103   for (Int_t ent=0; ent<numEnt; ent++) {
104     tree->GetEntry(ent);
105     Alieve::TPCSectorData::GetParam().AdjustSectorRow(digit.GetID(), sector, row);
106     if(sector >= 36) {
107       sector -= 36;
108       row    += TPCSectorData::GetInnSeg().GetNRows();
109     }
110     secData = GetSectorData(sector, spawnSectors);
111     if(secData == 0)
112       continue;
113
114     if(digit.First() == kFALSE)
115       continue;
116     curPad = -1;
117     do {
118       pad    = digit.CurrentColumn();
119       time   = digit.CurrentRow();
120       signal = digit.CurrentDigit();
121
122       if(pad != curPad) {
123         if(inFill)
124           secData->EndPad(fAutoPedestal, fLoadThreshold);
125         secData->BeginPad(row, pad, kFALSE);
126         curPad = pad;
127         inFill = kTRUE;
128       }
129       if(fAutoPedestal) {
130         secData->RegisterData(time, signal);
131       } else {
132         signal -= fLoadPedestal;
133         if(signal >= fLoadThreshold)
134           secData->RegisterData(time, signal);
135       }
136
137     } while (digit.Next());
138     if(inFill) {
139       secData->EndPad(fAutoPedestal, fLoadThreshold);
140       inFill = kFALSE;
141     }
142   }
143 }
144
145 void TPCData::LoadRaw(AliTPCRawStream& input, Bool_t spawnSectors, Bool_t warn)
146 {
147   // Load data from AliTPCRawStream.
148   // If spawnSectors is false only sectors that have been created previously
149   // via CreateSector() are loaded.
150   // If spawnSectors is true sectors are created if data for them is encountered.
151
152   static const TEveException eH("TPCData::LoadRaw ");
153
154   Int_t   sector = -1, row = -1, pad = -1, rowOffset = 0;
155   Short_t time,  signal;
156   Bool_t  inFill   = kFALSE;
157   Short_t lastTime = 9999;
158   Bool_t  lastTimeWarn = kFALSE;
159   TPCSectorData* secData = 0;
160
161   Short_t threshold = fLoadThreshold;
162
163   while (input.Next()) {
164     if (input.IsNewSector()) {
165       if(inFill) {
166         secData->EndPad(fAutoPedestal, threshold);
167         inFill = kFALSE;
168       }
169       sector = input.GetSector();
170       if(sector >= 36) {
171         sector -= 36;
172         rowOffset = TPCSectorData::GetInnSeg().GetNRows();
173       } else {
174         rowOffset = 0;
175       }
176       secData = GetSectorData(sector, spawnSectors);
177     }
178     if (secData == 0)
179       continue;
180
181     if (input.IsNewPad()) {
182       if(inFill) {
183         secData->EndPad(fAutoPedestal, threshold);
184         inFill = kFALSE;
185       }
186       row = input.GetRow() + rowOffset;
187       pad = input.GetPad();
188
189       if(pad >= TPCSectorData::GetNPadsInRow(row)) {
190         if(warn) {
191           Warning(eH.Data(), "pad out of range (row=%d, pad=%d, maxpad=%d).",
192                   row, pad, TPCSectorData::GetNPadsInRow(row));
193         }
194         continue;
195       }
196
197       TPCSectorData::PadRowHack* prh = secData->GetPadRowHack(row, pad);
198       if(prh != 0) {
199         threshold = prh->fThrExt + Short_t(prh->fThrFac*fLoadThreshold);
200       } else {
201         threshold = fLoadThreshold;
202       }
203
204       secData->BeginPad(row, pad, kTRUE);
205       inFill   = kTRUE;
206       lastTime = 1024;  lastTimeWarn = kFALSE;
207     }
208
209     time   = input.GetTime();
210     signal = input.GetSignal();
211     if(time >= lastTime) {
212       if(lastTimeWarn == kFALSE) {
213         if(warn)
214           Warning(eH.Data(), "time out of order (row=%d, pad=%d, time=%d, lastTime=%d).",
215                   row, pad, time, lastTime);
216         lastTimeWarn = kTRUE;
217       }
218       continue;
219     }
220     lastTime = time;
221     if(fAutoPedestal) {
222       secData->RegisterData(time, signal);
223     } else {
224       signal -= fLoadPedestal;
225       if(signal > threshold)
226         secData->RegisterData(time, signal);
227     }
228   }
229
230   if(inFill) {
231     secData->EndPad(fAutoPedestal, threshold);
232     inFill = kFALSE;
233   }
234 }