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