]>
Commit | Line | Data |
---|---|---|
dfd03fc3 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
5eba8ada | 16 | /* $Id$ */ |
17 | ||
dfd03fc3 | 18 | /////////////////////////////////////////////////////////////////////////////// |
19 | // // | |
20 | // TRD MCM (Multi Chip Module) simulator // | |
ce4786b9 | 21 | // which simulates the TRAP processing after the AD-conversion. // |
22 | // The relevant parameters (i.e. configuration settings of the TRAP) // | |
23 | // are taken from AliTRDtrapConfig. // | |
dfd03fc3 | 24 | // // |
25 | /////////////////////////////////////////////////////////////////////////////// | |
26 | ||
ce4786b9 | 27 | #include <iostream> |
28 | #include <iomanip> | |
ecf39416 | 29 | |
ce4786b9 | 30 | #include "TCanvas.h" |
31 | #include "TH1F.h" | |
32 | #include "TH2F.h" | |
33 | #include "TGraph.h" | |
34 | #include "TLine.h" | |
35 | #include "TRandom.h" | |
36 | #include "TClonesArray.h" | |
ce51199c | 37 | #include "TMath.h" |
0c349049 | 38 | |
dfd03fc3 | 39 | #include "AliLog.h" |
b0a41e80 | 40 | #include "AliRunLoader.h" |
41 | #include "AliLoader.h" | |
0c349049 | 42 | |
dfd03fc3 | 43 | #include "AliTRDfeeParam.h" |
b0a41e80 | 44 | #include "AliTRDtrapConfig.h" |
4cc89512 | 45 | #include "AliTRDdigitsManager.h" |
b65e5048 | 46 | #include "AliTRDarrayADC.h" |
40bd6ee4 | 47 | #include "AliTRDarrayDictionary.h" |
52c19022 | 48 | #include "AliTRDtrackletMCM.h" |
b0a41e80 | 49 | #include "AliTRDmcmSim.h" |
1d93b218 | 50 | |
dfd03fc3 | 51 | ClassImp(AliTRDmcmSim) |
52 | ||
40bd6ee4 | 53 | Bool_t AliTRDmcmSim::fgApplyCut = kTRUE; |
ce4786b9 | 54 | Int_t AliTRDmcmSim::fgAddBaseline = 0; |
55 | ||
56 | const Int_t AliTRDmcmSim::fgkFormatIndex = std::ios_base::xalloc(); | |
57 | ||
58 | const Int_t AliTRDmcmSim::fgkNADC = AliTRDfeeParam::GetNadcMcm(); | |
59 | const UShort_t AliTRDmcmSim::fgkFPshifts[4] = {11, 14, 17, 21}; | |
60 | ||
61 | ||
62 | AliTRDmcmSim::AliTRDmcmSim() : | |
63 | TObject(), | |
64 | fInitialized(kFALSE), | |
65 | fDetector(-1), | |
66 | fRobPos(-1), | |
67 | fMcmPos(-1), | |
68 | fRow (-1), | |
69 | fNTimeBin(-1), | |
70 | fADCR(NULL), | |
71 | fADCF(NULL), | |
72 | fMCMT(NULL), | |
73 | fTrackletArray(NULL), | |
74 | fZSMap(NULL), | |
75 | fFeeParam(NULL), | |
76 | fTrapConfig(NULL), | |
77 | fDigitsManager(NULL), | |
78 | fPedAcc(NULL), | |
79 | fGainCounterA(NULL), | |
80 | fGainCounterB(NULL), | |
81 | fTailAmplLong(NULL), | |
82 | fTailAmplShort(NULL), | |
83 | fNHits(0), | |
84 | fFitReg(NULL) | |
dfd03fc3 | 85 | { |
86 | // | |
b0a41e80 | 87 | // AliTRDmcmSim default constructor |
dfd03fc3 | 88 | // By default, nothing is initialized. |
89 | // It is necessary to issue Init before use. | |
90 | } | |
91 | ||
dfd03fc3 | 92 | AliTRDmcmSim::~AliTRDmcmSim() |
93 | { | |
94 | // | |
95 | // AliTRDmcmSim destructor | |
96 | // | |
0c349049 | 97 | |
b0a41e80 | 98 | if(fInitialized) { |
ce4786b9 | 99 | for( Int_t iAdc = 0 ; iAdc < fgkNADC; iAdc++ ) { |
100 | delete [] fADCR[iAdc]; | |
101 | delete [] fADCF[iAdc]; | |
dfd03fc3 | 102 | } |
16e077d0 | 103 | delete [] fADCR; |
104 | delete [] fADCF; | |
ce4786b9 | 105 | delete [] fZSMap; |
1d93b218 | 106 | delete [] fMCMT; |
b0a41e80 | 107 | |
108 | delete [] fPedAcc; | |
109 | delete [] fGainCounterA; | |
110 | delete [] fGainCounterB; | |
111 | delete [] fTailAmplLong; | |
112 | delete [] fTailAmplShort; | |
113 | delete [] fFitReg; | |
114 | ||
115 | fTrackletArray->Delete(); | |
116 | delete fTrackletArray; | |
1d93b218 | 117 | } |
dfd03fc3 | 118 | } |
119 | ||
b0a41e80 | 120 | void AliTRDmcmSim::Init( Int_t det, Int_t robPos, Int_t mcmPos, Bool_t /* newEvent */ ) |
dfd03fc3 | 121 | { |
0c349049 | 122 | // |
ce4786b9 | 123 | // Initialize the class with new MCM position information |
124 | // memory is allocated in the first initialization | |
0c349049 | 125 | // |
96e6312d | 126 | |
b0a41e80 | 127 | if (!fInitialized) { |
128 | fFeeParam = AliTRDfeeParam::Instance(); | |
129 | fTrapConfig = AliTRDtrapConfig::Instance(); | |
b0a41e80 | 130 | } |
131 | ||
132 | fDetector = det; | |
0c349049 | 133 | fRobPos = robPos; |
134 | fMcmPos = mcmPos; | |
ce4786b9 | 135 | fNTimeBin = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kC13CPUA); |
dfd03fc3 | 136 | fRow = fFeeParam->GetPadRowFromMCM( fRobPos, fMcmPos ); |
23200400 | 137 | |
b0a41e80 | 138 | if (!fInitialized) { |
ce4786b9 | 139 | fADCR = new Int_t *[fgkNADC]; |
140 | fADCF = new Int_t *[fgkNADC]; | |
141 | fZSMap = new Int_t [fgkNADC]; | |
142 | fGainCounterA = new UInt_t[fgkNADC]; | |
143 | fGainCounterB = new UInt_t[fgkNADC]; | |
144 | for( Int_t iAdc = 0 ; iAdc < fgkNADC; iAdc++ ) { | |
145 | fADCR[iAdc] = new Int_t[fNTimeBin]; | |
146 | fADCF[iAdc] = new Int_t[fNTimeBin]; | |
dfd03fc3 | 147 | } |
b0a41e80 | 148 | |
149 | // filter registers | |
ce4786b9 | 150 | fPedAcc = new UInt_t[fgkNADC]; // accumulator for pedestal filter |
151 | fTailAmplLong = new UShort_t[fgkNADC]; | |
152 | fTailAmplShort = new UShort_t[fgkNADC]; | |
b0a41e80 | 153 | |
154 | // tracklet calculation | |
ce4786b9 | 155 | fFitReg = new FitReg_t[fgkNADC]; |
156 | fTrackletArray = new TClonesArray("AliTRDtrackletMCM", fgkMaxTracklets); | |
b0a41e80 | 157 | |
ce4786b9 | 158 | fMCMT = new UInt_t[fgkMaxTracklets]; |
dfd03fc3 | 159 | } |
160 | ||
b0a41e80 | 161 | fInitialized = kTRUE; |
162 | ||
163 | Reset(); | |
164 | } | |
165 | ||
166 | void AliTRDmcmSim::Reset() | |
167 | { | |
168 | // Resets the data values and internal filter registers | |
169 | // by re-initialising them | |
170 | ||
ce4786b9 | 171 | if( !CheckInitialized() ) |
172 | return; | |
5896bc23 | 173 | |
ce4786b9 | 174 | for( Int_t iAdc = 0 ; iAdc < fgkNADC; iAdc++ ) { |
175 | for( Int_t it = 0 ; it < fNTimeBin ; it++ ) { | |
176 | fADCR[iAdc][it] = 0; | |
177 | fADCF[iAdc][it] = 0; | |
dfd03fc3 | 178 | } |
ce4786b9 | 179 | fZSMap[iAdc] = -1; // Default unread, low active bit mask |
180 | fGainCounterA[iAdc] = 0; | |
181 | fGainCounterB[iAdc] = 0; | |
dfd03fc3 | 182 | } |
ecf39416 | 183 | |
ce4786b9 | 184 | for(Int_t i = 0; i < fgkMaxTracklets; i++) { |
1d93b218 | 185 | fMCMT[i] = 0; |
186 | } | |
ce4786b9 | 187 | |
188 | for (Int_t iDict = 0; iDict < 3; iDict++) | |
189 | fDict[iDict] = 0x0; | |
b0a41e80 | 190 | |
191 | FilterPedestalInit(); | |
192 | FilterGainInit(); | |
ce4786b9 | 193 | FilterTailInit(); |
b0a41e80 | 194 | } |
1d93b218 | 195 | |
4ff7ed2b | 196 | void AliTRDmcmSim::SetNTimebins(Int_t ntimebins) |
197 | { | |
ce4786b9 | 198 | // Reallocate memory if a change in the number of timebins |
199 | // is needed (should not be the case for real data) | |
200 | ||
201 | if( !CheckInitialized() ) | |
202 | return; | |
203 | ||
4ff7ed2b | 204 | fNTimeBin = ntimebins; |
ce4786b9 | 205 | for( Int_t iAdc = 0 ; iAdc < fgkNADC; iAdc++ ) { |
206 | delete fADCR[iAdc]; | |
207 | delete fADCF[iAdc]; | |
208 | fADCR[iAdc] = new Int_t[fNTimeBin]; | |
209 | fADCF[iAdc] = new Int_t[fNTimeBin]; | |
4ff7ed2b | 210 | } |
211 | } | |
212 | ||
ab9f7002 | 213 | Bool_t AliTRDmcmSim::LoadMCM(AliRunLoader* const runloader, Int_t det, Int_t rob, Int_t mcm) |
b0a41e80 | 214 | { |
ce4786b9 | 215 | // loads the ADC data as obtained from the digitsManager for the specified MCM. |
216 | // This method is meant for rare execution, e.g. in the visualization. When called | |
217 | // frequently use SetData(...) instead. | |
b0a41e80 | 218 | |
64e3d742 | 219 | Init(det, rob, mcm); |
b0a41e80 | 220 | |
221 | if (!runloader) { | |
222 | AliError("No Runloader given"); | |
223 | return kFALSE; | |
224 | } | |
225 | ||
226 | AliLoader *trdLoader = runloader->GetLoader("TRDLoader"); | |
227 | if (!trdLoader) { | |
228 | AliError("Could not get TRDLoader"); | |
229 | return kFALSE; | |
230 | } | |
231 | ||
5eba8ada | 232 | Bool_t retval = kTRUE; |
b0a41e80 | 233 | trdLoader->LoadDigits(); |
40bd6ee4 | 234 | fDigitsManager = 0x0; |
b0a41e80 | 235 | AliTRDdigitsManager *digMgr = new AliTRDdigitsManager(); |
236 | digMgr->SetSDigits(0); | |
237 | digMgr->CreateArrays(); | |
238 | digMgr->ReadDigits(trdLoader->TreeD()); | |
239 | AliTRDarrayADC *digits = (AliTRDarrayADC*) digMgr->GetDigits(det); | |
5eba8ada | 240 | if (digits->HasData()) { |
241 | digits->Expand(); | |
242 | ||
5896bc23 | 243 | if (fNTimeBin != digits->GetNtime()) { |
ce4786b9 | 244 | AliWarning(Form("Changing no. of timebins from %i to %i", fNTimeBin, digits->GetNtime())); |
4ff7ed2b | 245 | SetNTimebins(digits->GetNtime()); |
5896bc23 | 246 | } |
4ff7ed2b | 247 | |
ce4786b9 | 248 | SetData(digits); |
b0a41e80 | 249 | } |
5eba8ada | 250 | else |
251 | retval = kFALSE; | |
4ff7ed2b | 252 | |
b0a41e80 | 253 | delete digMgr; |
4ff7ed2b | 254 | |
255 | return retval; | |
b0a41e80 | 256 | } |
257 | ||
258 | void AliTRDmcmSim::NoiseTest(Int_t nsamples, Int_t mean, Int_t sigma, Int_t inputGain, Int_t inputTail) | |
259 | { | |
260 | // This function can be used to test the filters. | |
261 | // It feeds nsamples of ADC values with a gaussian distribution specified by mean and sigma. | |
262 | // The filter chain implemented here consists of: | |
263 | // Pedestal -> Gain -> Tail | |
264 | // With inputGain and inputTail the input to the gain and tail filter, respectively, | |
265 | // can be chosen where | |
266 | // 0: noise input | |
267 | // 1: pedestal output | |
268 | // 2: gain output | |
269 | // The input has to be chosen from a stage before. | |
270 | // The filter behaviour is controlled by the TRAP parameters from AliTRDtrapConfig in the | |
271 | // same way as in normal simulation. | |
272 | // The functions produces four histograms with the values at the different stages. | |
273 | ||
ce4786b9 | 274 | if( !CheckInitialized() ) |
275 | return; | |
276 | ||
277 | TString nameInputGain; | |
278 | TString nameInputTail; | |
279 | ||
280 | switch (inputGain) { | |
281 | case 0: | |
282 | nameInputGain = "Noise"; | |
283 | break; | |
284 | ||
285 | case 1: | |
286 | nameInputGain = "Pedestal"; | |
287 | break; | |
288 | ||
289 | default: | |
290 | AliError("Undefined input to tail cancellation filter"); | |
291 | return; | |
292 | } | |
293 | ||
294 | switch (inputTail) { | |
295 | case 0: | |
296 | nameInputTail = "Noise"; | |
297 | break; | |
298 | ||
299 | case 1: | |
300 | nameInputTail = "Pedestal"; | |
301 | break; | |
302 | ||
303 | case 2: | |
304 | nameInputTail = "Gain"; | |
305 | break; | |
306 | ||
307 | default: | |
308 | AliError("Undefined input to tail cancellation filter"); | |
309 | return; | |
310 | } | |
311 | ||
b0a41e80 | 312 | TH1F *h = new TH1F("noise", "Gaussian Noise;sample;ADC count", |
313 | nsamples, 0, nsamples); | |
ce4786b9 | 314 | TH1F *hfp = new TH1F("ped", "Noise #rightarrow Pedestal filter;sample;ADC count", nsamples, 0, nsamples); |
315 | TH1F *hfg = new TH1F("gain", | |
316 | (nameInputGain + "#rightarrow Gain;sample;ADC count").Data(), | |
317 | nsamples, 0, nsamples); | |
318 | TH1F *hft = new TH1F("tail", | |
319 | (nameInputTail + "#rightarrow Tail;sample;ADC count").Data(), | |
320 | nsamples, 0, nsamples); | |
b0a41e80 | 321 | h->SetStats(kFALSE); |
322 | hfp->SetStats(kFALSE); | |
323 | hfg->SetStats(kFALSE); | |
324 | hft->SetStats(kFALSE); | |
325 | ||
326 | Int_t value; // ADC count with noise (10 bit) | |
327 | Int_t valuep; // pedestal filter output (12 bit) | |
328 | Int_t valueg; // gain filter output (12 bit) | |
329 | Int_t valuet; // tail filter value (12 bit) | |
330 | ||
331 | for (Int_t i = 0; i < nsamples; i++) { | |
332 | value = (Int_t) gRandom->Gaus(mean, sigma); // generate noise with gaussian distribution | |
333 | h->SetBinContent(i, value); | |
334 | ||
335 | valuep = FilterPedestalNextSample(1, 0, ((Int_t) value) << 2); | |
336 | ||
337 | if (inputGain == 0) | |
338 | valueg = FilterGainNextSample(1, ((Int_t) value) << 2); | |
339 | else | |
340 | valueg = FilterGainNextSample(1, valuep); | |
341 | ||
342 | if (inputTail == 0) | |
343 | valuet = FilterTailNextSample(1, ((Int_t) value) << 2); | |
344 | else if (inputTail == 1) | |
345 | valuet = FilterTailNextSample(1, valuep); | |
346 | else | |
347 | valuet = FilterTailNextSample(1, valueg); | |
348 | ||
349 | hfp->SetBinContent(i, valuep >> 2); | |
350 | hfg->SetBinContent(i, valueg >> 2); | |
351 | hft->SetBinContent(i, valuet >> 2); | |
352 | } | |
353 | ||
354 | TCanvas *c = new TCanvas; | |
355 | c->Divide(2,2); | |
356 | c->cd(1); | |
357 | h->Draw(); | |
358 | c->cd(2); | |
359 | hfp->Draw(); | |
360 | c->cd(3); | |
361 | hfg->Draw(); | |
362 | c->cd(4); | |
363 | hft->Draw(); | |
dfd03fc3 | 364 | } |
365 | ||
ce4786b9 | 366 | Bool_t AliTRDmcmSim::CheckInitialized() const |
ecf39416 | 367 | { |
0c349049 | 368 | // |
369 | // Check whether object is initialized | |
370 | // | |
371 | ||
ce4786b9 | 372 | if( ! fInitialized ) |
373 | AliError(Form ("AliTRDmcmSim is not initialized but function other than Init() is called.")); | |
374 | ||
ecf39416 | 375 | return fInitialized; |
376 | } | |
377 | ||
ab9f7002 | 378 | void AliTRDmcmSim::Print(Option_t* const option) const |
b0a41e80 | 379 | { |
380 | // Prints the data stored and/or calculated for this MCM. | |
381 | // The output is controlled by option which can be a sequence of any of | |
382 | // the following characters: | |
383 | // R - prints raw ADC data | |
384 | // F - prints filtered data | |
385 | // H - prints detected hits | |
386 | // T - prints found tracklets | |
ce4786b9 | 387 | // The later stages are only meaningful after the corresponding calculations |
b0a41e80 | 388 | // have been performed. |
389 | ||
ce4786b9 | 390 | if ( !CheckInitialized() ) |
391 | return; | |
392 | ||
b0a41e80 | 393 | printf("MCM %i on ROB %i in detector %i\n", fMcmPos, fRobPos, fDetector); |
394 | ||
395 | TString opt = option; | |
ce4786b9 | 396 | if (opt.Contains("R") || opt.Contains("F")) { |
397 | std::cout << *this; | |
1d93b218 | 398 | } |
399 | ||
b0a41e80 | 400 | if (opt.Contains("H")) { |
401 | printf("Found %i hits:\n", fNHits); | |
402 | for (Int_t iHit = 0; iHit < fNHits; iHit++) { | |
403 | printf("Hit %3i in timebin %2i, ADC %2i has charge %3i and position %3i\n", | |
ab9f7002 | 404 | iHit, fHits[iHit].fTimebin, fHits[iHit].fChannel, fHits[iHit].fQtot, fHits[iHit].fYpos); |
b0a41e80 | 405 | } |
1d93b218 | 406 | } |
1d93b218 | 407 | |
b0a41e80 | 408 | if (opt.Contains("T")) { |
409 | printf("Tracklets:\n"); | |
410 | for (Int_t iTrkl = 0; iTrkl < fTrackletArray->GetEntriesFast(); iTrkl++) { | |
411 | printf("tracklet %i: 0x%08x\n", iTrkl, ((AliTRDtrackletMCM*) (*fTrackletArray)[iTrkl])->GetTrackletWord()); | |
412 | } | |
1d93b218 | 413 | } |
b0a41e80 | 414 | } |
1d93b218 | 415 | |
ab9f7002 | 416 | void AliTRDmcmSim::Draw(Option_t* const option) |
b0a41e80 | 417 | { |
418 | // Plots the data stored in a 2-dim. timebin vs. ADC channel plot. | |
419 | // The option selects what data is plotted and can be a sequence of | |
420 | // the following characters: | |
421 | // R - plot raw data (default) | |
422 | // F - plot filtered data (meaningless if R is specified) | |
423 | // In addition to the ADC values: | |
424 | // H - plot hits | |
425 | // T - plot tracklets | |
426 | ||
ce4786b9 | 427 | if( !CheckInitialized() ) |
428 | return; | |
429 | ||
b0a41e80 | 430 | TString opt = option; |
431 | ||
432 | TH2F *hist = new TH2F("mcmdata", Form("Data of MCM %i on ROB %i in detector %i", \ | |
433 | fMcmPos, fRobPos, fDetector), \ | |
ce4786b9 | 434 | fgkNADC, -0.5, fgkNADC-.5, fNTimeBin, -.5, fNTimeBin-.5); |
b0a41e80 | 435 | hist->GetXaxis()->SetTitle("ADC Channel"); |
436 | hist->GetYaxis()->SetTitle("Timebin"); | |
437 | hist->SetStats(kFALSE); | |
438 | ||
439 | if (opt.Contains("R")) { | |
440 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
ce4786b9 | 441 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { |
b0a41e80 | 442 | hist->SetBinContent(iAdc+1, iTimeBin+1, fADCR[iAdc][iTimeBin] >> fgkAddDigits); |
443 | } | |
1d93b218 | 444 | } |
b0a41e80 | 445 | } |
446 | else { | |
447 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
ce4786b9 | 448 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { |
b0a41e80 | 449 | hist->SetBinContent(iAdc+1, iTimeBin+1, fADCF[iAdc][iTimeBin] >> fgkAddDigits); |
450 | } | |
1d93b218 | 451 | } |
1d93b218 | 452 | } |
b0a41e80 | 453 | hist->Draw("colz"); |
1d93b218 | 454 | |
b0a41e80 | 455 | if (opt.Contains("H")) { |
456 | TGraph *grHits = new TGraph(); | |
457 | for (Int_t iHit = 0; iHit < fNHits; iHit++) { | |
458 | grHits->SetPoint(iHit, | |
ab9f7002 | 459 | fHits[iHit].fChannel + 1 + fHits[iHit].fYpos/256., |
460 | fHits[iHit].fTimebin); | |
b0a41e80 | 461 | } |
462 | grHits->Draw("*"); | |
463 | } | |
1d93b218 | 464 | |
b0a41e80 | 465 | if (opt.Contains("T")) { |
466 | TLine *trklLines = new TLine[4]; | |
64e3d742 | 467 | for (Int_t iTrkl = 0; iTrkl < fTrackletArray->GetEntries(); iTrkl++) { |
b0a41e80 | 468 | AliTRDtrackletMCM *trkl = (AliTRDtrackletMCM*) (*fTrackletArray)[iTrkl]; |
ce4786b9 | 469 | Float_t padWidth = 0.635 + 0.03 * (fDetector % 6); |
470 | Float_t offset = padWidth/256. * ((((((fRobPos & 0x1) << 2) + (fMcmPos & 0x3)) * 18) << 8) - ((18*4*2 - 18*2 - 3) << 7)); // revert adding offset in FitTracklet | |
471 | Int_t ndrift = fTrapConfig->GetDmem(0xc025, fDetector, fRobPos, fMcmPos) >> 5; | |
472 | Float_t slope = trkl->GetdY() * 140e-4 / ndrift; | |
473 | ||
474 | Int_t t0 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFS); | |
475 | Int_t t1 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFE); | |
476 | ||
477 | trklLines[iTrkl].SetX1((offset - (trkl->GetY() - slope * t0)) / padWidth); // ??? sign? | |
478 | trklLines[iTrkl].SetY1(t0); | |
479 | trklLines[iTrkl].SetX2((offset - (trkl->GetY() - slope * t1)) / padWidth); // ??? sign? | |
480 | trklLines[iTrkl].SetY2(t1); | |
b0a41e80 | 481 | trklLines[iTrkl].SetLineColor(2); |
482 | trklLines[iTrkl].SetLineWidth(2); | |
483 | printf("Tracklet %i: y = %f, dy = %f, offset = %f\n", iTrkl, trkl->GetY(), (trkl->GetdY() * 140e-4), offset); | |
484 | trklLines[iTrkl].Draw(); | |
485 | } | |
486 | } | |
1d93b218 | 487 | } |
488 | ||
ce4786b9 | 489 | void AliTRDmcmSim::SetData( Int_t adc, Int_t* const data ) |
dfd03fc3 | 490 | { |
0c349049 | 491 | // |
dfd03fc3 | 492 | // Store ADC data into array of raw data |
0c349049 | 493 | // |
dfd03fc3 | 494 | |
ecf39416 | 495 | if( !CheckInitialized() ) return; |
dfd03fc3 | 496 | |
ce4786b9 | 497 | if( adc < 0 || adc >= fgkNADC ) { |
498 | AliError(Form ("Error: ADC %i is out of range (0 .. %d).", adc, fgkNADC-1)); | |
dfd03fc3 | 499 | return; |
500 | } | |
501 | ||
4ff7ed2b | 502 | for( Int_t it = 0 ; it < fNTimeBin ; it++ ) { |
ce4786b9 | 503 | fADCR[adc][it] = (Int_t) (data[it]) << fgkAddDigits; |
504 | fADCF[adc][it] = (Int_t) (data[it]) << fgkAddDigits; | |
dfd03fc3 | 505 | } |
506 | } | |
507 | ||
ce4786b9 | 508 | void AliTRDmcmSim::SetData( Int_t adc, Int_t it, Int_t data ) |
dfd03fc3 | 509 | { |
0c349049 | 510 | // |
dfd03fc3 | 511 | // Store ADC data into array of raw data |
0c349049 | 512 | // |
dfd03fc3 | 513 | |
ecf39416 | 514 | if( !CheckInitialized() ) return; |
dfd03fc3 | 515 | |
ce4786b9 | 516 | if( adc < 0 || adc >= fgkNADC ) { |
517 | AliError(Form ("Error: ADC %i is out of range (0 .. %d).", adc, fgkNADC-1)); | |
dfd03fc3 | 518 | return; |
519 | } | |
520 | ||
ce4786b9 | 521 | fADCR[adc][it] = data << fgkAddDigits; |
522 | fADCF[adc][it] = data << fgkAddDigits; | |
b0a41e80 | 523 | } |
524 | ||
40bd6ee4 | 525 | void AliTRDmcmSim::SetData(AliTRDarrayADC* const adcArray, AliTRDdigitsManager *digitsManager) |
b0a41e80 | 526 | { |
ab9f7002 | 527 | // Set the ADC data from an AliTRDarrayADC |
528 | ||
ce4786b9 | 529 | if( !CheckInitialized() ) |
b0a41e80 | 530 | return; |
b0a41e80 | 531 | |
40bd6ee4 | 532 | fDigitsManager = digitsManager; |
ce4786b9 | 533 | if (fDigitsManager) { |
534 | for (Int_t iDict = 0; iDict < 3; iDict++) { | |
535 | AliTRDarrayDictionary *newDict = (AliTRDarrayDictionary*) fDigitsManager->GetDictionary(fDetector, iDict); | |
536 | if (fDict[iDict] != 0x0 && newDict != 0x0) { | |
537 | ||
538 | if (fDict[iDict] == newDict) | |
539 | continue; | |
40bd6ee4 | 540 | |
ce4786b9 | 541 | fDict[iDict] = newDict; |
542 | ||
543 | if (fDict[iDict]->GetDim() == 0) { | |
544 | AliError(Form("Dictionary %i of det. %i has dim. 0", fDetector, iDict)); | |
545 | continue; | |
546 | } | |
547 | fDict[iDict]->Expand(); | |
548 | } | |
549 | else { | |
550 | fDict[iDict] = newDict; | |
551 | if (fDict[iDict]) | |
552 | fDict[iDict]->Expand(); | |
553 | } | |
554 | } | |
5896bc23 | 555 | } |
4ff7ed2b | 556 | |
ce4786b9 | 557 | if (fNTimeBin != adcArray->GetNtime()) |
558 | SetNTimebins(adcArray->GetNtime()); | |
559 | ||
560 | Int_t offset = (fMcmPos % 4 + 1) * 21 + (fRobPos % 2) * 84 - 1; | |
b0a41e80 | 561 | |
562 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
ce4786b9 | 563 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { |
564 | Int_t value = adcArray->GetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin); | |
565 | if (value < 0 || (offset - iAdc < 1) || (offset - iAdc > 165)) { | |
566 | fADCR[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP) + (fgAddBaseline << fgkAddDigits); | |
4ff7ed2b | 567 | fADCF[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP) + (fgAddBaseline << fgkAddDigits); |
b0a41e80 | 568 | } |
569 | else { | |
ce4786b9 | 570 | fZSMap[iAdc] = 0; |
571 | fADCR[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits); | |
572 | fADCF[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits); | |
b0a41e80 | 573 | } |
574 | } | |
575 | } | |
dfd03fc3 | 576 | } |
577 | ||
ce51199c | 578 | void AliTRDmcmSim::SetDataByPad(AliTRDarrayADC* const adcArray, AliTRDdigitsManager *digitsManager) |
579 | { | |
580 | // Set the ADC data from an AliTRDarrayADC | |
581 | // (by pad, to be used during initial reading in simulation) | |
582 | ||
583 | if( !CheckInitialized() ) | |
584 | return; | |
585 | ||
586 | fDigitsManager = digitsManager; | |
587 | if (fDigitsManager) { | |
588 | for (Int_t iDict = 0; iDict < 3; iDict++) { | |
589 | AliTRDarrayDictionary *newDict = (AliTRDarrayDictionary*) fDigitsManager->GetDictionary(fDetector, iDict); | |
590 | if (fDict[iDict] != 0x0 && newDict != 0x0) { | |
591 | ||
592 | if (fDict[iDict] == newDict) | |
593 | continue; | |
594 | ||
595 | fDict[iDict] = newDict; | |
596 | ||
597 | if (fDict[iDict]->GetDim() == 0) { | |
598 | AliError(Form("Dictionary %i of det. %i has dim. 0", fDetector, iDict)); | |
599 | continue; | |
600 | } | |
601 | fDict[iDict]->Expand(); | |
602 | } | |
603 | else { | |
604 | fDict[iDict] = newDict; | |
605 | if (fDict[iDict]) | |
606 | fDict[iDict]->Expand(); | |
607 | } | |
608 | } | |
609 | } | |
610 | ||
611 | if (fNTimeBin != adcArray->GetNtime()) | |
612 | SetNTimebins(adcArray->GetNtime()); | |
613 | ||
614 | Int_t offset = (fMcmPos % 4 + 1) * 18 + (fRobPos % 2) * 72 + 1; | |
615 | ||
616 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
617 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { | |
618 | Int_t value = -1; | |
619 | Int_t pad = offset - iAdc; | |
620 | if (pad > -1 && pad < 144) | |
621 | value = adcArray->GetData(GetRow(), offset - iAdc, iTimeBin); | |
622 | // Int_t value = adcArray->GetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin); | |
623 | if (value < 0 || (offset - iAdc < 1) || (offset - iAdc > 165)) { | |
624 | fADCR[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP) + (fgAddBaseline << fgkAddDigits); | |
625 | fADCF[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP) + (fgAddBaseline << fgkAddDigits); | |
626 | } | |
627 | else { | |
628 | fZSMap[iAdc] = 0; | |
629 | fADCR[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits); | |
630 | fADCF[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits); | |
631 | } | |
632 | } | |
633 | } | |
634 | } | |
635 | ||
ce4786b9 | 636 | void AliTRDmcmSim::SetDataPedestal( Int_t adc ) |
dfd03fc3 | 637 | { |
0c349049 | 638 | // |
dfd03fc3 | 639 | // Store ADC data into array of raw data |
0c349049 | 640 | // |
dfd03fc3 | 641 | |
ce4786b9 | 642 | if( !CheckInitialized() ) |
643 | return; | |
dfd03fc3 | 644 | |
ce4786b9 | 645 | if( adc < 0 || adc >= fgkNADC ) { |
dfd03fc3 | 646 | return; |
647 | } | |
648 | ||
649 | for( Int_t it = 0 ; it < fNTimeBin ; it++ ) { | |
ce4786b9 | 650 | fADCR[adc][it] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP) + (fgAddBaseline << fgkAddDigits); |
651 | fADCF[adc][it] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP) + (fgAddBaseline << fgkAddDigits); | |
dfd03fc3 | 652 | } |
653 | } | |
654 | ||
ce4786b9 | 655 | Bool_t AliTRDmcmSim::GetHit(Int_t index, Int_t &channel, Int_t &timebin, Int_t &qtot, Int_t &ypos, Float_t &y, Int_t &label) const |
656 | { | |
657 | // retrieve the MC hit information (not available in TRAP hardware) | |
658 | ||
659 | if (index < 0 || index >= fNHits) | |
660 | return kFALSE; | |
661 | ||
662 | channel = fHits[index].fChannel; | |
663 | timebin = fHits[index].fTimebin; | |
664 | qtot = fHits[index].fQtot; | |
665 | ypos = fHits[index].fYpos; | |
666 | y = (Float_t) ((((((fRobPos & 0x1) << 2) + (fMcmPos & 0x3)) * 18) << 8) - ((18*4*2 - 18*2 - 1) << 7) - | |
667 | (channel << 8) - ypos) | |
668 | * (0.635 + 0.03 * (fDetector % 6)) | |
669 | / 256.0; | |
670 | label = fHits[index].fLabel; | |
671 | ||
672 | return kTRUE; | |
673 | } | |
674 | ||
675 | Int_t AliTRDmcmSim::GetCol( Int_t adc ) | |
dfd03fc3 | 676 | { |
0c349049 | 677 | // |
dfd03fc3 | 678 | // Return column id of the pad for the given ADC channel |
0c349049 | 679 | // |
680 | ||
f793c83d | 681 | if( !CheckInitialized() ) |
682 | return -1; | |
dfd03fc3 | 683 | |
ce4786b9 | 684 | Int_t col = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adc); |
a6d08b7f | 685 | if (col < 0 || col >= fFeeParam->GetNcol()) |
686 | return -1; | |
687 | else | |
688 | return col; | |
dfd03fc3 | 689 | } |
690 | ||
ce4786b9 | 691 | Int_t AliTRDmcmSim::ProduceRawStream( UInt_t *buf, Int_t bufSize, UInt_t iEv) const |
dfd03fc3 | 692 | { |
0c349049 | 693 | // |
dfd03fc3 | 694 | // Produce raw data stream from this MCM and put in buf |
0c349049 | 695 | // Returns number of words filled, or negative value |
696 | // with -1 * number of overflowed words | |
697 | // | |
dfd03fc3 | 698 | |
ce4786b9 | 699 | if( !CheckInitialized() ) |
700 | return 0; | |
701 | ||
dfd03fc3 | 702 | UInt_t x; |
dfd03fc3 | 703 | Int_t nw = 0; // Number of written words |
704 | Int_t of = 0; // Number of overflowed words | |
705 | Int_t rawVer = fFeeParam->GetRAWversion(); | |
706 | Int_t **adc; | |
b0a41e80 | 707 | Int_t nActiveADC = 0; // number of activated ADC bits in a word |
dfd03fc3 | 708 | |
ce4786b9 | 709 | if( !CheckInitialized() ) |
710 | return 0; | |
ecf39416 | 711 | |
ce4786b9 | 712 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBSF) != 0) // store unfiltered data |
dfd03fc3 | 713 | adc = fADCR; |
ce4786b9 | 714 | else |
dfd03fc3 | 715 | adc = fADCF; |
ce4786b9 | 716 | |
dfd03fc3 | 717 | // Produce MCM header |
b0a41e80 | 718 | x = (1<<31) | (fRobPos << 28) | (fMcmPos << 24) | ((iEv % 0x100000) << 4) | 0xC; |
719 | ||
ce4786b9 | 720 | if (nw < bufSize) { |
dfd03fc3 | 721 | buf[nw++] = x; |
722 | } | |
723 | else { | |
724 | of++; | |
725 | } | |
726 | ||
b0a41e80 | 727 | // Produce ADC mask : nncc cccm mmmm mmmm mmmm mmmm mmmm 1100 |
728 | // n : unused , c : ADC count, m : selected ADCs | |
dfd03fc3 | 729 | if( rawVer >= 3 ) { |
730 | x = 0; | |
ce4786b9 | 731 | for( Int_t iAdc = 0 ; iAdc < fgkNADC ; iAdc++ ) { |
732 | if( ~fZSMap[iAdc] != 0 ) { // 0 means not suppressed | |
b0a41e80 | 733 | x = x | (1 << (iAdc+4) ); // last 4 digit reserved for 1100=0xc |
734 | nActiveADC++; // number of 1 in mmm....m | |
dfd03fc3 | 735 | } |
736 | } | |
b0a41e80 | 737 | x = x | (1 << 30) | ( ( 0x3FFFFFFC ) & (~(nActiveADC) << 25) ) | 0xC; // nn = 01, ccccc are inverted, 0xc=1100 |
b0a41e80 | 738 | |
ce4786b9 | 739 | if (nw < bufSize) { |
dfd03fc3 | 740 | buf[nw++] = x; |
741 | } | |
742 | else { | |
743 | of++; | |
744 | } | |
745 | } | |
746 | ||
747 | // Produce ADC data. 3 timebins are packed into one 32 bits word | |
748 | // In this version, different ADC channel will NOT share the same word | |
749 | ||
750 | UInt_t aa=0, a1=0, a2=0, a3=0; | |
751 | ||
752 | for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) { | |
ce4786b9 | 753 | if( rawVer>= 3 && ~fZSMap[iAdc] == 0 ) continue; // Zero Suppression, 0 means not suppressed |
dfd03fc3 | 754 | aa = !(iAdc & 1) + 2; |
755 | for (Int_t iT = 0; iT < fNTimeBin; iT+=3 ) { | |
b0a41e80 | 756 | a1 = ((iT ) < fNTimeBin ) ? adc[iAdc][iT ] >> fgkAddDigits : 0; |
757 | a2 = ((iT + 1) < fNTimeBin ) ? adc[iAdc][iT+1] >> fgkAddDigits : 0; | |
758 | a3 = ((iT + 2) < fNTimeBin ) ? adc[iAdc][iT+2] >> fgkAddDigits : 0; | |
ecf39416 | 759 | x = (a3 << 22) | (a2 << 12) | (a1 << 2) | aa; |
ce4786b9 | 760 | if (nw < bufSize) { |
b0a41e80 | 761 | buf[nw++] = x; |
ecf39416 | 762 | } |
763 | else { | |
b0a41e80 | 764 | of++; |
ecf39416 | 765 | } |
dfd03fc3 | 766 | } |
767 | } | |
768 | ||
769 | if( of != 0 ) return -of; else return nw; | |
770 | } | |
771 | ||
ce4786b9 | 772 | Int_t AliTRDmcmSim::ProduceTrackletStream( UInt_t *buf, Int_t bufSize ) |
987ba9a3 | 773 | { |
774 | // | |
b0a41e80 | 775 | // Produce tracklet data stream from this MCM and put in buf |
987ba9a3 | 776 | // Returns number of words filled, or negative value |
777 | // with -1 * number of overflowed words | |
778 | // | |
779 | ||
ce4786b9 | 780 | if( !CheckInitialized() ) |
781 | return 0; | |
782 | ||
987ba9a3 | 783 | Int_t nw = 0; // Number of written words |
784 | Int_t of = 0; // Number of overflowed words | |
b0a41e80 | 785 | |
b0a41e80 | 786 | // Produce tracklet data. A maximum of four 32 Bit words will be written per MCM |
787 | // fMCMT is filled continuously until no more tracklet words available | |
987ba9a3 | 788 | |
f793c83d | 789 | for (Int_t iTracklet = 0; iTracklet < fTrackletArray->GetEntriesFast(); iTracklet++) { |
ce4786b9 | 790 | if (nw < bufSize) |
f793c83d | 791 | buf[nw++] = ((AliTRDtrackletMCM*) (*fTrackletArray)[iTracklet])->GetTrackletWord(); |
792 | else | |
793 | of++; | |
987ba9a3 | 794 | } |
b0a41e80 | 795 | |
796 | if( of != 0 ) return -of; else return nw; | |
797 | } | |
987ba9a3 | 798 | |
b0a41e80 | 799 | void AliTRDmcmSim::Filter() |
800 | { | |
801 | // | |
802 | // Filter the raw ADC values. The active filter stages and their | |
803 | // parameters are taken from AliTRDtrapConfig. | |
804 | // The raw data is stored separate from the filtered data. Thus, | |
805 | // it is possible to run the filters on a set of raw values | |
806 | // sequentially for parameter tuning. | |
807 | // | |
987ba9a3 | 808 | |
ce4786b9 | 809 | if( !CheckInitialized() ) |
b0a41e80 | 810 | return; |
987ba9a3 | 811 | |
b0a41e80 | 812 | // Apply filters sequentially. Bypass is handled by filters |
813 | // since counters and internal registers may be updated even | |
814 | // if the filter is bypassed. | |
815 | // The first filter takes the data from fADCR and | |
816 | // outputs to fADCF. | |
817 | ||
818 | // Non-linearity filter not implemented. | |
819 | FilterPedestal(); | |
820 | FilterGain(); | |
821 | FilterTail(); | |
822 | // Crosstalk filter not implemented. | |
823 | } | |
987ba9a3 | 824 | |
ce4786b9 | 825 | void AliTRDmcmSim::FilterPedestalInit(Int_t baseline) |
b0a41e80 | 826 | { |
827 | // Initializes the pedestal filter assuming that the input has | |
828 | // been constant for a long time (compared to the time constant). | |
987ba9a3 | 829 | |
b0a41e80 | 830 | UShort_t fptc = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPTC); // 0..3, 0 - fastest, 3 - slowest |
987ba9a3 | 831 | |
ce4786b9 | 832 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) |
833 | fPedAcc[iAdc] = (baseline << 2) * (1 << fgkFPshifts[fptc]); | |
987ba9a3 | 834 | } |
835 | ||
b0a41e80 | 836 | UShort_t AliTRDmcmSim::FilterPedestalNextSample(Int_t adc, Int_t timebin, UShort_t value) |
1d93b218 | 837 | { |
b0a41e80 | 838 | // Returns the output of the pedestal filter given the input value. |
839 | // The output depends on the internal registers and, thus, the | |
840 | // history of the filter. | |
1d93b218 | 841 | |
b0a41e80 | 842 | UShort_t fpnp = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP); // 0..511 -> 0..127.75, pedestal at the output |
843 | UShort_t fptc = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPTC); // 0..3, 0 - fastest, 3 - slowest | |
ce4786b9 | 844 | UShort_t fpby = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPBY); // 0..1 bypass, active low |
1d93b218 | 845 | |
b0a41e80 | 846 | UShort_t accumulatorShifted; |
847 | Int_t correction; | |
848 | UShort_t inpAdd; | |
849 | ||
850 | inpAdd = value + fpnp; | |
1d93b218 | 851 | |
ce4786b9 | 852 | accumulatorShifted = (fPedAcc[adc] >> fgkFPshifts[fptc]) & 0x3FF; // 10 bits |
b0a41e80 | 853 | if (timebin == 0) // the accumulator is disabled in the drift time |
854 | { | |
855 | correction = (value & 0x3FF) - accumulatorShifted; | |
856 | fPedAcc[adc] = (fPedAcc[adc] + correction) & 0x7FFFFFFF; // 31 bits | |
1d93b218 | 857 | } |
858 | ||
ce4786b9 | 859 | if (fpby == 0) |
860 | return value; | |
861 | ||
b0a41e80 | 862 | if (inpAdd <= accumulatorShifted) |
863 | return 0; | |
864 | else | |
865 | { | |
866 | inpAdd = inpAdd - accumulatorShifted; | |
867 | if (inpAdd > 0xFFF) | |
868 | return 0xFFF; | |
869 | else | |
870 | return inpAdd; | |
871 | } | |
1d93b218 | 872 | } |
873 | ||
b0a41e80 | 874 | void AliTRDmcmSim::FilterPedestal() |
dfd03fc3 | 875 | { |
0c349049 | 876 | // |
b0a41e80 | 877 | // Apply pedestal filter |
0c349049 | 878 | // |
b0a41e80 | 879 | // As the first filter in the chain it reads data from fADCR |
880 | // and outputs to fADCF. | |
881 | // It has only an effect if previous samples have been fed to | |
882 | // find the pedestal. Currently, the simulation assumes that | |
883 | // the input has been stable for a sufficiently long time. | |
dfd03fc3 | 884 | |
b0a41e80 | 885 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
ce4786b9 | 886 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { |
b0a41e80 | 887 | fADCF[iAdc][iTimeBin] = FilterPedestalNextSample(iAdc, iTimeBin, fADCR[iAdc][iTimeBin]); |
dfd03fc3 | 888 | } |
889 | } | |
b0a41e80 | 890 | } |
891 | ||
892 | void AliTRDmcmSim::FilterGainInit() | |
893 | { | |
894 | // Initializes the gain filter. In this case, only threshold | |
895 | // counters are reset. | |
dfd03fc3 | 896 | |
ce4786b9 | 897 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { |
b0a41e80 | 898 | // these are counters which in hardware continue |
899 | // until maximum or reset | |
900 | fGainCounterA[iAdc] = 0; | |
901 | fGainCounterB[iAdc] = 0; | |
902 | } | |
dfd03fc3 | 903 | } |
904 | ||
b0a41e80 | 905 | UShort_t AliTRDmcmSim::FilterGainNextSample(Int_t adc, UShort_t value) |
dfd03fc3 | 906 | { |
b0a41e80 | 907 | // Apply the gain filter to the given value. |
908 | // BEGIN_LATEX O_{i}(t) = #gamma_{i} * I_{i}(t) + a_{i} END_LATEX | |
909 | // The output depends on the internal registers and, thus, the | |
910 | // history of the filter. | |
23200400 | 911 | |
b0a41e80 | 912 | UShort_t fgby = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFGBY); // bypass, active low |
913 | UShort_t fgf = fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGF0 + adc)); // 0x700 + (0 & 0x1ff); | |
914 | UShort_t fga = fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGA0 + adc)); // 40; | |
915 | UShort_t fgta = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFGTA); // 20; | |
916 | UShort_t fgtb = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFGTB); // 2060; | |
dfd03fc3 | 917 | |
ce4786b9 | 918 | UInt_t corr; // corrected value |
dfd03fc3 | 919 | |
b0a41e80 | 920 | value &= 0xFFF; |
ce4786b9 | 921 | corr = (value * fgf) >> 11; |
922 | corr = corr > 0xfff ? 0xfff : corr; | |
923 | corr = AddUintClipping(corr, fga, 12); | |
b0a41e80 | 924 | |
925 | // Update threshold counters | |
926 | // not really useful as they are cleared with every new event | |
ce4786b9 | 927 | if (!((fGainCounterA[adc] == 0x3FFFFFF) || (fGainCounterB[adc] == 0x3FFFFFF))) |
928 | // stop when full | |
b0a41e80 | 929 | { |
ce4786b9 | 930 | if (corr >= fgtb) |
b0a41e80 | 931 | fGainCounterB[adc]++; |
ce4786b9 | 932 | else if (corr >= fgta) |
b0a41e80 | 933 | fGainCounterA[adc]++; |
dfd03fc3 | 934 | } |
b0a41e80 | 935 | |
ce4786b9 | 936 | if (fgby == 1) |
937 | return corr; | |
938 | else | |
939 | return value; | |
dfd03fc3 | 940 | } |
941 | ||
dfd03fc3 | 942 | void AliTRDmcmSim::FilterGain() |
943 | { | |
b0a41e80 | 944 | // Read data from fADCF and apply gain filter. |
0c349049 | 945 | |
ce4786b9 | 946 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { |
b0a41e80 | 947 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
948 | fADCF[iAdc][iTimeBin] = FilterGainNextSample(iAdc, fADCF[iAdc][iTimeBin]); | |
949 | } | |
950 | } | |
dfd03fc3 | 951 | } |
952 | ||
b0a41e80 | 953 | void AliTRDmcmSim::FilterTailInit(Int_t baseline) |
dfd03fc3 | 954 | { |
b0a41e80 | 955 | // Initializes the tail filter assuming that the input has |
956 | // been at the baseline value (configured by FTFP) for a | |
957 | // sufficiently long time. | |
958 | ||
959 | // exponents and weight calculated from configuration | |
960 | UShort_t alphaLong = 0x3ff & fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTAL); // the weight of the long component | |
961 | UShort_t lambdaLong = (1 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLL) & 0x1FF); // the multiplier | |
962 | UShort_t lambdaShort = (0 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLS) & 0x1FF); // the multiplier | |
963 | ||
964 | Float_t lambdaL = lambdaLong * 1.0 / (1 << 11); | |
965 | Float_t lambdaS = lambdaShort * 1.0 / (1 << 11); | |
966 | Float_t alphaL = alphaLong * 1.0 / (1 << 11); | |
967 | Float_t qup, qdn; | |
968 | qup = (1 - lambdaL) * (1 - lambdaS); | |
969 | qdn = 1 - lambdaS * alphaL - lambdaL * (1 - alphaL); | |
970 | Float_t kdc = qup/qdn; | |
971 | ||
972 | Float_t kt, ql, qs; | |
973 | UShort_t aout; | |
ce4786b9 | 974 | |
975 | if (baseline < 0) | |
976 | baseline = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP); | |
b0a41e80 | 977 | |
b0a41e80 | 978 | ql = lambdaL * (1 - lambdaS) * alphaL; |
979 | qs = lambdaS * (1 - lambdaL) * (1 - alphaL); | |
980 | ||
ce4786b9 | 981 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { |
982 | Int_t value = baseline & 0xFFF; | |
983 | Int_t corr = (value * fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGF0 + iAdc))) >> 11; | |
984 | corr = corr > 0xfff ? 0xfff : corr; | |
985 | corr = AddUintClipping(corr, fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGA0 + iAdc)), 12); | |
986 | ||
987 | kt = kdc * baseline; | |
988 | aout = baseline - (UShort_t) kt; | |
989 | ||
b0a41e80 | 990 | fTailAmplLong[iAdc] = (UShort_t) (aout * ql / (ql + qs)); |
991 | fTailAmplShort[iAdc] = (UShort_t) (aout * qs / (ql + qs)); | |
992 | } | |
993 | } | |
dfd03fc3 | 994 | |
b0a41e80 | 995 | UShort_t AliTRDmcmSim::FilterTailNextSample(Int_t adc, UShort_t value) |
996 | { | |
997 | // Returns the output of the tail filter for the given input value. | |
998 | // The output depends on the internal registers and, thus, the | |
999 | // history of the filter. | |
1000 | ||
1001 | // exponents and weight calculated from configuration | |
ce4786b9 | 1002 | UShort_t alphaLong = 0x3ff & fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTAL); // the weight of the long component |
1003 | UShort_t lambdaLong = (1 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLL) & 0x1FF); // the multiplier of the long component | |
1004 | UShort_t lambdaShort = (0 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLS) & 0x1FF); // the multiplier of the short component | |
b0a41e80 | 1005 | |
ce4786b9 | 1006 | // intermediate signals |
1007 | UInt_t aDiff; | |
1008 | UInt_t alInpv; | |
b0a41e80 | 1009 | UShort_t aQ; |
ce4786b9 | 1010 | UInt_t tmp; |
b0a41e80 | 1011 | |
ab9f7002 | 1012 | UShort_t inpVolt = value & 0xFFF; // 12 bits |
b0a41e80 | 1013 | |
ce4786b9 | 1014 | // add the present generator outputs |
1015 | aQ = AddUintClipping(fTailAmplLong[adc], fTailAmplShort[adc], 12); | |
1016 | ||
1017 | // calculate the difference between the input and the generated signal | |
1018 | if (inpVolt > aQ) | |
1019 | aDiff = inpVolt - aQ; | |
1020 | else | |
1021 | aDiff = 0; | |
1022 | ||
1023 | // the inputs to the two generators, weighted | |
1024 | alInpv = (aDiff * alphaLong) >> 11; | |
1025 | ||
1026 | // the new values of the registers, used next time | |
1027 | // long component | |
1028 | tmp = AddUintClipping(fTailAmplLong[adc], alInpv, 12); | |
1029 | tmp = (tmp * lambdaLong) >> 11; | |
1030 | fTailAmplLong[adc] = tmp & 0xFFF; | |
1031 | // short component | |
1032 | tmp = AddUintClipping(fTailAmplShort[adc], aDiff - alInpv, 12); | |
1033 | tmp = (tmp * lambdaShort) >> 11; | |
1034 | fTailAmplShort[adc] = tmp & 0xFFF; | |
1035 | ||
1036 | // the output of the filter | |
b0a41e80 | 1037 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTBY) == 0) // bypass mode, active low |
1038 | return value; | |
1039 | else | |
b0a41e80 | 1040 | return aDiff; |
b0a41e80 | 1041 | } |
dfd03fc3 | 1042 | |
b0a41e80 | 1043 | void AliTRDmcmSim::FilterTail() |
1044 | { | |
ce4786b9 | 1045 | // Apply tail cancellation filter to all data. |
dfd03fc3 | 1046 | |
b0a41e80 | 1047 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
ce4786b9 | 1048 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { |
b0a41e80 | 1049 | fADCF[iAdc][iTimeBin] = FilterTailNextSample(iAdc, fADCF[iAdc][iTimeBin]); |
dfd03fc3 | 1050 | } |
dfd03fc3 | 1051 | } |
dfd03fc3 | 1052 | } |
1053 | ||
dfd03fc3 | 1054 | void AliTRDmcmSim::ZSMapping() |
1055 | { | |
0c349049 | 1056 | // |
dfd03fc3 | 1057 | // Zero Suppression Mapping implemented in TRAP chip |
ce4786b9 | 1058 | // only implemented for up to 30 timebins |
dfd03fc3 | 1059 | // |
1060 | // See detail TRAP manual "Data Indication" section: | |
1061 | // http://www.kip.uni-heidelberg.de/ti/TRD/doc/trap/TRAP-UserManual.pdf | |
0c349049 | 1062 | // |
dfd03fc3 | 1063 | |
ce4786b9 | 1064 | if( !CheckInitialized() ) |
1065 | return; | |
1066 | ||
1067 | Int_t eBIS = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIS); | |
1068 | Int_t eBIT = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIT); | |
1069 | Int_t eBIL = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIL); | |
1070 | Int_t eBIN = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIN); | |
ecf39416 | 1071 | |
b0a41e80 | 1072 | Int_t **adc = fADCF; |
dfd03fc3 | 1073 | |
ce4786b9 | 1074 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) |
1075 | fZSMap[iAdc] = -1; | |
b0a41e80 | 1076 | |
1077 | for( Int_t it = 0 ; it < fNTimeBin ; it++ ) { | |
ce4786b9 | 1078 | Int_t iAdc; // current ADC channel |
1079 | Int_t ap; | |
1080 | Int_t ac; | |
1081 | Int_t an; | |
1082 | Int_t mask; | |
1083 | Int_t supp; // suppression of the current channel (low active) | |
1084 | ||
1085 | // ----- first channel ----- | |
1086 | iAdc = 0; | |
1087 | ||
1088 | ap = 0; // previous | |
1089 | ac = adc[iAdc ][it]; // current | |
1090 | an = adc[iAdc+1][it]; // next | |
1091 | ||
1092 | mask = ( ac >= ap && ac >= an ) ? 0 : 0x1; // peak center detection | |
1093 | mask += ( ap + ac + an > eBIT ) ? 0 : 0x2; // cluster | |
1094 | mask += ( ac > eBIS ) ? 0 : 0x4; // absolute large peak | |
1095 | ||
1096 | supp = (eBIL >> mask) & 1; | |
1097 | ||
1098 | fZSMap[iAdc] &= ~((1-supp) << it); | |
1099 | if( eBIN == 0 ) { // neighbour sensitivity | |
1100 | fZSMap[iAdc+1] &= ~((1-supp) << it); | |
dfd03fc3 | 1101 | } |
ce4786b9 | 1102 | |
1103 | // ----- last channel ----- | |
1104 | iAdc = fgkNADC - 1; | |
1105 | ||
1106 | ap = adc[iAdc-1][it]; // previous | |
1107 | ac = adc[iAdc ][it]; // current | |
1108 | an = 0; // next | |
1109 | ||
1110 | mask = ( ac >= ap && ac >= an ) ? 0 : 0x1; // peak center detection | |
1111 | mask += ( ap + ac + an > eBIT ) ? 0 : 0x2; // cluster | |
1112 | mask += ( ac > eBIS ) ? 0 : 0x4; // absolute large peak | |
1113 | ||
1114 | supp = (eBIL >> mask) & 1; | |
1115 | ||
1116 | fZSMap[iAdc] &= ~((1-supp) << it); | |
1117 | if( eBIN == 0 ) { // neighbour sensitivity | |
1118 | fZSMap[iAdc-1] &= ~((1-supp) << it); | |
ecf39416 | 1119 | } |
ce4786b9 | 1120 | |
1121 | // ----- middle channels ----- | |
1122 | for( iAdc = 1 ; iAdc < fgkNADC-1; iAdc++ ) { | |
1123 | ap = adc[iAdc-1][it]; // previous | |
1124 | ac = adc[iAdc ][it]; // current | |
1125 | an = adc[iAdc+1][it]; // next | |
1126 | ||
1127 | mask = ( ac >= ap && ac >= an ) ? 0 : 0x1; // peak center detection | |
1128 | mask += ( ap + ac + an > eBIT ) ? 0 : 0x2; // cluster | |
1129 | mask += ( ac > eBIS ) ? 0 : 0x4; // absolute large peak | |
1130 | ||
1131 | supp = (eBIL >> mask) & 1; | |
1132 | ||
1133 | fZSMap[iAdc] &= ~((1-supp) << it); | |
1134 | if( eBIN == 0 ) { // neighbour sensitivity | |
1135 | fZSMap[iAdc-1] &= ~((1-supp) << it); | |
1136 | fZSMap[iAdc+1] &= ~((1-supp) << it); | |
ecf39416 | 1137 | } |
dfd03fc3 | 1138 | } |
ce4786b9 | 1139 | |
dfd03fc3 | 1140 | } |
1141 | } | |
1142 | ||
b0a41e80 | 1143 | void AliTRDmcmSim::AddHitToFitreg(Int_t adc, UShort_t timebin, UShort_t qtot, Short_t ypos, Int_t label) |
dfd03fc3 | 1144 | { |
b0a41e80 | 1145 | // Add the given hit to the fit register which is lateron used for |
1146 | // the tracklet calculation. | |
1147 | // In addition to the fit sums in the fit register MC information | |
1148 | // is stored. | |
1149 | ||
1150 | if ((timebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0)) && | |
1151 | (timebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE0))) | |
ab9f7002 | 1152 | fFitReg[adc].fQ0 += qtot; |
b0a41e80 | 1153 | |
1154 | if ((timebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS1)) && | |
1155 | (timebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1))) | |
ab9f7002 | 1156 | fFitReg[adc].fQ1 += qtot; |
b0a41e80 | 1157 | |
1158 | if ((timebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFS) ) && | |
1159 | (timebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFE))) | |
1160 | { | |
ab9f7002 | 1161 | fFitReg[adc].fSumX += timebin; |
1162 | fFitReg[adc].fSumX2 += timebin*timebin; | |
1163 | fFitReg[adc].fNhits++; | |
1164 | fFitReg[adc].fSumY += ypos; | |
1165 | fFitReg[adc].fSumY2 += ypos*ypos; | |
1166 | fFitReg[adc].fSumXY += timebin*ypos; | |
b0a41e80 | 1167 | } |
1168 | ||
1169 | // register hits (MC info) | |
ab9f7002 | 1170 | fHits[fNHits].fChannel = adc; |
1171 | fHits[fNHits].fQtot = qtot; | |
1172 | fHits[fNHits].fYpos = ypos; | |
1173 | fHits[fNHits].fTimebin = timebin; | |
1174 | fHits[fNHits].fLabel = label; | |
b0a41e80 | 1175 | fNHits++; |
1176 | } | |
dfd03fc3 | 1177 | |
b0a41e80 | 1178 | void AliTRDmcmSim::CalcFitreg() |
1179 | { | |
1180 | // Preprocessing. | |
1181 | // Detect the hits and fill the fit registers. | |
1182 | // Requires 12-bit data from fADCF which means Filter() | |
1183 | // has to be called before even if all filters are bypassed. | |
1184 | ||
b0a41e80 | 1185 | //??? to be clarified: |
64e3d742 | 1186 | UInt_t adcMask = 0xffffffff; |
b0a41e80 | 1187 | |
ab9f7002 | 1188 | UShort_t timebin, adcch, adcLeft, adcCentral, adcRight, hitQual, timebin1, timebin2, qtotTemp; |
b0a41e80 | 1189 | Short_t ypos, fromLeft, fromRight, found; |
ab9f7002 | 1190 | UShort_t qTotal[19]; // the last is dummy |
1191 | UShort_t marked[6], qMarked[6], worse1, worse2; | |
b0a41e80 | 1192 | |
1193 | timebin1 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFS); | |
1194 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0) | |
1195 | < timebin1) | |
1196 | timebin1 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0); | |
1197 | timebin2 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFE); | |
1198 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1) | |
1199 | > timebin2) | |
1200 | timebin2 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1); | |
1201 | ||
1202 | // reset the fit registers | |
1203 | fNHits = 0; | |
ce4786b9 | 1204 | for (adcch = 0; adcch < fgkNADC-2; adcch++) // due to border channels |
b0a41e80 | 1205 | { |
ab9f7002 | 1206 | fFitReg[adcch].fNhits = 0; |
1207 | fFitReg[adcch].fQ0 = 0; | |
1208 | fFitReg[adcch].fQ1 = 0; | |
1209 | fFitReg[adcch].fSumX = 0; | |
1210 | fFitReg[adcch].fSumY = 0; | |
1211 | fFitReg[adcch].fSumX2 = 0; | |
1212 | fFitReg[adcch].fSumY2 = 0; | |
1213 | fFitReg[adcch].fSumXY = 0; | |
b0a41e80 | 1214 | } |
1215 | ||
1216 | for (timebin = timebin1; timebin < timebin2; timebin++) | |
1217 | { | |
ab9f7002 | 1218 | // first find the hit candidates and store the total cluster charge in qTotal array |
b0a41e80 | 1219 | // in case of not hit store 0 there. |
ce4786b9 | 1220 | for (adcch = 0; adcch < fgkNADC-2; adcch++) { |
ab9f7002 | 1221 | if ( ( (adcMask >> adcch) & 7) == 7) //??? all 3 channels are present in case of ZS |
b0a41e80 | 1222 | { |
ab9f7002 | 1223 | adcLeft = fADCF[adcch ][timebin]; |
1224 | adcCentral = fADCF[adcch+1][timebin]; | |
1225 | adcRight = fADCF[adcch+2][timebin]; | |
b0a41e80 | 1226 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPVBY) == 1) |
ab9f7002 | 1227 | hitQual = ( (adcLeft * adcRight) < |
1228 | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPVT) * adcCentral) ); | |
b0a41e80 | 1229 | else |
ab9f7002 | 1230 | hitQual = 1; |
b0a41e80 | 1231 | // The accumulated charge is with the pedestal!!! |
ab9f7002 | 1232 | qtotTemp = adcLeft + adcCentral + adcRight; |
1233 | if ( (hitQual) && | |
1234 | (qtotTemp >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPHT)) && | |
1235 | (adcLeft <= adcCentral) && | |
1236 | (adcCentral > adcRight) ) | |
1237 | qTotal[adcch] = qtotTemp; | |
b0a41e80 | 1238 | else |
ab9f7002 | 1239 | qTotal[adcch] = 0; |
b0a41e80 | 1240 | } |
1241 | else | |
ab9f7002 | 1242 | qTotal[adcch] = 0; //jkl |
ce4786b9 | 1243 | if (qTotal[adcch] != 0) |
1244 | AliDebug(10,Form("ch %2d qTotal %5d",adcch, qTotal[adcch])); | |
b0a41e80 | 1245 | } |
dfd03fc3 | 1246 | |
b0a41e80 | 1247 | fromLeft = -1; |
1248 | adcch = 0; | |
1249 | found = 0; | |
1250 | marked[4] = 19; // invalid channel | |
1251 | marked[5] = 19; // invalid channel | |
ab9f7002 | 1252 | qTotal[19] = 0; |
b0a41e80 | 1253 | while ((adcch < 16) && (found < 3)) |
1254 | { | |
ab9f7002 | 1255 | if (qTotal[adcch] > 0) |
b0a41e80 | 1256 | { |
1257 | fromLeft = adcch; | |
1258 | marked[2*found+1]=adcch; | |
1259 | found++; | |
1260 | } | |
1261 | adcch++; | |
1262 | } | |
dfd03fc3 | 1263 | |
b0a41e80 | 1264 | fromRight = -1; |
1265 | adcch = 18; | |
1266 | found = 0; | |
1267 | while ((adcch > 2) && (found < 3)) | |
1268 | { | |
ab9f7002 | 1269 | if (qTotal[adcch] > 0) |
b0a41e80 | 1270 | { |
1271 | marked[2*found]=adcch; | |
1272 | found++; | |
1273 | fromRight = adcch; | |
1274 | } | |
1275 | adcch--; | |
1276 | } | |
dfd03fc3 | 1277 | |
4ff7ed2b | 1278 | AliDebug(10,Form("Fromleft=%d, Fromright=%d",fromLeft, fromRight)); |
b0a41e80 | 1279 | // here mask the hit candidates in the middle, if any |
1280 | if ((fromLeft >= 0) && (fromRight >= 0) && (fromLeft < fromRight)) | |
1281 | for (adcch = fromLeft+1; adcch < fromRight; adcch++) | |
ab9f7002 | 1282 | qTotal[adcch] = 0; |
dfd03fc3 | 1283 | |
b0a41e80 | 1284 | found = 0; |
1285 | for (adcch = 0; adcch < 19; adcch++) | |
ab9f7002 | 1286 | if (qTotal[adcch] > 0) found++; |
b0a41e80 | 1287 | // NOT READY |
1288 | ||
1289 | if (found > 4) // sorting like in the TRAP in case of 5 or 6 candidates! | |
1290 | { | |
1291 | if (marked[4] == marked[5]) marked[5] = 19; | |
1292 | for (found=0; found<6; found++) | |
1293 | { | |
ab9f7002 | 1294 | qMarked[found] = qTotal[marked[found]] >> 4; |
4ff7ed2b | 1295 | AliDebug(10,Form("ch_%d qTotal %d qTotals %d",marked[found],qTotal[marked[found]],qMarked[found])); |
b0a41e80 | 1296 | } |
dfd03fc3 | 1297 | |
b0a41e80 | 1298 | Sort6To2Worst(marked[0], marked[3], marked[4], marked[1], marked[2], marked[5], |
ab9f7002 | 1299 | qMarked[0], |
1300 | qMarked[3], | |
1301 | qMarked[4], | |
1302 | qMarked[1], | |
1303 | qMarked[2], | |
1304 | qMarked[5], | |
b0a41e80 | 1305 | &worse1, &worse2); |
1306 | // Now mask the two channels with the smallest charge | |
1307 | if (worse1 < 19) | |
1308 | { | |
ab9f7002 | 1309 | qTotal[worse1] = 0; |
4ff7ed2b | 1310 | AliDebug(10,Form("Kill ch %d\n",worse1)); |
b0a41e80 | 1311 | } |
1312 | if (worse2 < 19) | |
1313 | { | |
ab9f7002 | 1314 | qTotal[worse2] = 0; |
4ff7ed2b | 1315 | AliDebug(10,Form("Kill ch %d\n",worse2)); |
b0a41e80 | 1316 | } |
1317 | } | |
1318 | ||
1319 | for (adcch = 0; adcch < 19; adcch++) { | |
ab9f7002 | 1320 | if (qTotal[adcch] > 0) // the channel is marked for processing |
b0a41e80 | 1321 | { |
ab9f7002 | 1322 | adcLeft = fADCF[adcch ][timebin]; |
1323 | adcCentral = fADCF[adcch+1][timebin]; | |
1324 | adcRight = fADCF[adcch+2][timebin]; | |
b0a41e80 | 1325 | // hit detected, in TRAP we have 4 units and a hit-selection, here we proceed all channels! |
1326 | // subtract the pedestal TPFP, clipping instead of wrapping | |
1327 | ||
ab9f7002 | 1328 | Int_t regTPFP = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP); |
4ff7ed2b | 1329 | AliDebug(10, Form("Hit found, time=%d, adcch=%d/%d/%d, adc values=%d/%d/%d, regTPFP=%d, TPHT=%d\n", |
1330 | timebin, adcch, adcch+1, adcch+2, adcLeft, adcCentral, adcRight, regTPFP, | |
1331 | fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPHT))); | |
b0a41e80 | 1332 | |
ab9f7002 | 1333 | if (adcLeft < regTPFP) adcLeft = 0; else adcLeft -= regTPFP; |
1334 | if (adcCentral < regTPFP) adcCentral = 0; else adcCentral -= regTPFP; | |
1335 | if (adcRight < regTPFP) adcRight = 0; else adcRight -= regTPFP; | |
f793c83d | 1336 | |
b0a41e80 | 1337 | // Calculate the center of gravity |
f793c83d | 1338 | // checking for adcCentral != 0 (in case of "bad" configuration) |
1339 | if (adcCentral == 0) | |
1340 | continue; | |
ab9f7002 | 1341 | ypos = 128*(adcLeft - adcRight) / adcCentral; |
b0a41e80 | 1342 | if (ypos < 0) ypos = -ypos; |
ce4786b9 | 1343 | // make the correction using the position LUT |
1344 | ypos = ypos + fTrapConfig->GetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + (ypos & 0x7F))); | |
ab9f7002 | 1345 | if (adcLeft > adcRight) ypos = -ypos; |
40bd6ee4 | 1346 | |
1347 | // label calculation | |
1348 | Int_t mcLabel = -1; | |
1349 | if (fDigitsManager) { | |
1350 | Int_t label[9] = { 0 }; // up to 9 different labels possible | |
1351 | Int_t count[9] = { 0 }; | |
1352 | Int_t maxIdx = -1; | |
1353 | Int_t maxCount = 0; | |
1354 | Int_t nLabels = 0; | |
1355 | Int_t padcol[3]; | |
1356 | padcol[0] = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adcch); | |
1357 | padcol[1] = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adcch+1); | |
1358 | padcol[2] = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adcch+2); | |
1359 | Int_t padrow = fFeeParam->GetPadRowFromMCM(fRobPos, fMcmPos); | |
1360 | for (Int_t iDict = 0; iDict < 3; iDict++) { | |
ce4786b9 | 1361 | if (!fDict[iDict]) |
40bd6ee4 | 1362 | continue; |
40bd6ee4 | 1363 | for (Int_t iPad = 0; iPad < 3; iPad++) { |
1364 | if (padcol[iPad] < 0) | |
1365 | continue; | |
ce4786b9 | 1366 | Int_t currLabel = fDict[iDict]->GetData(padrow, padcol[iPad], timebin); //fDigitsManager->GetTrack(iDict, padrow, padcol, timebin, fDetector); |
4ff7ed2b | 1367 | AliDebug(10, Form("Read label: %4i for det: %3i, row: %i, col: %i, tb: %i\n", currLabel, fDetector, padrow, padcol[iPad], timebin)); |
40bd6ee4 | 1368 | for (Int_t iLabel = 0; iLabel < nLabels; iLabel++) { |
1369 | if (currLabel == label[iLabel]) { | |
1370 | count[iLabel]++; | |
1371 | if (count[iLabel] > maxCount) { | |
1372 | maxCount = count[iLabel]; | |
1373 | maxIdx = iLabel; | |
1374 | } | |
ce51199c | 1375 | currLabel = -1; |
40bd6ee4 | 1376 | break; |
1377 | } | |
1378 | } | |
ce51199c | 1379 | if (currLabel >= 0) { |
40bd6ee4 | 1380 | label[nLabels++] = currLabel; |
1381 | } | |
1382 | } | |
1383 | } | |
1384 | if (maxIdx >= 0) | |
1385 | mcLabel = label[maxIdx]; | |
1386 | } | |
1387 | ||
1388 | // add the hit to the fitregister | |
1389 | AddHitToFitreg(adcch, timebin, qTotal[adcch], ypos, mcLabel); | |
b0a41e80 | 1390 | } |
dfd03fc3 | 1391 | } |
1392 | } | |
ce4786b9 | 1393 | |
1394 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { | |
1395 | if (fFitReg[iAdc].fNhits != 0) { | |
1396 | AliDebug(2, Form("fitreg[%i]: nHits = %i, sumX = %i, sumY = %i, sumX2 = %i, sumY2 = %i, sumXY = %i", iAdc, | |
1397 | fFitReg[iAdc].fNhits, | |
1398 | fFitReg[iAdc].fSumX, | |
1399 | fFitReg[iAdc].fSumY, | |
1400 | fFitReg[iAdc].fSumX2, | |
1401 | fFitReg[iAdc].fSumY2, | |
1402 | fFitReg[iAdc].fSumXY | |
1403 | )); | |
1404 | } | |
1405 | } | |
dfd03fc3 | 1406 | } |
1407 | ||
b0a41e80 | 1408 | void AliTRDmcmSim::TrackletSelection() |
dfd03fc3 | 1409 | { |
b0a41e80 | 1410 | // Select up to 4 tracklet candidates from the fit registers |
1411 | // and assign them to the CPUs. | |
1412 | ||
ab9f7002 | 1413 | UShort_t adcIdx, i, j, ntracks, tmp; |
1414 | UShort_t trackletCand[18][2]; // store the adcch[0] and number of hits[1] for all tracklet candidates | |
b0a41e80 | 1415 | |
1416 | ntracks = 0; | |
ab9f7002 | 1417 | for (adcIdx = 0; adcIdx < 18; adcIdx++) // ADCs |
1418 | if ( (fFitReg[adcIdx].fNhits | |
b0a41e80 | 1419 | >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPCL)) && |
ab9f7002 | 1420 | (fFitReg[adcIdx].fNhits+fFitReg[adcIdx+1].fNhits |
b0a41e80 | 1421 | >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPCT))) |
1422 | { | |
ab9f7002 | 1423 | trackletCand[ntracks][0] = adcIdx; |
1424 | trackletCand[ntracks][1] = fFitReg[adcIdx].fNhits+fFitReg[adcIdx+1].fNhits; | |
4ff7ed2b | 1425 | AliDebug(10,Form("%d %2d %4d\n", ntracks, trackletCand[ntracks][0], trackletCand[ntracks][1])); |
b0a41e80 | 1426 | ntracks++; |
1427 | }; | |
1428 | ||
4ff7ed2b | 1429 | for (i=0; i<ntracks;i++) |
1430 | AliDebug(10,Form("%d %d %d\n",i,trackletCand[i][0], trackletCand[i][1])); | |
b0a41e80 | 1431 | |
1432 | if (ntracks > 4) | |
1433 | { | |
1434 | // primitive sorting according to the number of hits | |
1435 | for (j = 0; j < (ntracks-1); j++) | |
1436 | { | |
1437 | for (i = j+1; i < ntracks; i++) | |
1438 | { | |
ab9f7002 | 1439 | if ( (trackletCand[j][1] < trackletCand[i][1]) || |
1440 | ( (trackletCand[j][1] == trackletCand[i][1]) && (trackletCand[j][0] < trackletCand[i][0]) ) ) | |
b0a41e80 | 1441 | { |
1442 | // swap j & i | |
ab9f7002 | 1443 | tmp = trackletCand[j][1]; |
1444 | trackletCand[j][1] = trackletCand[i][1]; | |
1445 | trackletCand[i][1] = tmp; | |
1446 | tmp = trackletCand[j][0]; | |
1447 | trackletCand[j][0] = trackletCand[i][0]; | |
1448 | trackletCand[i][0] = tmp; | |
b0a41e80 | 1449 | } |
1450 | } | |
1451 | } | |
1452 | ntracks = 4; // cut the rest, 4 is the max | |
dfd03fc3 | 1453 | } |
b0a41e80 | 1454 | // else is not necessary to sort |
dfd03fc3 | 1455 | |
b0a41e80 | 1456 | // now sort, so that the first tracklet going to CPU0 corresponds to the highest adc channel - as in the TRAP |
1457 | for (j = 0; j < (ntracks-1); j++) | |
1458 | { | |
1459 | for (i = j+1; i < ntracks; i++) | |
1460 | { | |
ab9f7002 | 1461 | if (trackletCand[j][0] < trackletCand[i][0]) |
b0a41e80 | 1462 | { |
1463 | // swap j & i | |
ab9f7002 | 1464 | tmp = trackletCand[j][1]; |
1465 | trackletCand[j][1] = trackletCand[i][1]; | |
1466 | trackletCand[i][1] = tmp; | |
1467 | tmp = trackletCand[j][0]; | |
1468 | trackletCand[j][0] = trackletCand[i][0]; | |
1469 | trackletCand[i][0] = tmp; | |
b0a41e80 | 1470 | } |
dfd03fc3 | 1471 | } |
b0a41e80 | 1472 | } |
1473 | for (i = 0; i < ntracks; i++) // CPUs with tracklets. | |
ab9f7002 | 1474 | fFitPtr[i] = trackletCand[i][0]; // pointer to the left channel with tracklet for CPU[i] |
b0a41e80 | 1475 | for (i = ntracks; i < 4; i++) // CPUs without tracklets |
1476 | fFitPtr[i] = 31; // pointer to the left channel with tracklet for CPU[i] = 31 (invalid) | |
4ff7ed2b | 1477 | AliDebug(10,Form("found %i tracklet candidates\n", ntracks)); |
1478 | for (i = 0; i < 4; i++) | |
1479 | AliDebug(10,Form("fitPtr[%i]: %i\n", i, fFitPtr[i])); | |
b0a41e80 | 1480 | } |
dfd03fc3 | 1481 | |
b0a41e80 | 1482 | void AliTRDmcmSim::FitTracklet() |
1483 | { | |
1484 | // Perform the actual tracklet fit based on the fit sums | |
1485 | // which have been filled in the fit registers. | |
1486 | ||
1487 | // parameters in fitred.asm (fit program) | |
1488 | Int_t decPlaces = 5; | |
1489 | Int_t rndAdd = 0; | |
1490 | if (decPlaces > 1) | |
1491 | rndAdd = (1 << (decPlaces-1)) + 1; | |
1492 | else if (decPlaces == 1) | |
1493 | rndAdd = 1; | |
4ff7ed2b | 1494 | Int_t ndriftDp = 5; // decimal places for drift time |
1495 | Long64_t shift = ((Long64_t) 1 << 32); | |
1496 | ||
4ff7ed2b | 1497 | // calculated in fitred.asm |
1498 | Int_t padrow = ((fRobPos >> 1) << 2) | (fMcmPos >> 2); | |
1499 | Int_t yoffs = (((((fRobPos & 0x1) << 2) + (fMcmPos & 0x3)) * 18) << 8) - | |
1500 | ((18*4*2 - 18*2 - 1) << 7); | |
1501 | yoffs = yoffs << decPlaces; // holds position of ADC channel 1 | |
1502 | Int_t layer = fDetector % 6; | |
1503 | UInt_t scaleY = (UInt_t) ((0.635 + 0.03 * layer)/(256.0 * 160.0e-4) * shift); | |
1504 | UInt_t scaleD = (UInt_t) ((0.635 + 0.03 * layer)/(256.0 * 140.0e-4) * shift); | |
4ff7ed2b | 1505 | |
ce4786b9 | 1506 | Int_t deflCorr = fTrapConfig->GetDmem(0xc022, fDetector, fRobPos, fMcmPos); |
1507 | Int_t ndrift = fTrapConfig->GetDmem(0xc025, fDetector, fRobPos, fMcmPos); | |
b0a41e80 | 1508 | |
1509 | // local variables for calculation | |
1510 | Long64_t mult, temp, denom; //??? | |
1511 | UInt_t q0, q1, qTotal; // charges in the two windows and total charge | |
1512 | UShort_t nHits; // number of hits | |
1513 | Int_t slope, offset; // slope and offset of the tracklet | |
1514 | Int_t sumX, sumY, sumXY, sumX2; // fit sums from fit registers | |
ce51199c | 1515 | Int_t sumY2; // not used in the current TRAP program, now used for error calculation (simulation only) |
1516 | Float_t fitError, fitSlope, fitOffset; | |
b0a41e80 | 1517 | FitReg_t *fit0, *fit1; // pointers to relevant fit registers |
1518 | ||
1519 | // const uint32_t OneDivN[32] = { // 2**31/N : exactly like in the TRAP, the simple division here gives the same result! | |
1520 | // 0x00000000, 0x80000000, 0x40000000, 0x2AAAAAA0, 0x20000000, 0x19999990, 0x15555550, 0x12492490, | |
1521 | // 0x10000000, 0x0E38E380, 0x0CCCCCC0, 0x0BA2E8B0, 0x0AAAAAA0, 0x09D89D80, 0x09249240, 0x08888880, | |
1522 | // 0x08000000, 0x07878780, 0x071C71C0, 0x06BCA1A0, 0x06666660, 0x06186180, 0x05D17450, 0x0590B210, | |
1523 | // 0x05555550, 0x051EB850, 0x04EC4EC0, 0x04BDA120, 0x04924920, 0x0469EE50, 0x04444440, 0x04210840}; | |
1524 | ||
1525 | for (Int_t cpu = 0; cpu < 4; cpu++) { | |
1526 | if (fFitPtr[cpu] == 31) | |
1527 | { | |
1528 | fMCMT[cpu] = 0x10001000; //??? AliTRDfeeParam::GetTrackletEndmarker(); | |
dfd03fc3 | 1529 | } |
b0a41e80 | 1530 | else |
1531 | { | |
1532 | fit0 = &fFitReg[fFitPtr[cpu] ]; | |
1533 | fit1 = &fFitReg[fFitPtr[cpu]+1]; // next channel | |
1534 | ||
1535 | mult = 1; | |
1536 | mult = mult << (32 + decPlaces); | |
1537 | mult = -mult; | |
1538 | ||
1539 | // Merging | |
ab9f7002 | 1540 | nHits = fit0->fNhits + fit1->fNhits; // number of hits |
1541 | sumX = fit0->fSumX + fit1->fSumX; | |
1542 | sumX2 = fit0->fSumX2 + fit1->fSumX2; | |
b0a41e80 | 1543 | denom = nHits*sumX2 - sumX*sumX; |
1544 | ||
1545 | mult = mult / denom; // exactly like in the TRAP program | |
ab9f7002 | 1546 | q0 = fit0->fQ0 + fit1->fQ0; |
1547 | q1 = fit0->fQ1 + fit1->fQ1; | |
1548 | sumY = fit0->fSumY + fit1->fSumY + 256*fit1->fNhits; | |
1549 | sumXY = fit0->fSumXY + fit1->fSumXY + 256*fit1->fSumX; | |
ce51199c | 1550 | sumY2 = fit0->fSumY2 + fit1->fSumY2 + 512*fit1->fSumY + 256*256*fit1->fNhits; |
b0a41e80 | 1551 | |
1552 | slope = nHits*sumXY - sumX * sumY; | |
1553 | offset = sumX2*sumY - sumX * sumXY; | |
1554 | temp = mult * slope; | |
1555 | slope = temp >> 32; // take the upper 32 bits | |
4ff7ed2b | 1556 | slope = -slope; |
b0a41e80 | 1557 | temp = mult * offset; |
1558 | offset = temp >> 32; // take the upper 32 bits | |
1559 | ||
4ff7ed2b | 1560 | offset = offset + yoffs; |
ce4786b9 | 1561 | AliDebug(10, Form("slope = %i, slope * ndrift = %i, deflCorr: %i", |
1562 | slope, slope * ndrift, deflCorr)); | |
1563 | slope = ((slope * ndrift) >> ndriftDp) + deflCorr; | |
b0a41e80 | 1564 | offset = offset - (fFitPtr[cpu] << (8 + decPlaces)); |
1565 | ||
4ff7ed2b | 1566 | temp = slope; |
1567 | temp = temp * scaleD; | |
1568 | slope = (temp >> 32); | |
4ff7ed2b | 1569 | temp = offset; |
1570 | temp = temp * scaleY; | |
1571 | offset = (temp >> 32); | |
1572 | ||
1573 | // rounding, like in the TRAP | |
1574 | slope = (slope + rndAdd) >> decPlaces; | |
4ff7ed2b | 1575 | offset = (offset + rndAdd) >> decPlaces; |
1576 | ||
ce4786b9 | 1577 | AliDebug(5, Form("Det: %3i, ROB: %i, MCM: %2i: deflection: %i, min: %i, max: %i", |
1578 | fDetector, fRobPos, fMcmPos, slope, | |
1579 | fTrapConfig->GetDmem(0xc030 + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos), | |
1580 | fTrapConfig->GetDmem(0xc031 + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos))); | |
1581 | ||
ce51199c | 1582 | AliDebug(5, Form("Fit sums: x = %i, X = %i, y = %i, Y = %i, Z = %i", |
1583 | sumX, sumX2, sumY, sumY2, sumXY)); | |
1584 | ||
1585 | fitSlope = (Float_t) (nHits * sumXY - sumX * sumY) / (nHits * sumX2 - sumX*sumX); | |
1586 | ||
1587 | fitOffset = (Float_t) (sumX2 * sumY - sumX * sumXY) / (nHits * sumX2 - sumX*sumX); | |
1588 | ||
1589 | Float_t sx = (Float_t) sumX; | |
1590 | Float_t sx2 = (Float_t) sumX2; | |
1591 | Float_t sy = (Float_t) sumY; | |
1592 | Float_t sy2 = (Float_t) sumY2; | |
1593 | Float_t sxy = (Float_t) sumXY; | |
1594 | fitError = sy2 - (sx2 * sy*sy - 2 * sx * sxy * sy + nHits * sxy*sxy) / (nHits * sx2 - sx*sx); | |
1595 | //fitError = (Float_t) sumY2 - (Float_t) (sumY*sumY) / nHits - fitSlope * ((Float_t) (sumXY - sumX*sumY) / nHits); | |
1596 | ||
40bd6ee4 | 1597 | Bool_t rejected = kFALSE; |
ce4786b9 | 1598 | // deflection range table from DMEM |
1599 | if ((slope < fTrapConfig->GetDmem(0xc030 + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos)) || | |
1600 | (slope > fTrapConfig->GetDmem(0xc031 + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos))) | |
40bd6ee4 | 1601 | rejected = kTRUE; |
4ff7ed2b | 1602 | |
1603 | if (rejected && GetApplyCut()) | |
b0a41e80 | 1604 | { |
1605 | fMCMT[cpu] = 0x10001000; //??? AliTRDfeeParam::GetTrackletEndmarker(); | |
1606 | } | |
1607 | else | |
1608 | { | |
4ff7ed2b | 1609 | if (slope > 63 || slope < -64) { // wrapping in TRAP! |
40bd6ee4 | 1610 | AliError(Form("Overflow in slope: %i, tracklet discarded!", slope)); |
1611 | fMCMT[cpu] = 0x10001000; | |
1612 | continue; | |
1613 | } | |
b0a41e80 | 1614 | |
4ff7ed2b | 1615 | slope = slope & 0x7F; // 7 bit |
1616 | ||
40bd6ee4 | 1617 | if (offset > 0xfff || offset < -0xfff) |
b0a41e80 | 1618 | AliWarning("Overflow in offset"); |
1619 | offset = offset & 0x1FFF; // 13 bit | |
1620 | ||
ce4786b9 | 1621 | qTotal = 0; // set to zero as long as no reasonable PID calculation is available |
1622 | // before: GetPID(q0/length/fgChargeNorm, q1/length/fgChargeNorm); | |
4ff7ed2b | 1623 | |
b0a41e80 | 1624 | if (qTotal > 0xff) |
1625 | AliWarning("Overflow in charge"); | |
1626 | qTotal = qTotal & 0xFF; // 8 bit, exactly like in the TRAP program | |
4ff7ed2b | 1627 | |
b0a41e80 | 1628 | // assemble and store the tracklet word |
1629 | fMCMT[cpu] = (qTotal << 24) | (padrow << 20) | (slope << 13) | offset; | |
40bd6ee4 | 1630 | |
1631 | // calculate MC label | |
1632 | Int_t mcLabel = -1; | |
4ff7ed2b | 1633 | Int_t nHits0 = 0; |
1634 | Int_t nHits1 = 0; | |
40bd6ee4 | 1635 | if (fDigitsManager) { |
1636 | Int_t label[30] = {0}; // up to 30 different labels possible | |
1637 | Int_t count[30] = {0}; | |
1638 | Int_t maxIdx = -1; | |
1639 | Int_t maxCount = 0; | |
1640 | Int_t nLabels = 0; | |
1641 | for (Int_t iHit = 0; iHit < fNHits; iHit++) { | |
1642 | if ((fHits[iHit].fChannel - fFitPtr[cpu] < 0) || | |
1643 | (fHits[iHit].fChannel - fFitPtr[cpu] > 1)) | |
1644 | continue; | |
4ff7ed2b | 1645 | |
1646 | // counting contributing hits | |
1647 | if (fHits[iHit].fTimebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0) && | |
1648 | fHits[iHit].fTimebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE0)) | |
1649 | nHits0++; | |
1650 | if (fHits[iHit].fTimebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS1) && | |
1651 | fHits[iHit].fTimebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1)) | |
1652 | nHits1++; | |
1653 | ||
40bd6ee4 | 1654 | Int_t currLabel = fHits[iHit].fLabel; |
1655 | for (Int_t iLabel = 0; iLabel < nLabels; iLabel++) { | |
1656 | if (currLabel == label[iLabel]) { | |
1657 | count[iLabel]++; | |
1658 | if (count[iLabel] > maxCount) { | |
1659 | maxCount = count[iLabel]; | |
1660 | maxIdx = iLabel; | |
1661 | } | |
ce51199c | 1662 | currLabel = -1; |
40bd6ee4 | 1663 | break; |
1664 | } | |
1665 | } | |
ce51199c | 1666 | if (currLabel >= 0) { |
40bd6ee4 | 1667 | label[nLabels++] = currLabel; |
1668 | } | |
1669 | } | |
1670 | if (maxIdx >= 0) | |
1671 | mcLabel = label[maxIdx]; | |
1672 | } | |
f793c83d | 1673 | new ((*fTrackletArray)[fTrackletArray->GetEntriesFast()]) AliTRDtrackletMCM((UInt_t) fMCMT[cpu], fDetector*2 + fRobPos%2, fRobPos, fMcmPos); |
40bd6ee4 | 1674 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetLabel(mcLabel); |
4ff7ed2b | 1675 | |
1676 | ||
1677 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetNHits(fit0->fNhits + fit1->fNhits); | |
1678 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetNHits0(nHits0); | |
1679 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetNHits1(nHits1); | |
48e5462a | 1680 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetQ0(q0); |
1681 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetQ1(q1); | |
ce51199c | 1682 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetSlope(fitSlope); |
1683 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetOffset(fitOffset); | |
1684 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetError(TMath::Sqrt(TMath::Abs(fitError)/nHits)); | |
1685 | ||
1686 | // // cluster information | |
1687 | // Float_t *res = new Float_t[nHits]; | |
1688 | // Float_t *qtot = new Float_t[nHits]; | |
1689 | // Int_t nCls = 0; | |
1690 | // for (Int_t iHit = 0; iHit < fNHits; iHit++) { | |
1691 | // // check if hit contributes | |
1692 | // if (fHits[iHit].fChannel == fFitPtr[cpu]) { | |
1693 | // res[nCls] = fHits[iHit].fYpos - (fitSlope * fHits[iHit].fTimebin + fitOffset); | |
1694 | // qtot[nCls] = fHits[iHit].fQtot; | |
1695 | // nCls++; | |
1696 | // } | |
1697 | // else if (fHits[iHit].fChannel == fFitPtr[cpu] + 1) { | |
1698 | // res[nCls] = fHits[iHit].fYpos + 256 - (fitSlope * fHits[iHit].fTimebin + fitOffset); | |
1699 | // qtot[nCls] = fHits[iHit].fQtot; | |
1700 | // nCls++; | |
1701 | // } | |
1702 | // } | |
1703 | // ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetClusters(res, qtot, nCls); | |
1704 | // delete [] res; | |
1705 | // delete [] qtot; | |
1706 | ||
1707 | if (fitError < 0) | |
1708 | AliError(Form("Strange fit error: %f from Sx: %i, Sy: %i, Sxy: %i, Sx2: %i, Sy2: %i, nHits: %i", | |
1709 | fitError, sumX, sumY, sumXY, sumX2, sumY2, nHits)); | |
1710 | AliDebug(3, Form("fit slope: %f, offset: %f, error: %f", | |
1711 | fitSlope, fitOffset, TMath::Sqrt(TMath::Abs(fitError)/nHits))); | |
b0a41e80 | 1712 | } |
dfd03fc3 | 1713 | } |
dfd03fc3 | 1714 | } |
1715 | } | |
1716 | ||
b0a41e80 | 1717 | void AliTRDmcmSim::Tracklet() |
dfd03fc3 | 1718 | { |
ab9f7002 | 1719 | // Run the tracklet calculation by calling sequentially: |
1720 | // CalcFitreg(); TrackletSelection(); FitTracklet() | |
1721 | // and store the tracklets | |
1722 | ||
b0a41e80 | 1723 | if (!fInitialized) { |
ab9f7002 | 1724 | AliError("Called uninitialized! Nothing done!"); |
b0a41e80 | 1725 | return; |
dfd03fc3 | 1726 | } |
1727 | ||
b0a41e80 | 1728 | fTrackletArray->Delete(); |
dfd03fc3 | 1729 | |
b0a41e80 | 1730 | CalcFitreg(); |
40bd6ee4 | 1731 | if (fNHits == 0) |
1732 | return; | |
b0a41e80 | 1733 | TrackletSelection(); |
1734 | FitTracklet(); | |
c8b1590d | 1735 | } |
1736 | ||
1737 | Bool_t AliTRDmcmSim::StoreTracklets() | |
1738 | { | |
36dc3337 | 1739 | // store the found tracklets via the loader |
1740 | ||
40bd6ee4 | 1741 | if (fTrackletArray->GetEntriesFast() == 0) |
c8b1590d | 1742 | return kTRUE; |
dfd03fc3 | 1743 | |
b0a41e80 | 1744 | AliRunLoader *rl = AliRunLoader::Instance(); |
1745 | AliDataLoader *dl = 0x0; | |
1746 | if (rl) | |
1747 | dl = rl->GetLoader("TRDLoader")->GetDataLoader("tracklets"); | |
1748 | if (!dl) { | |
1749 | AliError("Could not get the tracklets data loader!"); | |
c8b1590d | 1750 | return kFALSE; |
dfd03fc3 | 1751 | } |
b0a41e80 | 1752 | |
c8b1590d | 1753 | TTree *trackletTree = dl->Tree(); |
1754 | if (!trackletTree) { | |
1755 | dl->MakeTree(); | |
1756 | trackletTree = dl->Tree(); | |
1757 | } | |
1758 | ||
1759 | AliTRDtrackletMCM *trkl = 0x0; | |
1760 | TBranch *trkbranch = trackletTree->GetBranch("mcmtrklbranch"); | |
1761 | if (!trkbranch) | |
1762 | trkbranch = trackletTree->Branch("mcmtrklbranch", "AliTRDtrackletMCM", &trkl, 32000); | |
1763 | ||
1764 | for (Int_t iTracklet = 0; iTracklet < fTrackletArray->GetEntriesFast(); iTracklet++) { | |
1765 | trkl = ((AliTRDtrackletMCM*) (*fTrackletArray)[iTracklet]); | |
1766 | trkbranch->SetAddress(&trkl); | |
c8b1590d | 1767 | trkbranch->Fill(); |
b0a41e80 | 1768 | } |
c8b1590d | 1769 | |
1770 | return kTRUE; | |
dfd03fc3 | 1771 | } |
1772 | ||
b0a41e80 | 1773 | void AliTRDmcmSim::WriteData(AliTRDarrayADC *digits) |
dfd03fc3 | 1774 | { |
b0a41e80 | 1775 | // write back the processed data configured by EBSF |
1776 | // EBSF = 1: unfiltered data; EBSF = 0: filtered data | |
1777 | // zero-suppressed valued are written as -1 to digits | |
dfd03fc3 | 1778 | |
ce4786b9 | 1779 | if( !CheckInitialized() ) |
b0a41e80 | 1780 | return; |
dfd03fc3 | 1781 | |
ce4786b9 | 1782 | Int_t offset = (fMcmPos % 4 + 1) * 21 + (fRobPos % 2) * 84 - 1; |
dfd03fc3 | 1783 | |
b0a41e80 | 1784 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBSF) != 0) // store unfiltered data |
1785 | { | |
ce4786b9 | 1786 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { |
1787 | if (~fZSMap[iAdc] == 0) { | |
b0a41e80 | 1788 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
ce4786b9 | 1789 | digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, -1); |
b0a41e80 | 1790 | } |
1791 | } | |
ce51199c | 1792 | else if (iAdc < 2 || iAdc == 20) { |
1793 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
1794 | digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, (fADCR[iAdc][iTimeBin] >> fgkAddDigits) - fgAddBaseline); | |
1795 | } | |
1796 | } | |
b0a41e80 | 1797 | } |
1798 | } | |
1799 | else { | |
ce4786b9 | 1800 | for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) { |
1801 | if (~fZSMap[iAdc] != 0) { | |
b0a41e80 | 1802 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
ce4786b9 | 1803 | digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, (fADCF[iAdc][iTimeBin] >> fgkAddDigits) - fgAddBaseline); |
b0a41e80 | 1804 | } |
1805 | } | |
1806 | else { | |
1807 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
ce4786b9 | 1808 | digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, -1); |
b0a41e80 | 1809 | } |
1810 | } | |
1811 | } | |
dfd03fc3 | 1812 | } |
b0a41e80 | 1813 | } |
dfd03fc3 | 1814 | |
b0a41e80 | 1815 | // help functions, to be cleaned up |
1816 | ||
ab9f7002 | 1817 | UInt_t AliTRDmcmSim::AddUintClipping(UInt_t a, UInt_t b, UInt_t nbits) const |
b0a41e80 | 1818 | { |
1819 | // | |
1820 | // This function adds a and b (unsigned) and clips to | |
1821 | // the specified number of bits. | |
1822 | // | |
1823 | ||
1824 | UInt_t sum = a + b; | |
1825 | if (nbits < 32) | |
1826 | { | |
1827 | UInt_t maxv = (1 << nbits) - 1;; | |
1828 | if (sum > maxv) | |
1829 | sum = maxv; | |
1830 | } | |
1831 | else | |
1832 | { | |
1833 | if ((sum < a) || (sum < b)) | |
1834 | sum = 0xFFFFFFFF; | |
1835 | } | |
1836 | return sum; | |
dfd03fc3 | 1837 | } |
1838 | ||
982869bc | 1839 | void AliTRDmcmSim::Sort2(UShort_t idx1i, UShort_t idx2i, \ |
1840 | UShort_t val1i, UShort_t val2i, \ | |
1841 | UShort_t *idx1o, UShort_t *idx2o, \ | |
1842 | UShort_t *val1o, UShort_t *val2o) const | |
dfd03fc3 | 1843 | { |
ab9f7002 | 1844 | // sorting for tracklet selection |
dfd03fc3 | 1845 | |
b0a41e80 | 1846 | if (val1i > val2i) |
1847 | { | |
1848 | *idx1o = idx1i; | |
1849 | *idx2o = idx2i; | |
1850 | *val1o = val1i; | |
1851 | *val2o = val2i; | |
1852 | } | |
1853 | else | |
1854 | { | |
1855 | *idx1o = idx2i; | |
1856 | *idx2o = idx1i; | |
1857 | *val1o = val2i; | |
1858 | *val2o = val1i; | |
1859 | } | |
1860 | } | |
1861 | ||
982869bc | 1862 | void AliTRDmcmSim::Sort3(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, \ |
1863 | UShort_t val1i, UShort_t val2i, UShort_t val3i, \ | |
1864 | UShort_t *idx1o, UShort_t *idx2o, UShort_t *idx3o, \ | |
1865 | UShort_t *val1o, UShort_t *val2o, UShort_t *val3o) | |
b0a41e80 | 1866 | { |
ab9f7002 | 1867 | // sorting for tracklet selection |
1868 | ||
4ff7ed2b | 1869 | Int_t sel; |
dfd03fc3 | 1870 | |
dfd03fc3 | 1871 | |
b0a41e80 | 1872 | if (val1i > val2i) sel=4; else sel=0; |
1873 | if (val2i > val3i) sel=sel + 2; | |
1874 | if (val3i > val1i) sel=sel + 1; | |
b0a41e80 | 1875 | switch(sel) |
1876 | { | |
1877 | case 6 : // 1 > 2 > 3 => 1 2 3 | |
1878 | case 0 : // 1 = 2 = 3 => 1 2 3 : in this case doesn't matter, but so is in hardware! | |
1879 | *idx1o = idx1i; | |
1880 | *idx2o = idx2i; | |
1881 | *idx3o = idx3i; | |
1882 | *val1o = val1i; | |
1883 | *val2o = val2i; | |
1884 | *val3o = val3i; | |
1885 | break; | |
1886 | ||
1887 | case 4 : // 1 > 2, 2 <= 3, 3 <= 1 => 1 3 2 | |
1888 | *idx1o = idx1i; | |
1889 | *idx2o = idx3i; | |
1890 | *idx3o = idx2i; | |
1891 | *val1o = val1i; | |
1892 | *val2o = val3i; | |
1893 | *val3o = val2i; | |
1894 | break; | |
1895 | ||
1896 | case 2 : // 1 <= 2, 2 > 3, 3 <= 1 => 2 1 3 | |
1897 | *idx1o = idx2i; | |
1898 | *idx2o = idx1i; | |
1899 | *idx3o = idx3i; | |
1900 | *val1o = val2i; | |
1901 | *val2o = val1i; | |
1902 | *val3o = val3i; | |
1903 | break; | |
1904 | ||
1905 | case 3 : // 1 <= 2, 2 > 3, 3 > 1 => 2 3 1 | |
1906 | *idx1o = idx2i; | |
1907 | *idx2o = idx3i; | |
1908 | *idx3o = idx1i; | |
1909 | *val1o = val2i; | |
1910 | *val2o = val3i; | |
1911 | *val3o = val1i; | |
1912 | break; | |
1913 | ||
1914 | case 1 : // 1 <= 2, 2 <= 3, 3 > 1 => 3 2 1 | |
1915 | *idx1o = idx3i; | |
1916 | *idx2o = idx2i; | |
1917 | *idx3o = idx1i; | |
1918 | *val1o = val3i; | |
1919 | *val2o = val2i; | |
1920 | *val3o = val1i; | |
1921 | break; | |
1922 | ||
1923 | case 5 : // 1 > 2, 2 <= 3, 3 > 1 => 3 1 2 | |
1924 | *idx1o = idx3i; | |
1925 | *idx2o = idx1i; | |
1926 | *idx3o = idx2i; | |
1927 | *val1o = val3i; | |
1928 | *val2o = val1i; | |
1929 | *val3o = val2i; | |
1930 | break; | |
1931 | ||
1932 | default: // the rest should NEVER happen! | |
40bd6ee4 | 1933 | AliError("ERROR in Sort3!!!\n"); |
b0a41e80 | 1934 | break; |
1935 | } | |
b0a41e80 | 1936 | } |
dfd03fc3 | 1937 | |
982869bc | 1938 | void AliTRDmcmSim::Sort6To4(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, UShort_t idx4i, UShort_t idx5i, UShort_t idx6i, \ |
1939 | UShort_t val1i, UShort_t val2i, UShort_t val3i, UShort_t val4i, UShort_t val5i, UShort_t val6i, \ | |
1940 | UShort_t *idx1o, UShort_t *idx2o, UShort_t *idx3o, UShort_t *idx4o, \ | |
1941 | UShort_t *val1o, UShort_t *val2o, UShort_t *val3o, UShort_t *val4o) | |
b0a41e80 | 1942 | { |
ab9f7002 | 1943 | // sorting for tracklet selection |
dfd03fc3 | 1944 | |
982869bc | 1945 | UShort_t idx21s, idx22s, idx23s, dummy; |
1946 | UShort_t val21s, val22s, val23s; | |
1947 | UShort_t idx23as, idx23bs; | |
1948 | UShort_t val23as, val23bs; | |
dfd03fc3 | 1949 | |
b0a41e80 | 1950 | Sort3(idx1i, idx2i, idx3i, val1i, val2i, val3i, |
1951 | idx1o, &idx21s, &idx23as, | |
1952 | val1o, &val21s, &val23as); | |
dfd03fc3 | 1953 | |
b0a41e80 | 1954 | Sort3(idx4i, idx5i, idx6i, val4i, val5i, val6i, |
1955 | idx2o, &idx22s, &idx23bs, | |
1956 | val2o, &val22s, &val23bs); | |
1957 | ||
1958 | Sort2(idx23as, idx23bs, val23as, val23bs, &idx23s, &dummy, &val23s, &dummy); | |
1959 | ||
1960 | Sort3(idx21s, idx22s, idx23s, val21s, val22s, val23s, | |
1961 | idx3o, idx4o, &dummy, | |
1962 | val3o, val4o, &dummy); | |
dfd03fc3 | 1963 | |
dfd03fc3 | 1964 | } |
1965 | ||
982869bc | 1966 | void AliTRDmcmSim::Sort6To2Worst(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, UShort_t idx4i, UShort_t idx5i, UShort_t idx6i, \ |
1967 | UShort_t val1i, UShort_t val2i, UShort_t val3i, UShort_t val4i, UShort_t val5i, UShort_t val6i, \ | |
1968 | UShort_t *idx5o, UShort_t *idx6o) | |
b0a41e80 | 1969 | { |
ab9f7002 | 1970 | // sorting for tracklet selection |
1d93b218 | 1971 | |
982869bc | 1972 | UShort_t idx21s, idx22s, idx23s, dummy1, dummy2, dummy3, dummy4, dummy5; |
1973 | UShort_t val21s, val22s, val23s; | |
1974 | UShort_t idx23as, idx23bs; | |
1975 | UShort_t val23as, val23bs; | |
1d93b218 | 1976 | |
b0a41e80 | 1977 | Sort3(idx1i, idx2i, idx3i, val1i, val2i, val3i, |
1978 | &dummy1, &idx21s, &idx23as, | |
1979 | &dummy2, &val21s, &val23as); | |
1d93b218 | 1980 | |
b0a41e80 | 1981 | Sort3(idx4i, idx5i, idx6i, val4i, val5i, val6i, |
1982 | &dummy1, &idx22s, &idx23bs, | |
1983 | &dummy2, &val22s, &val23bs); | |
1d93b218 | 1984 | |
b0a41e80 | 1985 | Sort2(idx23as, idx23bs, val23as, val23bs, &idx23s, idx5o, &val23s, &dummy1); |
b65e5048 | 1986 | |
b0a41e80 | 1987 | Sort3(idx21s, idx22s, idx23s, val21s, val22s, val23s, |
1988 | &dummy1, &dummy2, idx6o, | |
1989 | &dummy3, &dummy4, &dummy5); | |
0d64b05f | 1990 | } |
f793c83d | 1991 | |
1992 | ||
ce4786b9 | 1993 | // ----- I/O implementation ----- |
1994 | ||
59f78ad5 | 1995 | ostream& AliTRDmcmSim::Text(ostream& os) |
ce4786b9 | 1996 | { |
1997 | // manipulator to activate output in text format (default) | |
1998 | ||
1999 | os.iword(fgkFormatIndex) = 0; | |
2000 | return os; | |
2001 | } | |
2002 | ||
59f78ad5 | 2003 | ostream& AliTRDmcmSim::Cfdat(ostream& os) |
ce4786b9 | 2004 | { |
2005 | // manipulator to activate output in CFDAT format | |
2006 | // to send to the FEE via SCSN | |
2007 | ||
2008 | os.iword(fgkFormatIndex) = 1; | |
2009 | return os; | |
2010 | } | |
2011 | ||
59f78ad5 | 2012 | ostream& AliTRDmcmSim::Raw(ostream& os) |
ce4786b9 | 2013 | { |
2014 | // manipulator to activate output as raw data dump | |
2015 | ||
2016 | os.iword(fgkFormatIndex) = 2; | |
2017 | return os; | |
2018 | } | |
2019 | ||
2020 | ostream& operator<<(ostream& os, const AliTRDmcmSim& mcm) | |
2021 | { | |
2022 | // output implementation | |
2023 | ||
2024 | // no output for non-initialized MCM | |
2025 | if (!mcm.CheckInitialized()) | |
2026 | return os; | |
2027 | ||
2028 | // ----- human-readable output ----- | |
2029 | if (os.iword(AliTRDmcmSim::fgkFormatIndex) == 0) { | |
2030 | ||
2031 | os << "MCM " << mcm.fMcmPos << " on ROB " << mcm.fRobPos << | |
2032 | " in detector " << mcm.fDetector << std::endl; | |
2033 | ||
2034 | os << "----- Unfiltered ADC data (10 bit) -----" << std::endl; | |
2035 | os << "ch "; | |
2036 | for (Int_t iChannel = 0; iChannel < mcm.fgkNADC; iChannel++) | |
2037 | os << std::setw(5) << iChannel; | |
2038 | os << std::endl; | |
2039 | for (Int_t iTimeBin = 0; iTimeBin < mcm.fNTimeBin; iTimeBin++) { | |
2040 | os << "tb " << std::setw(2) << iTimeBin << ":"; | |
2041 | for (Int_t iChannel = 0; iChannel < mcm.fgkNADC; iChannel++) { | |
2042 | os << std::setw(5) << (mcm.fADCR[iChannel][iTimeBin] >> mcm.fgkAddDigits); | |
2043 | } | |
2044 | os << std::endl; | |
2045 | } | |
2046 | ||
2047 | os << "----- Filtered ADC data (10+2 bit) -----" << std::endl; | |
2048 | os << "ch "; | |
2049 | for (Int_t iChannel = 0; iChannel < mcm.fgkNADC; iChannel++) | |
2050 | os << std::setw(4) << iChannel | |
2051 | << ((~mcm.fZSMap[iChannel] != 0) ? "!" : " "); | |
2052 | os << std::endl; | |
2053 | for (Int_t iTimeBin = 0; iTimeBin < mcm.fNTimeBin; iTimeBin++) { | |
2054 | os << "tb " << std::setw(2) << iTimeBin << ":"; | |
2055 | for (Int_t iChannel = 0; iChannel < mcm.fgkNADC; iChannel++) { | |
2056 | os << std::setw(4) << (mcm.fADCF[iChannel][iTimeBin]) | |
2057 | << (((mcm.fZSMap[iChannel] & (1 << iTimeBin)) == 0) ? "!" : " "); | |
2058 | } | |
2059 | os << std::endl; | |
2060 | } | |
2061 | } | |
2062 | ||
2063 | // ----- CFDAT output ----- | |
2064 | else if(os.iword(AliTRDmcmSim::fgkFormatIndex) == 1) { | |
2065 | Int_t dest = 127; | |
2066 | Int_t addrOffset = 0x2000; | |
2067 | Int_t addrStep = 0x80; | |
2068 | ||
2069 | for (Int_t iTimeBin = 0; iTimeBin < mcm.fNTimeBin; iTimeBin++) { | |
2070 | for (Int_t iChannel = 0; iChannel < mcm.fgkNADC; iChannel++) { | |
2071 | os << std::setw(5) << 10 | |
2072 | << std::setw(5) << addrOffset + iChannel * addrStep + iTimeBin | |
2073 | << std::setw(5) << (mcm.fADCF[iChannel][iTimeBin]) | |
2074 | << std::setw(5) << dest << std::endl; | |
2075 | } | |
2076 | os << std::endl; | |
2077 | } | |
2078 | } | |
2079 | ||
2080 | // ----- raw data ouptut ----- | |
2081 | else if (os.iword(AliTRDmcmSim::fgkFormatIndex) == 2) { | |
2082 | Int_t bufSize = 300; | |
2083 | UInt_t *buf = new UInt_t[bufSize]; | |
2084 | ||
2085 | Int_t bufLength = mcm.ProduceRawStream(&buf[0], bufSize); | |
2086 | ||
2087 | for (Int_t i = 0; i < bufLength; i++) | |
2088 | std::cout << "0x" << std::hex << buf[i] << std::endl; | |
2089 | ||
2090 | delete [] buf; | |
2091 | } | |
2092 | ||
2093 | else { | |
2094 | os << "unknown format set" << std::endl; | |
2095 | } | |
2096 | ||
2097 | return os; | |
2098 | } |