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