]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/Alieve/TPCSectorData.h
Fix handling of AliESDfriends.root.
[u/mrichter/AliRoot.git] / EVE / Alieve / TPCSectorData.h
1 // $Header$
2
3 #ifndef ALIEVE_TPCSectorData_H
4 #define ALIEVE_TPCSectorData_H
5
6 #include <Reve/Reve.h>
7
8 #include <TObject.h>
9
10 #include <vector>
11
12 class AliTPCParam;
13
14 namespace Alieve {
15
16 class TPCSectorData : public TObject
17 {
18   TPCSectorData(const TPCSectorData&);            // Not implemented
19   TPCSectorData& operator=(const TPCSectorData&); // Not implemented
20
21 public:
22
23   class PadData
24   {
25   protected:
26     Short_t* fData;
27     Short_t  fLength;
28
29   public:
30     PadData(Short_t* d=0, Short_t l=0) : fData(d), fLength(l) {}
31
32     PadData(const PadData& p) : fData(p.fData), fLength(p.fLength) {}
33     PadData& operator=(const PadData& p)
34     { fData = p.fData; fLength = p.fLength; return *this; }
35
36     Short_t* Data()   const { return fData; }
37     Short_t  Length() const { return fLength; }
38
39     void SetDataLength(Short_t* d, Short_t l) { fData = d; fLength = l; }
40
41     void Print(Option_t* opt="");
42   };
43
44   class PadIterator
45   {
46   protected:
47     Short_t *fBeg, *fEnd, *fPos;
48     Short_t  fTime, fSignal;
49     Short_t  fThreshold;
50     Short_t  fNChunk;
51
52   public:
53     PadIterator(const PadData& pd, Short_t thr=0) :
54       fBeg(pd.Data()), fEnd(pd.Data() + pd.Length()), fPos(pd.Data()),
55       fTime(-1), fSignal(-1), fThreshold(thr), fNChunk(0)
56     {}
57     PadIterator(const PadIterator& i) :
58       fBeg(i.fBeg), fEnd(i.fEnd), fPos(i.fPos),
59       fTime(i.fTime), fSignal(i.fSignal), fThreshold(i.fThreshold), fNChunk(i.fNChunk)
60     {}
61     virtual ~PadIterator() {}
62
63     PadIterator& operator=(const PadIterator& i) {
64       fBeg = i.fBeg; fEnd = i.fEnd; fPos = i.fPos;
65       fTime = i.fTime; fSignal = i.fSignal; fThreshold = i.fThreshold; fNChunk = i.fNChunk;
66       return *this;
67     }
68
69     Bool_t Next();
70     void   Reset();
71     void   Reset(const PadData& pd);
72
73     Short_t Time()   const { return fTime; }
74     Short_t Signal() const { return fSignal; }
75
76     Short_t Threshold()    const { return fThreshold; }
77     void SetThreshold(Short_t t) { fThreshold = t; }
78
79     void Test();
80   };
81
82   class RowIterator : public PadIterator
83   {
84   protected:
85     const PadData* fPadArray;
86     Short_t fNPads;
87     Short_t fPad;
88
89   public:
90     RowIterator(const PadData* first, Short_t npads, Short_t thr=0) :
91       PadIterator(*first, thr),
92       fPadArray(first), fNPads(npads),
93       fPad(-1)
94     {}
95     RowIterator(const RowIterator& i) :
96       PadIterator(i),
97       fPadArray(i.fPadArray), fNPads(i.fNPads), fPad(i.fPad)
98     {}
99
100     RowIterator& operator=(const RowIterator& i) {
101       fPadArray = i.fPadArray; fNPads = i.fNPads; fPad = i.fPad;
102       return *this;
103     }
104
105     Bool_t NextPad();
106     void   ResetRow();
107     void   ResetRow(const PadData* first, Short_t npads);
108     
109     Short_t Pad() const { return fPad; }
110
111     void Test();
112   };
113
114   class SegmentInfo : public TObject
115   {
116     friend class TPCSectorData;
117
118   private:
119     Float_t   fPadWidth;
120     Float_t   fPadHeight;
121     Float_t   fRLow;      // Radius at the bottom of first row
122     Int_t     fNRows;     // Number of rows in this segment
123     Int_t     fFirstRow;  // First row index within sector
124     Int_t     fLastRow;   // Last row index within sector
125     Int_t     fNMaxPads;  // Maximum number of pads in a row
126     Int_t     fNYSteps;   // Number of steps in pad-count
127     Float_t   fYStep[64]; // Y coords where pad-count changes
128
129   public:
130     SegmentInfo();
131
132     Float_t GetPadWidth()  const { return fPadWidth; }
133     Float_t GetPadHeight() const { return fPadHeight; }
134     Float_t GetRLow()      const { return fRLow; }
135     Int_t   GetNRows()     const { return fNRows; }
136     Int_t   GetFirstRow()  const { return fFirstRow; }
137     Int_t   GetLastRow()   const { return fLastRow; }
138     Int_t   GetNMaxPads()  const { return fNMaxPads; }
139     Int_t   GetNYSteps()   const { return fNYSteps; }
140     Float_t GetYStep(Int_t step) const { return fYStep[step]; }
141
142     ClassDef(SegmentInfo, 0);
143   };
144
145 private:
146   static AliTPCParam *fgParam;
147   static Float_t      fgZLength;
148   static Int_t        fgNAllRows;
149   static Int_t        fgNAllPads;
150   static Int_t       *fgRowBegs;
151
152   static SegmentInfo  fgInnSeg;
153   static SegmentInfo  fgOut1Seg;
154   static SegmentInfo  fgOut2Seg;
155
156   static SegmentInfo* fgSegInfoPtrs[3];
157
158 protected:
159   Int_t                 fSectorID;
160   Int_t                 fNPadsFilled;
161   std::vector<PadData>  fPads;
162
163   // Blocks of pad-data.
164   const Int_t           fBlockSize;
165   Int_t                 fBlockPos;
166   std::vector<Short_t*> fBlocks;
167
168   void NewBlock();
169
170   // Intermediate buffer/vars for pad-data.
171   Short_t fPadBuffer[2048];
172   Int_t   fCurrentRow, fCurrentPad, fCurrentPos, fCurrentStep;
173
174   Int_t PadIndex(Int_t row, Int_t pad) { return fgRowBegs[row] + pad; }
175
176 public:
177   TPCSectorData(Int_t sector, Int_t bsize=65536);
178   virtual ~TPCSectorData();
179
180   void DropData();
181
182   virtual void Print(Option_t* opt="") const;
183
184   void BeginPad(Int_t row, Int_t pad, Bool_t reverseTime=kFALSE);
185   void RegisterData(Short_t time, Short_t signal);
186   void EndPad(Bool_t autoPedestal=kFALSE, Short_t threshold=0);
187
188   const PadData& GetPadData(Int_t padAddr);
189   const PadData& GetPadData(Int_t row, Int_t pad);
190
191   PadIterator MakePadIterator(Int_t padAddr, Short_t thr=0);
192   PadIterator MakePadIterator(Int_t row, Int_t pad, Short_t thr=0);
193
194   RowIterator MakeRowIterator(Int_t row, Short_t thr=0);
195
196   // --- Static functions
197
198   static const AliTPCParam& GetParam() { return *fgParam; }
199   static Float_t GetZLength()  { return fgZLength;  }
200   static Int_t   GetNAllRows() { return fgNAllRows; }
201   static Int_t   GetNAllPads() { return fgNAllPads; }
202
203   static Int_t GetNPadsInRow(Int_t row);
204
205   static const SegmentInfo& GetInnSeg()  { return fgInnSeg;  }
206   static const SegmentInfo& GetOut1Seg() { return fgOut1Seg; }
207   static const SegmentInfo& GetOut2Seg() { return fgOut2Seg; }
208
209   static const SegmentInfo& GetSeg(Int_t seg);
210   
211   static void InitStatics();
212
213
214   //----------------------------------------------------------------
215   // Hack for noisy pad-row removal
216   //----------------------------------------------------------------
217
218   class PadRowHack
219   {
220   public:
221     Int_t   fRow, fPad;
222     Int_t   fThrExt;
223     Float_t fThrFac; // Actual threshold = fThrExt + fThrFac*thr
224
225     PadRowHack(Int_t r, Int_t p, Int_t te=0, Float_t tf=1) :
226       fRow(r), fPad(p), fThrExt(te), fThrFac(tf) {}
227     bool operator<(const PadRowHack& a) const
228     { return (fRow == a.fRow) ? fPad < a.fPad : fRow < a.fRow; }
229   };
230
231   PadRowHack* GetPadRowHack(Int_t r, Int_t p);
232   void AddPadRowHack(Int_t r, Int_t p, Int_t te=0, Float_t tf=1);
233   void RemovePadRowHack(Int_t r, Int_t p);
234   void DeletePadRowHack();
235
236 protected:
237   void* fPadRowHackSet;
238   
239
240   ClassDef(TPCSectorData, 0);
241 }; // endclass TPCSectorData
242
243
244 inline void TPCSectorData::RegisterData(Short_t time, Short_t signal)
245 {
246   fPadBuffer[fCurrentPos]   = time;
247   fPadBuffer[fCurrentPos+1] = signal;
248   fCurrentPos += fCurrentStep;
249 }
250
251 }
252
253 #endif