]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TRD/AliTRDmcmSim.h
Plotting macro updates
[u/mrichter/AliRoot.git] / TRD / AliTRDmcmSim.h
... / ...
CommitLineData
1#ifndef ALITRDMCMSIM_H
2#define ALITRDMCMSIM_H
3/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
5
6/* $Id$ */
7
8///////////////////////////////////////////////////////
9// //
10// Multi Chip Module Simulation Class //
11// //
12///////////////////////////////////////////////////////
13
14#include <iostream>
15
16class TObject;
17class TClonesArray;
18class TH2F;
19
20class AliRunLoader;
21class AliTRDfeeParam;
22class AliTRDtrapConfig;
23class AliTRDarrayADC;
24class AliTRDarrayDictionary;
25class AliTRDdigitsManager;
26
27class AliTRDmcmSim : public TObject {
28 public:
29 AliTRDmcmSim();
30 virtual ~AliTRDmcmSim();
31
32 void Init(Int_t det, Int_t rob, Int_t mcm, Bool_t newEvent = kFALSE);
33 // Initialize MCM by the position parameters
34
35 void Reset();
36 // clears filter registers and internal data
37
38 Bool_t LoadMCM(AliRunLoader* const runloader, Int_t det, Int_t rob, Int_t mcm);
39
40 void NoiseTest(Int_t nsamples, Int_t mean, Int_t sigma, Int_t inputGain = 1, Int_t inputTail = 2);
41
42 Int_t GetDataRaw(Int_t iadc, Int_t timebin) const { return (fADCR[iadc][timebin] >> 2); }
43 // Get unfiltered ADC data
44 Int_t GetDataFiltered(Int_t iadc, Int_t timebin) const { return (fADCF[iadc][timebin] >> 2); }
45 // Get filtered ADC data
46
47 void SetData(Int_t iadc, const Int_t* const adc); // Set ADC data with array
48 void SetData(Int_t iadc, Int_t it, Int_t adc); // Set ADC data
49 void SetData(AliTRDarrayADC * const adcArray,
50 AliTRDdigitsManager * const digitsManager = 0x0); // Set ADC data from adcArray
51 void SetDataByPad(const AliTRDarrayADC *const adcArray,
52 AliTRDdigitsManager * const digitsManager = 0x0); // Set ADC data from adcArray
53 void SetDataPedestal(Int_t iadc); // Fill ADC data with pedestal values
54
55 static Bool_t GetApplyCut() { return fgApplyCut; }
56 static void SetApplyCut(Bool_t applyCut) { fgApplyCut = applyCut; }
57
58 static Int_t GetAddBaseline() { return fgAddBaseline; }
59 static void SetAddBaseline(Int_t baseline) { fgAddBaseline = baseline; }
60 // Additional baseline which is added for the processing
61 // in the TRAP and removed when writing back the data.
62 // This is needed to run with TRAP parameters set for a
63 // different baseline but it will not change the baseline
64 // of the output.
65
66 static void SetStoreClusters(Bool_t storeClusters) { fgStoreClusters = storeClusters; }
67 static Bool_t GetStoreClusters() { return fgStoreClusters; }
68
69 Int_t GetDetector() const { return fDetector; }; // Returns Chamber ID (0-539)
70 Int_t GetRobPos() const { return fRobPos; }; // Returns ROB position (0-7)
71 Int_t GetMcmPos() const { return fMcmPos; }; // Returns MCM position (0-17) (16,17 are mergers)
72 Int_t GetRow() const { return fRow; }; // Returns Row number on chamber where the MCM is sitting
73 Int_t GetCol( Int_t iadc ); // Get corresponding column (0-143) from for ADC channel iadc = [0:20]
74 // for the ADC/Col mapping, see: http://wiki.kip.uni-heidelberg.de/ti/TRD/index.php/Image:ROB_MCM_numbering.pdf
75
76 void WriteData(AliTRDarrayADC *digits);
77 Bool_t StoreTracklets(); // Stores tracklets via runloader
78 TString GetTrklBranchName() const { return fTrklBranchName; }
79 void SetTrklBranchName(TString name) { fTrklBranchName = name; }
80
81 Int_t ProduceRawStream( UInt_t *buf, Int_t bufsize, UInt_t iEv = 0 ) const; // Produce raw data stream - Real data format
82 Int_t ProduceTrackletStream( UInt_t *buf, Int_t bufsize ); // produce the tracklet stream for this MCM
83
84 // different stages of processing in the TRAP
85 void Filter(); // Apply digital filters for existing data (according to configuration)
86 void ZSMapping(); // Do ZS mapping for existing data
87 void Tracklet(); // Run tracklet preprocessor and perform tracklet fit
88
89 // apply individual filters to all channels and timebins
90 void FilterPedestal(); // Apply pedestal filter
91 void FilterGain(); // Apply gain filter
92 void FilterTail(); // Apply tail filter
93
94 // filter initialization (resets internal registers)
95 void FilterPedestalInit(Int_t baseline = 10);
96 void FilterGainInit();
97 void FilterTailInit(Int_t baseline = -1);
98
99 // feed single sample to individual filter
100 // this changes the internal registers
101 // all filters operate on (10+2)-bit values!
102 UShort_t FilterPedestalNextSample(Int_t adc, Int_t timebin, UShort_t value);
103 UShort_t FilterGainNextSample(Int_t adc, UShort_t value);
104 UShort_t FilterTailNextSample(Int_t adc, UShort_t value);
105
106 // tracklet calculation
107 void AddHitToFitreg(Int_t adc, UShort_t timebin, UShort_t qtot, Short_t ypos, Int_t label[]);
108 void CalcFitreg();
109 void TrackletSelection();
110 void FitTracklet();
111
112 Int_t GetNHits() const { return fNHits; }
113 Bool_t GetHit(Int_t index, Int_t &channel, Int_t &timebin, Int_t &qtot, Int_t &ypos, Float_t &y, Int_t &label) const;
114 TClonesArray* GetTrackletArray() const { return fTrackletArray; }
115
116 // data display
117 void Print(Option_t* const option="") const; // print stored data to stdout
118 void Draw(Option_t* const option =""); // draw data (ADC data, hits and tracklets)
119
120 friend std::ostream& operator<<(std::ostream &os, const AliTRDmcmSim &mcm); // data output using ostream (e.g. cout << mcm;)
121 static ostream& Cfdat(ostream &os); // manipulator to activate cfdat output
122 static ostream& Raw (ostream &os); // manipulator to activate raw output
123 static ostream& Text (ostream &os); // manipulator to activate text output
124
125 // PID
126 Int_t GetPID(Int_t q0, Int_t q1);
127 void PrintPidLutHuman();
128
129 // I/O
130 void PrintFitRegXml(ostream& os) const;
131 void PrintTrackletsXml(ostream& os) const;
132 void PrintAdcDatHuman(ostream& os) const;
133 void PrintAdcDatXml(ostream& os) const;
134 void PrintAdcDatDatx(ostream& os, Bool_t broadcast=kFALSE, Int_t timeBinOffset = -1) const;
135
136 static Bool_t ReadPackedConfig(AliTRDtrapConfig *cfg, Int_t hc, UInt_t *data, Int_t size);
137
138 // DMEM addresses
139 static const Int_t fgkDmemAddrLUTcor0 = 0xC02A;
140 static const Int_t fgkDmemAddrLUTcor1 = 0xC028;
141 static const Int_t fgkDmemAddrLUTnbins = 0xC029;
142
143 static const Int_t fgkDmemAddrLUTStart = 0xC100; // LUT start address
144 static const Int_t fgkDmemAddrLUTEnd = 0xC3FF; // maximum possible end address for the LUT table
145 static const Int_t fgkDmemAddrLUTLength = 0xC02B; // address where real size of the LUT table is stored
146
147 static const Int_t fgkDmemAddrTrackletStart = 0xC0E0; // Storage area for tracklets, start address
148 static const Int_t fgkDmemAddrTrackletEnd = 0xC0E3; // Storage area for tracklets, end address
149
150 static const Int_t fgkDmemAddrDeflCorr = 0xc022; // DMEM address of deflection correction
151 static const Int_t fgkDmemAddrNdrift = 0xc025; // DMEM address of Ndrift
152 static const Int_t fgkDmemAddrDeflCutStart = 0xc030; // DMEM start address of deflection cut
153 static const Int_t fgkDmemAddrDeflCutEnd = 0xc055; // DMEM end address of deflection cut
154
155 protected:
156 Bool_t CheckInitialized() const; // Check whether the class is initialized
157
158 void SetNTimebins(Int_t ntimebins); // allocate data arrays corr. to the no. of timebins
159
160 static const Int_t fgkFormatIndex; // index for format settings in stream
161
162 static const Int_t fgkMaxTracklets = 4; // maximum number of tracklet-words submitted per MCM (one per CPU)
163 static const Int_t fgkAddDigits = 2; // additional digits used for internal representation of ADC data
164 // all internal data as after data control block (i.e. 12 bit), s. TRAP manual
165 static const Int_t fgkNCPU = 4; // Number of CPUs in the TRAP
166 static const Int_t fgkNHitsMC = 100; // maximum number of hits for which MC information is kept
167
168 static const UShort_t fgkFPshifts[4]; // shifts for pedestal filter
169
170 Bool_t fInitialized; // memory is allocated if initialized
171 Int_t fDetector; // Chamber ID
172 Int_t fRobPos; // ROB Position on chamber
173 Int_t fMcmPos; // MCM Position on chamber
174 Int_t fRow; // Pad row number (0-11 or 0-15) of the MCM on chamber
175 Int_t fNTimeBin; // Number of timebins currently allocated
176 Int_t **fADCR; // Array with MCM ADC values (Raw, 12 bit)
177 Int_t **fADCF; // Array with MCM ADC values (Filtered, 12 bit)
178 UInt_t *fMCMT; // tracklet word for one mcm/trap-chip
179 TClonesArray *fTrackletArray; // Array of AliTRDtrackletMCM which contains MC information in addition to the tracklet word
180 Int_t *fZSMap; // Zero suppression map (1 dimensional projection)
181
182 Int_t fFitPtr[fgkNCPU]; // pointer to the tracklet to be calculated by CPU i
183
184 TString fTrklBranchName; // name of the tracklet branch to right to
185
186 // Parameter classes
187 AliTRDfeeParam *fFeeParam; // FEE parameters
188 AliTRDtrapConfig *fTrapConfig; // TRAP config
189
190 AliTRDdigitsManager *fDigitsManager; // pointer to digits manager used for MC label calculation
191 AliTRDarrayDictionary* fDict[3]; // pointers to label dictionaries
192
193
194 // internal filter registers
195 UInt_t* fPedAcc; // Accumulator for pedestal filter
196 UInt_t* fGainCounterA; // Counter for values above FGTA in the gain filter
197 UInt_t* fGainCounterB; // Counter for values above FGTB in the gain filter
198 UShort_t* fTailAmplLong; // Amplitude of the long component in the tail filter
199 UShort_t* fTailAmplShort; // Amplitude of the short component in the tail filter
200
201 // hit detection
202 // individual hits can be stored as MC info
203 struct Hit_t { // Array of detected hits (only available in MC)
204 Hit_t() : fChannel(0), fTimebin(0), fQtot(0), fYpos(0) { fLabel[0] = 0; fLabel[1] = 0; fLabel[2] = 0; }
205 Int_t fChannel; // ADC channel of the hit
206 Int_t fTimebin; // timebin of the hit
207 Int_t fQtot; // total charge of the hit
208 Int_t fYpos; // calculated y-position
209 Int_t fLabel[3]; // up to 3 labels (only in MC)
210 } fHits[fgkNHitsMC];
211 Int_t fNHits; // Number of detected hits
212
213 // tracklet calculation
214 struct FitReg_t { // pointer to the 18 fit registers
215 Int_t fNhits; // number of hits
216 UInt_t fQ0; // charge accumulated in first window
217 UInt_t fQ1; // charge accumulated in second window
218 UInt_t fSumX; // sum x
219 Int_t fSumY; // sum y
220 UInt_t fSumX2; // sum x**2
221 UInt_t fSumY2; // sum y**2
222 Int_t fSumXY; // sum x*y
223 } *fFitReg;
224
225 // Sort functions as in TRAP
226 void Sort2(UShort_t idx1i, UShort_t idx2i, UShort_t val1i, UShort_t val2i,
227 UShort_t * const idx1o, UShort_t * const idx2o, UShort_t * const val1o, UShort_t * const val2o) const;
228 void Sort3(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i,
229 UShort_t val1i, UShort_t val2i, UShort_t val3i,
230 UShort_t * const idx1o, UShort_t * const idx2o, UShort_t * const idx3o,
231 UShort_t * const val1o, UShort_t * const val2o, UShort_t * const val3o);
232 void Sort6To4(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, UShort_t idx4i, UShort_t idx5i, UShort_t idx6i,
233 UShort_t val1i, UShort_t val2i, UShort_t val3i, UShort_t val4i, UShort_t val5i, UShort_t val6i,
234 UShort_t * const idx1o, UShort_t * const idx2o, UShort_t * const idx3o, UShort_t * const idx4o,
235 UShort_t * const val1o, UShort_t * const val2o, UShort_t * const val3o, UShort_t * const val4o);
236 void Sort6To2Worst(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, UShort_t idx4i, UShort_t idx5i, UShort_t idx6i,
237 UShort_t val1i, UShort_t val2i, UShort_t val3i, UShort_t val4i, UShort_t val5i, UShort_t val6i,
238 UShort_t * const idx5o, UShort_t * const idx6o);
239
240 UInt_t AddUintClipping(UInt_t a, UInt_t b, UInt_t nbits) const;
241 // Add a and b (unsigned) with clipping to the maximum value representable by nbits
242
243 private:
244 AliTRDmcmSim(const AliTRDmcmSim &m); // not implemented
245 AliTRDmcmSim &operator=(const AliTRDmcmSim &m); // not implemented
246
247 static Bool_t fgApplyCut; // apply cut on deflection length
248
249 static Int_t fgAddBaseline; // add baseline to the ADC values
250
251 static Bool_t fgStoreClusters; // whether to store all clusters in the tracklets
252
253 ClassDef(AliTRDmcmSim,7)
254};
255
256std::ostream& operator<<(std::ostream& os, const AliTRDmcmSim& mcm);
257
258#endif