]>
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" |
c93255fe | 38 | #include <TTree.h> |
0c349049 | 39 | |
dfd03fc3 | 40 | #include "AliLog.h" |
b0a41e80 | 41 | #include "AliRunLoader.h" |
42 | #include "AliLoader.h" | |
0c349049 | 43 | |
dfd03fc3 | 44 | #include "AliTRDfeeParam.h" |
1b1afdd3 | 45 | #include "AliTRDcalibDB.h" |
b0a41e80 | 46 | #include "AliTRDtrapConfig.h" |
4cc89512 | 47 | #include "AliTRDdigitsManager.h" |
b65e5048 | 48 | #include "AliTRDarrayADC.h" |
40bd6ee4 | 49 | #include "AliTRDarrayDictionary.h" |
52c19022 | 50 | #include "AliTRDtrackletMCM.h" |
b0a41e80 | 51 | #include "AliTRDmcmSim.h" |
1d93b218 | 52 | |
dfd03fc3 | 53 | ClassImp(AliTRDmcmSim) |
54 | ||
40bd6ee4 | 55 | Bool_t AliTRDmcmSim::fgApplyCut = kTRUE; |
ce4786b9 | 56 | Int_t AliTRDmcmSim::fgAddBaseline = 0; |
dc1f2681 | 57 | Bool_t AliTRDmcmSim::fgStoreClusters = kFALSE; |
ce4786b9 | 58 | |
5f006bd7 | 59 | const Int_t AliTRDmcmSim::fgkFormatIndex = std::ios_base::xalloc(); |
ce4786b9 | 60 | |
5f006bd7 | 61 | const UShort_t AliTRDmcmSim::fgkFPshifts[4] = {11, 14, 17, 21}; |
ce4786b9 | 62 | |
63 | ||
5f006bd7 | 64 | AliTRDmcmSim::AliTRDmcmSim() : |
ce4786b9 | 65 | TObject(), |
66 | fInitialized(kFALSE), | |
67 | fDetector(-1), | |
68 | fRobPos(-1), | |
69 | fMcmPos(-1), | |
70 | fRow (-1), | |
71 | fNTimeBin(-1), | |
72 | fADCR(NULL), | |
73 | fADCF(NULL), | |
74 | fMCMT(NULL), | |
75 | fTrackletArray(NULL), | |
76 | fZSMap(NULL), | |
6b094867 | 77 | fTrklBranchName("mcmtrklbranch"), |
ce4786b9 | 78 | fFeeParam(NULL), |
79 | fTrapConfig(NULL), | |
80 | fDigitsManager(NULL), | |
81 | fPedAcc(NULL), | |
82 | fGainCounterA(NULL), | |
83 | fGainCounterB(NULL), | |
84 | fTailAmplLong(NULL), | |
85 | fTailAmplShort(NULL), | |
86 | fNHits(0), | |
87 | fFitReg(NULL) | |
dfd03fc3 | 88 | { |
89 | // | |
b0a41e80 | 90 | // AliTRDmcmSim default constructor |
dfd03fc3 | 91 | // By default, nothing is initialized. |
92 | // It is necessary to issue Init before use. | |
54d34aac | 93 | |
94 | for (Int_t iDict = 0; iDict < 3; iDict++) | |
95 | fDict[iDict] = 0x0; | |
96 | ||
97 | fFitPtr[0] = 0; | |
98 | fFitPtr[1] = 0; | |
99 | fFitPtr[2] = 0; | |
100 | fFitPtr[3] = 0; | |
dfd03fc3 | 101 | } |
102 | ||
5f006bd7 | 103 | AliTRDmcmSim::~AliTRDmcmSim() |
dfd03fc3 | 104 | { |
105 | // | |
106 | // AliTRDmcmSim destructor | |
107 | // | |
0c349049 | 108 | |
b0a41e80 | 109 | if(fInitialized) { |
6170d369 | 110 | for( Int_t iAdc = 0 ; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++ ) { |
ce4786b9 | 111 | delete [] fADCR[iAdc]; |
112 | delete [] fADCF[iAdc]; | |
dfd03fc3 | 113 | } |
16e077d0 | 114 | delete [] fADCR; |
115 | delete [] fADCF; | |
ce4786b9 | 116 | delete [] fZSMap; |
1d93b218 | 117 | delete [] fMCMT; |
5f006bd7 | 118 | |
b0a41e80 | 119 | delete [] fPedAcc; |
120 | delete [] fGainCounterA; | |
121 | delete [] fGainCounterB; | |
122 | delete [] fTailAmplLong; | |
123 | delete [] fTailAmplShort; | |
124 | delete [] fFitReg; | |
5f006bd7 | 125 | |
b0a41e80 | 126 | fTrackletArray->Delete(); |
127 | delete fTrackletArray; | |
1d93b218 | 128 | } |
dfd03fc3 | 129 | } |
130 | ||
5f006bd7 | 131 | void AliTRDmcmSim::Init( Int_t det, Int_t robPos, Int_t mcmPos, Bool_t /* newEvent */ ) |
dfd03fc3 | 132 | { |
0c349049 | 133 | // |
ce4786b9 | 134 | // Initialize the class with new MCM position information |
135 | // memory is allocated in the first initialization | |
0c349049 | 136 | // |
5f006bd7 | 137 | |
b0a41e80 | 138 | if (!fInitialized) { |
139 | fFeeParam = AliTRDfeeParam::Instance(); | |
1b1afdd3 | 140 | fTrapConfig = AliTRDcalibDB::Instance()->GetTrapConfig(); |
b0a41e80 | 141 | } |
142 | ||
143 | fDetector = det; | |
0c349049 | 144 | fRobPos = robPos; |
145 | fMcmPos = mcmPos; | |
dfd03fc3 | 146 | fRow = fFeeParam->GetPadRowFromMCM( fRobPos, fMcmPos ); |
5f006bd7 | 147 | |
b0a41e80 | 148 | if (!fInitialized) { |
6170d369 | 149 | fADCR = new Int_t *[AliTRDfeeParam::GetNadcMcm()]; |
150 | fADCF = new Int_t *[AliTRDfeeParam::GetNadcMcm()]; | |
151 | fZSMap = new Int_t [AliTRDfeeParam::GetNadcMcm()]; | |
152 | fGainCounterA = new UInt_t[AliTRDfeeParam::GetNadcMcm()]; | |
153 | fGainCounterB = new UInt_t[AliTRDfeeParam::GetNadcMcm()]; | |
759042e7 | 154 | fNTimeBin = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kC13CPUA, fDetector, fRobPos, fMcmPos); |
6170d369 | 155 | for( Int_t iAdc = 0 ; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++ ) { |
ce4786b9 | 156 | fADCR[iAdc] = new Int_t[fNTimeBin]; |
157 | fADCF[iAdc] = new Int_t[fNTimeBin]; | |
dfd03fc3 | 158 | } |
5f006bd7 | 159 | |
b0a41e80 | 160 | // filter registers |
6170d369 | 161 | fPedAcc = new UInt_t[AliTRDfeeParam::GetNadcMcm()]; // accumulator for pedestal filter |
162 | fTailAmplLong = new UShort_t[AliTRDfeeParam::GetNadcMcm()]; | |
163 | fTailAmplShort = new UShort_t[AliTRDfeeParam::GetNadcMcm()]; | |
5f006bd7 | 164 | |
b0a41e80 | 165 | // tracklet calculation |
6170d369 | 166 | fFitReg = new FitReg_t[AliTRDfeeParam::GetNadcMcm()]; |
ce4786b9 | 167 | fTrackletArray = new TClonesArray("AliTRDtrackletMCM", fgkMaxTracklets); |
5f006bd7 | 168 | |
ce4786b9 | 169 | fMCMT = new UInt_t[fgkMaxTracklets]; |
dfd03fc3 | 170 | } |
171 | ||
b0a41e80 | 172 | fInitialized = kTRUE; |
173 | ||
174 | Reset(); | |
175 | } | |
176 | ||
177 | void AliTRDmcmSim::Reset() | |
178 | { | |
179 | // Resets the data values and internal filter registers | |
180 | // by re-initialising them | |
181 | ||
5f006bd7 | 182 | if( !CheckInitialized() ) |
ce4786b9 | 183 | return; |
5896bc23 | 184 | |
6170d369 | 185 | for( Int_t iAdc = 0 ; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++ ) { |
ce4786b9 | 186 | for( Int_t it = 0 ; it < fNTimeBin ; it++ ) { |
187 | fADCR[iAdc][it] = 0; | |
188 | fADCF[iAdc][it] = 0; | |
dfd03fc3 | 189 | } |
ce4786b9 | 190 | fZSMap[iAdc] = -1; // Default unread, low active bit mask |
191 | fGainCounterA[iAdc] = 0; | |
192 | fGainCounterB[iAdc] = 0; | |
dfd03fc3 | 193 | } |
5f006bd7 | 194 | |
ce4786b9 | 195 | for(Int_t i = 0; i < fgkMaxTracklets; i++) { |
1d93b218 | 196 | fMCMT[i] = 0; |
197 | } | |
ce4786b9 | 198 | |
199 | for (Int_t iDict = 0; iDict < 3; iDict++) | |
200 | fDict[iDict] = 0x0; | |
5f006bd7 | 201 | |
b0a41e80 | 202 | FilterPedestalInit(); |
203 | FilterGainInit(); | |
ce4786b9 | 204 | FilterTailInit(); |
b0a41e80 | 205 | } |
1d93b218 | 206 | |
5f006bd7 | 207 | void AliTRDmcmSim::SetNTimebins(Int_t ntimebins) |
4ff7ed2b | 208 | { |
5f006bd7 | 209 | // Reallocate memory if a change in the number of timebins |
ce4786b9 | 210 | // is needed (should not be the case for real data) |
211 | ||
5f006bd7 | 212 | if( !CheckInitialized() ) |
ce4786b9 | 213 | return; |
214 | ||
4ff7ed2b | 215 | fNTimeBin = ntimebins; |
6170d369 | 216 | for( Int_t iAdc = 0 ; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++ ) { |
759042e7 | 217 | delete [] fADCR[iAdc]; |
218 | delete [] fADCF[iAdc]; | |
ce4786b9 | 219 | fADCR[iAdc] = new Int_t[fNTimeBin]; |
220 | fADCF[iAdc] = new Int_t[fNTimeBin]; | |
4ff7ed2b | 221 | } |
222 | } | |
223 | ||
5f006bd7 | 224 | Bool_t AliTRDmcmSim::LoadMCM(AliRunLoader* const runloader, Int_t det, Int_t rob, Int_t mcm) |
b0a41e80 | 225 | { |
ce4786b9 | 226 | // loads the ADC data as obtained from the digitsManager for the specified MCM. |
5f006bd7 | 227 | // This method is meant for rare execution, e.g. in the visualization. When called |
228 | // frequently use SetData(...) instead. | |
b0a41e80 | 229 | |
64e3d742 | 230 | Init(det, rob, mcm); |
b0a41e80 | 231 | |
232 | if (!runloader) { | |
233 | AliError("No Runloader given"); | |
234 | return kFALSE; | |
235 | } | |
236 | ||
237 | AliLoader *trdLoader = runloader->GetLoader("TRDLoader"); | |
238 | if (!trdLoader) { | |
239 | AliError("Could not get TRDLoader"); | |
240 | return kFALSE; | |
241 | } | |
242 | ||
5eba8ada | 243 | Bool_t retval = kTRUE; |
b0a41e80 | 244 | trdLoader->LoadDigits(); |
40bd6ee4 | 245 | fDigitsManager = 0x0; |
b0a41e80 | 246 | AliTRDdigitsManager *digMgr = new AliTRDdigitsManager(); |
247 | digMgr->SetSDigits(0); | |
248 | digMgr->CreateArrays(); | |
249 | digMgr->ReadDigits(trdLoader->TreeD()); | |
250 | AliTRDarrayADC *digits = (AliTRDarrayADC*) digMgr->GetDigits(det); | |
5eba8ada | 251 | if (digits->HasData()) { |
252 | digits->Expand(); | |
253 | ||
5896bc23 | 254 | if (fNTimeBin != digits->GetNtime()) { |
ce4786b9 | 255 | AliWarning(Form("Changing no. of timebins from %i to %i", fNTimeBin, digits->GetNtime())); |
4ff7ed2b | 256 | SetNTimebins(digits->GetNtime()); |
5896bc23 | 257 | } |
4ff7ed2b | 258 | |
ce4786b9 | 259 | SetData(digits); |
b0a41e80 | 260 | } |
5f006bd7 | 261 | else |
5eba8ada | 262 | retval = kFALSE; |
5f006bd7 | 263 | |
b0a41e80 | 264 | delete digMgr; |
5f006bd7 | 265 | |
4ff7ed2b | 266 | return retval; |
b0a41e80 | 267 | } |
268 | ||
269 | void AliTRDmcmSim::NoiseTest(Int_t nsamples, Int_t mean, Int_t sigma, Int_t inputGain, Int_t inputTail) | |
270 | { | |
5f006bd7 | 271 | // This function can be used to test the filters. |
b0a41e80 | 272 | // It feeds nsamples of ADC values with a gaussian distribution specified by mean and sigma. |
273 | // The filter chain implemented here consists of: | |
274 | // Pedestal -> Gain -> Tail | |
5f006bd7 | 275 | // With inputGain and inputTail the input to the gain and tail filter, respectively, |
276 | // can be chosen where | |
b0a41e80 | 277 | // 0: noise input |
278 | // 1: pedestal output | |
279 | // 2: gain output | |
5f006bd7 | 280 | // The input has to be chosen from a stage before. |
281 | // The filter behaviour is controlled by the TRAP parameters from AliTRDtrapConfig in the | |
b0a41e80 | 282 | // same way as in normal simulation. |
283 | // The functions produces four histograms with the values at the different stages. | |
284 | ||
5f006bd7 | 285 | if( !CheckInitialized() ) |
ce4786b9 | 286 | return; |
287 | ||
288 | TString nameInputGain; | |
5f006bd7 | 289 | TString nameInputTail; |
ce4786b9 | 290 | |
291 | switch (inputGain) { | |
292 | case 0: | |
293 | nameInputGain = "Noise"; | |
294 | break; | |
295 | ||
296 | case 1: | |
297 | nameInputGain = "Pedestal"; | |
298 | break; | |
299 | ||
300 | default: | |
301 | AliError("Undefined input to tail cancellation filter"); | |
302 | return; | |
303 | } | |
304 | ||
305 | switch (inputTail) { | |
306 | case 0: | |
307 | nameInputTail = "Noise"; | |
308 | break; | |
309 | ||
310 | case 1: | |
311 | nameInputTail = "Pedestal"; | |
312 | break; | |
313 | ||
314 | case 2: | |
315 | nameInputTail = "Gain"; | |
316 | break; | |
317 | ||
318 | default: | |
319 | AliError("Undefined input to tail cancellation filter"); | |
320 | return; | |
321 | } | |
322 | ||
b0a41e80 | 323 | TH1F *h = new TH1F("noise", "Gaussian Noise;sample;ADC count", |
324 | nsamples, 0, nsamples); | |
ce4786b9 | 325 | TH1F *hfp = new TH1F("ped", "Noise #rightarrow Pedestal filter;sample;ADC count", nsamples, 0, nsamples); |
5f006bd7 | 326 | TH1F *hfg = new TH1F("gain", |
327 | (nameInputGain + "#rightarrow Gain;sample;ADC count").Data(), | |
ce4786b9 | 328 | nsamples, 0, nsamples); |
5f006bd7 | 329 | TH1F *hft = new TH1F("tail", |
330 | (nameInputTail + "#rightarrow Tail;sample;ADC count").Data(), | |
ce4786b9 | 331 | nsamples, 0, nsamples); |
b0a41e80 | 332 | h->SetStats(kFALSE); |
333 | hfp->SetStats(kFALSE); | |
334 | hfg->SetStats(kFALSE); | |
335 | hft->SetStats(kFALSE); | |
5f006bd7 | 336 | |
b0a41e80 | 337 | Int_t value; // ADC count with noise (10 bit) |
338 | Int_t valuep; // pedestal filter output (12 bit) | |
339 | Int_t valueg; // gain filter output (12 bit) | |
340 | Int_t valuet; // tail filter value (12 bit) | |
5f006bd7 | 341 | |
b0a41e80 | 342 | for (Int_t i = 0; i < nsamples; i++) { |
5f006bd7 | 343 | value = (Int_t) gRandom->Gaus(mean, sigma); // generate noise with gaussian distribution |
b0a41e80 | 344 | h->SetBinContent(i, value); |
345 | ||
346 | valuep = FilterPedestalNextSample(1, 0, ((Int_t) value) << 2); | |
5f006bd7 | 347 | |
b0a41e80 | 348 | if (inputGain == 0) |
349 | valueg = FilterGainNextSample(1, ((Int_t) value) << 2); | |
5f006bd7 | 350 | else |
351 | valueg = FilterGainNextSample(1, valuep); | |
352 | ||
b0a41e80 | 353 | if (inputTail == 0) |
354 | valuet = FilterTailNextSample(1, ((Int_t) value) << 2); | |
355 | else if (inputTail == 1) | |
5f006bd7 | 356 | valuet = FilterTailNextSample(1, valuep); |
b0a41e80 | 357 | else |
5f006bd7 | 358 | valuet = FilterTailNextSample(1, valueg); |
b0a41e80 | 359 | |
360 | hfp->SetBinContent(i, valuep >> 2); | |
361 | hfg->SetBinContent(i, valueg >> 2); | |
362 | hft->SetBinContent(i, valuet >> 2); | |
363 | } | |
364 | ||
5f006bd7 | 365 | TCanvas *c = new TCanvas; |
b0a41e80 | 366 | c->Divide(2,2); |
367 | c->cd(1); | |
368 | h->Draw(); | |
369 | c->cd(2); | |
370 | hfp->Draw(); | |
371 | c->cd(3); | |
372 | hfg->Draw(); | |
373 | c->cd(4); | |
374 | hft->Draw(); | |
dfd03fc3 | 375 | } |
376 | ||
ce4786b9 | 377 | Bool_t AliTRDmcmSim::CheckInitialized() const |
ecf39416 | 378 | { |
0c349049 | 379 | // |
380 | // Check whether object is initialized | |
381 | // | |
382 | ||
5f006bd7 | 383 | if( ! fInitialized ) |
ce4786b9 | 384 | AliError(Form ("AliTRDmcmSim is not initialized but function other than Init() is called.")); |
385 | ||
ecf39416 | 386 | return fInitialized; |
387 | } | |
388 | ||
ab9f7002 | 389 | void AliTRDmcmSim::Print(Option_t* const option) const |
b0a41e80 | 390 | { |
391 | // Prints the data stored and/or calculated for this MCM. | |
5f006bd7 | 392 | // The output is controlled by option which can be a sequence of any of |
b0a41e80 | 393 | // the following characters: |
394 | // R - prints raw ADC data | |
5f006bd7 | 395 | // F - prints filtered data |
b0a41e80 | 396 | // H - prints detected hits |
397 | // T - prints found tracklets | |
5f006bd7 | 398 | // The later stages are only meaningful after the corresponding calculations |
b0a41e80 | 399 | // have been performed. |
400 | ||
5f006bd7 | 401 | if ( !CheckInitialized() ) |
ce4786b9 | 402 | return; |
403 | ||
b0a41e80 | 404 | printf("MCM %i on ROB %i in detector %i\n", fMcmPos, fRobPos, fDetector); |
405 | ||
406 | TString opt = option; | |
ce4786b9 | 407 | if (opt.Contains("R") || opt.Contains("F")) { |
408 | std::cout << *this; | |
1d93b218 | 409 | } |
410 | ||
b0a41e80 | 411 | if (opt.Contains("H")) { |
412 | printf("Found %i hits:\n", fNHits); | |
413 | for (Int_t iHit = 0; iHit < fNHits; iHit++) { | |
414 | printf("Hit %3i in timebin %2i, ADC %2i has charge %3i and position %3i\n", | |
ab9f7002 | 415 | iHit, fHits[iHit].fTimebin, fHits[iHit].fChannel, fHits[iHit].fQtot, fHits[iHit].fYpos); |
b0a41e80 | 416 | } |
1d93b218 | 417 | } |
1d93b218 | 418 | |
b0a41e80 | 419 | if (opt.Contains("T")) { |
420 | printf("Tracklets:\n"); | |
421 | for (Int_t iTrkl = 0; iTrkl < fTrackletArray->GetEntriesFast(); iTrkl++) { | |
422 | printf("tracklet %i: 0x%08x\n", iTrkl, ((AliTRDtrackletMCM*) (*fTrackletArray)[iTrkl])->GetTrackletWord()); | |
423 | } | |
1d93b218 | 424 | } |
b0a41e80 | 425 | } |
1d93b218 | 426 | |
5f006bd7 | 427 | void AliTRDmcmSim::Draw(Option_t* const option) |
b0a41e80 | 428 | { |
429 | // Plots the data stored in a 2-dim. timebin vs. ADC channel plot. | |
5f006bd7 | 430 | // The option selects what data is plotted and can be a sequence of |
b0a41e80 | 431 | // the following characters: |
432 | // R - plot raw data (default) | |
433 | // F - plot filtered data (meaningless if R is specified) | |
434 | // In addition to the ADC values: | |
5f006bd7 | 435 | // H - plot hits |
b0a41e80 | 436 | // T - plot tracklets |
437 | ||
5f006bd7 | 438 | if( !CheckInitialized() ) |
ce4786b9 | 439 | return; |
440 | ||
b0a41e80 | 441 | TString opt = option; |
442 | ||
443 | TH2F *hist = new TH2F("mcmdata", Form("Data of MCM %i on ROB %i in detector %i", \ | |
444 | fMcmPos, fRobPos, fDetector), \ | |
6170d369 | 445 | AliTRDfeeParam::GetNadcMcm(), -0.5, AliTRDfeeParam::GetNadcMcm()-.5, fNTimeBin, -.5, fNTimeBin-.5); |
b0a41e80 | 446 | hist->GetXaxis()->SetTitle("ADC Channel"); |
447 | hist->GetYaxis()->SetTitle("Timebin"); | |
448 | hist->SetStats(kFALSE); | |
449 | ||
450 | if (opt.Contains("R")) { | |
451 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
6170d369 | 452 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
b0a41e80 | 453 | hist->SetBinContent(iAdc+1, iTimeBin+1, fADCR[iAdc][iTimeBin] >> fgkAddDigits); |
454 | } | |
1d93b218 | 455 | } |
b0a41e80 | 456 | } |
457 | else { | |
458 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
6170d369 | 459 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
b0a41e80 | 460 | hist->SetBinContent(iAdc+1, iTimeBin+1, fADCF[iAdc][iTimeBin] >> fgkAddDigits); |
461 | } | |
1d93b218 | 462 | } |
1d93b218 | 463 | } |
b0a41e80 | 464 | hist->Draw("colz"); |
1d93b218 | 465 | |
b0a41e80 | 466 | if (opt.Contains("H")) { |
467 | TGraph *grHits = new TGraph(); | |
468 | for (Int_t iHit = 0; iHit < fNHits; iHit++) { | |
5f006bd7 | 469 | grHits->SetPoint(iHit, |
470 | fHits[iHit].fChannel + 1 + fHits[iHit].fYpos/256., | |
ab9f7002 | 471 | fHits[iHit].fTimebin); |
b0a41e80 | 472 | } |
473 | grHits->Draw("*"); | |
474 | } | |
1d93b218 | 475 | |
b0a41e80 | 476 | if (opt.Contains("T")) { |
477 | TLine *trklLines = new TLine[4]; | |
64e3d742 | 478 | for (Int_t iTrkl = 0; iTrkl < fTrackletArray->GetEntries(); iTrkl++) { |
b0a41e80 | 479 | AliTRDtrackletMCM *trkl = (AliTRDtrackletMCM*) (*fTrackletArray)[iTrkl]; |
ce4786b9 | 480 | Float_t padWidth = 0.635 + 0.03 * (fDetector % 6); |
481 | Float_t offset = padWidth/256. * ((((((fRobPos & 0x1) << 2) + (fMcmPos & 0x3)) * 18) << 8) - ((18*4*2 - 18*2 - 3) << 7)); // revert adding offset in FitTracklet | |
2b2b540f | 482 | Int_t ndrift = fTrapConfig->GetDmemUnsigned(fgkDmemAddrNdrift, fDetector, fRobPos, fMcmPos) >> 5; |
eaf6dbb0 | 483 | Float_t slope = 0; |
484 | if (ndrift) | |
485 | slope = trkl->GetdY() * 140e-4 / ndrift; | |
ce4786b9 | 486 | |
759042e7 | 487 | Int_t t0 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFS, fDetector, fRobPos, fMcmPos); |
488 | Int_t t1 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFE, fDetector, fRobPos, fMcmPos); | |
ce4786b9 | 489 | |
490 | trklLines[iTrkl].SetX1((offset - (trkl->GetY() - slope * t0)) / padWidth); // ??? sign? | |
491 | trklLines[iTrkl].SetY1(t0); | |
492 | trklLines[iTrkl].SetX2((offset - (trkl->GetY() - slope * t1)) / padWidth); // ??? sign? | |
493 | trklLines[iTrkl].SetY2(t1); | |
b0a41e80 | 494 | trklLines[iTrkl].SetLineColor(2); |
495 | trklLines[iTrkl].SetLineWidth(2); | |
496 | printf("Tracklet %i: y = %f, dy = %f, offset = %f\n", iTrkl, trkl->GetY(), (trkl->GetdY() * 140e-4), offset); | |
497 | trklLines[iTrkl].Draw(); | |
498 | } | |
499 | } | |
1d93b218 | 500 | } |
501 | ||
6419bebb | 502 | void AliTRDmcmSim::SetData( Int_t adc, const Int_t* const data ) |
dfd03fc3 | 503 | { |
0c349049 | 504 | // |
dfd03fc3 | 505 | // Store ADC data into array of raw data |
0c349049 | 506 | // |
dfd03fc3 | 507 | |
ecf39416 | 508 | if( !CheckInitialized() ) return; |
dfd03fc3 | 509 | |
6170d369 | 510 | if( adc < 0 || adc >= AliTRDfeeParam::GetNadcMcm() ) { |
511 | AliError(Form ("Error: ADC %i is out of range (0 .. %d).", adc, AliTRDfeeParam::GetNadcMcm()-1)); | |
dfd03fc3 | 512 | return; |
513 | } | |
514 | ||
4ff7ed2b | 515 | for( Int_t it = 0 ; it < fNTimeBin ; it++ ) { |
ce4786b9 | 516 | fADCR[adc][it] = (Int_t) (data[it]) << fgkAddDigits; |
517 | fADCF[adc][it] = (Int_t) (data[it]) << fgkAddDigits; | |
dfd03fc3 | 518 | } |
519 | } | |
520 | ||
ce4786b9 | 521 | void AliTRDmcmSim::SetData( Int_t adc, Int_t it, Int_t data ) |
dfd03fc3 | 522 | { |
0c349049 | 523 | // |
dfd03fc3 | 524 | // Store ADC data into array of raw data |
0c349049 | 525 | // |
dfd03fc3 | 526 | |
ecf39416 | 527 | if( !CheckInitialized() ) return; |
dfd03fc3 | 528 | |
6170d369 | 529 | if( adc < 0 || adc >= AliTRDfeeParam::GetNadcMcm() ) { |
530 | AliError(Form ("Error: ADC %i is out of range (0 .. %d).", adc, AliTRDfeeParam::GetNadcMcm()-1)); | |
dfd03fc3 | 531 | return; |
532 | } | |
533 | ||
ce4786b9 | 534 | fADCR[adc][it] = data << fgkAddDigits; |
535 | fADCF[adc][it] = data << fgkAddDigits; | |
b0a41e80 | 536 | } |
537 | ||
6b094867 | 538 | void AliTRDmcmSim::SetData(AliTRDarrayADC* const adcArray, AliTRDdigitsManager * const digitsManager) |
b0a41e80 | 539 | { |
ab9f7002 | 540 | // Set the ADC data from an AliTRDarrayADC |
541 | ||
5f006bd7 | 542 | if( !CheckInitialized() ) |
b0a41e80 | 543 | return; |
b0a41e80 | 544 | |
40bd6ee4 | 545 | fDigitsManager = digitsManager; |
ce4786b9 | 546 | if (fDigitsManager) { |
547 | for (Int_t iDict = 0; iDict < 3; iDict++) { | |
548 | AliTRDarrayDictionary *newDict = (AliTRDarrayDictionary*) fDigitsManager->GetDictionary(fDetector, iDict); | |
549 | if (fDict[iDict] != 0x0 && newDict != 0x0) { | |
5f006bd7 | 550 | |
ce4786b9 | 551 | if (fDict[iDict] == newDict) |
552 | continue; | |
40bd6ee4 | 553 | |
ce4786b9 | 554 | fDict[iDict] = newDict; |
5f7c3c48 | 555 | if(fDict[iDict]->GetDim() != 0) |
556 | fDict[iDict]->Expand(); | |
ce4786b9 | 557 | } |
558 | else { | |
559 | fDict[iDict] = newDict; | |
5f7c3c48 | 560 | if (fDict[iDict] && (fDict[iDict]->GetDim() != 0) ) |
ce4786b9 | 561 | fDict[iDict]->Expand(); |
5f7c3c48 | 562 | } |
5f006bd7 | 563 | |
564 | // If there is no data, set dictionary to zero to avoid crashes | |
27a030ab | 565 | if (fDict[iDict]->GetDim() == 0) { |
5f7c3c48 | 566 | // AliError(Form("Dictionary %i of det. %i has dim. 0", iDict, fDetector)); |
27a030ab | 567 | fDict[iDict] = 0x0; |
ce4786b9 | 568 | } |
569 | } | |
5896bc23 | 570 | } |
4ff7ed2b | 571 | |
ce4786b9 | 572 | if (fNTimeBin != adcArray->GetNtime()) |
573 | SetNTimebins(adcArray->GetNtime()); | |
5f006bd7 | 574 | |
ce4786b9 | 575 | Int_t offset = (fMcmPos % 4 + 1) * 21 + (fRobPos % 2) * 84 - 1; |
b0a41e80 | 576 | |
577 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
6170d369 | 578 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
ce4786b9 | 579 | Int_t value = adcArray->GetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin); |
a10c6981 | 580 | // treat 0 as suppressed, |
581 | // this is not correct but reported like that from arrayADC | |
582 | if (value <= 0 || (offset - iAdc < 1) || (offset - iAdc > 165)) { | |
759042e7 | 583 | fADCR[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP, fDetector, fRobPos, fMcmPos) + (fgAddBaseline << fgkAddDigits); |
584 | fADCF[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP, fDetector, fRobPos, fMcmPos) + (fgAddBaseline << fgkAddDigits); | |
b0a41e80 | 585 | } |
586 | else { | |
ce4786b9 | 587 | fZSMap[iAdc] = 0; |
588 | fADCR[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits); | |
589 | fADCF[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits); | |
b0a41e80 | 590 | } |
591 | } | |
592 | } | |
dfd03fc3 | 593 | } |
594 | ||
6419bebb | 595 | void AliTRDmcmSim::SetDataByPad(const AliTRDarrayADC* const adcArray, AliTRDdigitsManager * const digitsManager) |
ce51199c | 596 | { |
5f006bd7 | 597 | // Set the ADC data from an AliTRDarrayADC |
ce51199c | 598 | // (by pad, to be used during initial reading in simulation) |
599 | ||
5f006bd7 | 600 | if( !CheckInitialized() ) |
ce51199c | 601 | return; |
602 | ||
603 | fDigitsManager = digitsManager; | |
604 | if (fDigitsManager) { | |
605 | for (Int_t iDict = 0; iDict < 3; iDict++) { | |
606 | AliTRDarrayDictionary *newDict = (AliTRDarrayDictionary*) fDigitsManager->GetDictionary(fDetector, iDict); | |
607 | if (fDict[iDict] != 0x0 && newDict != 0x0) { | |
5f006bd7 | 608 | |
ce51199c | 609 | if (fDict[iDict] == newDict) |
610 | continue; | |
611 | ||
612 | fDict[iDict] = newDict; | |
5f006bd7 | 613 | fDict[iDict]->Expand(); |
ce51199c | 614 | } |
615 | else { | |
616 | fDict[iDict] = newDict; | |
617 | if (fDict[iDict]) | |
618 | fDict[iDict]->Expand(); | |
619 | } | |
5f006bd7 | 620 | |
621 | // If there is no data, set dictionary to zero to avoid crashes | |
27a030ab | 622 | if (fDict[iDict]->GetDim() == 0) { |
282c303c | 623 | AliError(Form("Dictionary %i of det. %i has dim. 0", iDict, fDetector)); |
27a030ab | 624 | fDict[iDict] = 0x0; |
625 | } | |
ce51199c | 626 | } |
627 | } | |
628 | ||
629 | if (fNTimeBin != adcArray->GetNtime()) | |
630 | SetNTimebins(adcArray->GetNtime()); | |
5f006bd7 | 631 | |
ce51199c | 632 | Int_t offset = (fMcmPos % 4 + 1) * 18 + (fRobPos % 2) * 72 + 1; |
633 | ||
634 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
6170d369 | 635 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
ce51199c | 636 | Int_t value = -1; |
637 | Int_t pad = offset - iAdc; | |
5f006bd7 | 638 | if (pad > -1 && pad < 144) |
ce51199c | 639 | value = adcArray->GetData(GetRow(), offset - iAdc, iTimeBin); |
640 | // Int_t value = adcArray->GetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin); | |
641 | if (value < 0 || (offset - iAdc < 1) || (offset - iAdc > 165)) { | |
759042e7 | 642 | fADCR[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP, fDetector, fRobPos, fMcmPos) + (fgAddBaseline << fgkAddDigits); |
643 | fADCF[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP, fDetector, fRobPos, fMcmPos) + (fgAddBaseline << fgkAddDigits); | |
ce51199c | 644 | } |
645 | else { | |
646 | fZSMap[iAdc] = 0; | |
647 | fADCR[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits); | |
648 | fADCF[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits); | |
649 | } | |
650 | } | |
651 | } | |
652 | } | |
653 | ||
ce4786b9 | 654 | void AliTRDmcmSim::SetDataPedestal( Int_t adc ) |
dfd03fc3 | 655 | { |
0c349049 | 656 | // |
dfd03fc3 | 657 | // Store ADC data into array of raw data |
0c349049 | 658 | // |
dfd03fc3 | 659 | |
5f006bd7 | 660 | if( !CheckInitialized() ) |
ce4786b9 | 661 | return; |
dfd03fc3 | 662 | |
6170d369 | 663 | if( adc < 0 || adc >= AliTRDfeeParam::GetNadcMcm() ) { |
dfd03fc3 | 664 | return; |
665 | } | |
666 | ||
667 | for( Int_t it = 0 ; it < fNTimeBin ; it++ ) { | |
759042e7 | 668 | fADCR[adc][it] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP, fDetector, fRobPos, fMcmPos) + (fgAddBaseline << fgkAddDigits); |
669 | fADCF[adc][it] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP, fDetector, fRobPos, fMcmPos) + (fgAddBaseline << fgkAddDigits); | |
dfd03fc3 | 670 | } |
671 | } | |
672 | ||
ce4786b9 | 673 | 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 |
674 | { | |
675 | // retrieve the MC hit information (not available in TRAP hardware) | |
676 | ||
677 | if (index < 0 || index >= fNHits) | |
678 | return kFALSE; | |
5f006bd7 | 679 | |
ce4786b9 | 680 | channel = fHits[index].fChannel; |
681 | timebin = fHits[index].fTimebin; | |
682 | qtot = fHits[index].fQtot; | |
683 | ypos = fHits[index].fYpos; | |
684 | y = (Float_t) ((((((fRobPos & 0x1) << 2) + (fMcmPos & 0x3)) * 18) << 8) - ((18*4*2 - 18*2 - 1) << 7) - | |
5f006bd7 | 685 | (channel << 8) - ypos) |
ce4786b9 | 686 | * (0.635 + 0.03 * (fDetector % 6)) |
687 | / 256.0; | |
25b41f6f | 688 | label = fHits[index].fLabel[0]; |
ce4786b9 | 689 | |
690 | return kTRUE; | |
691 | } | |
692 | ||
693 | Int_t AliTRDmcmSim::GetCol( Int_t adc ) | |
dfd03fc3 | 694 | { |
0c349049 | 695 | // |
dfd03fc3 | 696 | // Return column id of the pad for the given ADC channel |
0c349049 | 697 | // |
698 | ||
5f006bd7 | 699 | if( !CheckInitialized() ) |
f793c83d | 700 | return -1; |
dfd03fc3 | 701 | |
ce4786b9 | 702 | Int_t col = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adc); |
5f006bd7 | 703 | if (col < 0 || col >= fFeeParam->GetNcol()) |
a6d08b7f | 704 | return -1; |
5f006bd7 | 705 | else |
a6d08b7f | 706 | return col; |
dfd03fc3 | 707 | } |
708 | ||
ce4786b9 | 709 | Int_t AliTRDmcmSim::ProduceRawStream( UInt_t *buf, Int_t bufSize, UInt_t iEv) const |
dfd03fc3 | 710 | { |
0c349049 | 711 | // |
dfd03fc3 | 712 | // Produce raw data stream from this MCM and put in buf |
5f006bd7 | 713 | // Returns number of words filled, or negative value |
0c349049 | 714 | // with -1 * number of overflowed words |
715 | // | |
dfd03fc3 | 716 | |
5f006bd7 | 717 | if( !CheckInitialized() ) |
ce4786b9 | 718 | return 0; |
719 | ||
dfd03fc3 | 720 | UInt_t x; |
7d619a80 | 721 | UInt_t mcmHeader = 0; |
722 | UInt_t adcMask = 0; | |
dfd03fc3 | 723 | Int_t nw = 0; // Number of written words |
724 | Int_t of = 0; // Number of overflowed words | |
725 | Int_t rawVer = fFeeParam->GetRAWversion(); | |
726 | Int_t **adc; | |
b0a41e80 | 727 | Int_t nActiveADC = 0; // number of activated ADC bits in a word |
dfd03fc3 | 728 | |
5f006bd7 | 729 | if( !CheckInitialized() ) |
ce4786b9 | 730 | return 0; |
ecf39416 | 731 | |
759042e7 | 732 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBSF, fDetector, fRobPos, fMcmPos) != 0) // store unfiltered data |
dfd03fc3 | 733 | adc = fADCR; |
5f006bd7 | 734 | else |
dfd03fc3 | 735 | adc = fADCF; |
5f006bd7 | 736 | |
b0a41e80 | 737 | // Produce ADC mask : nncc cccm mmmm mmmm mmmm mmmm mmmm 1100 |
738 | // n : unused , c : ADC count, m : selected ADCs | |
7d619a80 | 739 | if( rawVer >= 3 && |
759042e7 | 740 | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kC15CPUA, fDetector, fRobPos, fMcmPos) & (1 << 13))) { // check for zs flag in TRAP configuration |
6170d369 | 741 | for( Int_t iAdc = 0 ; iAdc < AliTRDfeeParam::GetNadcMcm() ; iAdc++ ) { |
ce4786b9 | 742 | if( ~fZSMap[iAdc] != 0 ) { // 0 means not suppressed |
7d619a80 | 743 | adcMask |= (1 << (iAdc+4) ); // last 4 digit reserved for 1100=0xc |
744 | nActiveADC++; // number of 1 in mmm....m | |
dfd03fc3 | 745 | } |
746 | } | |
b0a41e80 | 747 | |
7d619a80 | 748 | if ((nActiveADC == 0) && |
759042e7 | 749 | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kC15CPUA, fDetector, fRobPos, fMcmPos) & (1 << 8))) // check for DEH flag in TRAP configuration |
7d619a80 | 750 | return 0; |
751 | ||
752 | // assemble adc mask word | |
753 | adcMask |= (1 << 30) | ( ( 0x3FFFFFFC ) & (~(nActiveADC) << 25) ) | 0xC; // nn = 01, ccccc are inverted, 0xc=1100 | |
754 | } | |
755 | ||
756 | // MCM header | |
757 | mcmHeader = (1<<31) | (fRobPos << 28) | (fMcmPos << 24) | ((iEv % 0x100000) << 4) | 0xC; | |
758 | if (nw < bufSize) | |
759 | buf[nw++] = mcmHeader; | |
760 | else | |
761 | of++; | |
762 | ||
763 | // ADC mask | |
764 | if( adcMask != 0 ) { | |
765 | if (nw < bufSize) | |
766 | buf[nw++] = adcMask; | |
767 | else | |
dfd03fc3 | 768 | of++; |
dfd03fc3 | 769 | } |
770 | ||
771 | // Produce ADC data. 3 timebins are packed into one 32 bits word | |
772 | // In this version, different ADC channel will NOT share the same word | |
773 | ||
774 | UInt_t aa=0, a1=0, a2=0, a3=0; | |
775 | ||
776 | for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) { | |
ce4786b9 | 777 | if( rawVer>= 3 && ~fZSMap[iAdc] == 0 ) continue; // Zero Suppression, 0 means not suppressed |
dfd03fc3 | 778 | aa = !(iAdc & 1) + 2; |
779 | for (Int_t iT = 0; iT < fNTimeBin; iT+=3 ) { | |
b0a41e80 | 780 | a1 = ((iT ) < fNTimeBin ) ? adc[iAdc][iT ] >> fgkAddDigits : 0; |
781 | a2 = ((iT + 1) < fNTimeBin ) ? adc[iAdc][iT+1] >> fgkAddDigits : 0; | |
782 | a3 = ((iT + 2) < fNTimeBin ) ? adc[iAdc][iT+2] >> fgkAddDigits : 0; | |
ecf39416 | 783 | x = (a3 << 22) | (a2 << 12) | (a1 << 2) | aa; |
ce4786b9 | 784 | if (nw < bufSize) { |
b0a41e80 | 785 | buf[nw++] = x; |
ecf39416 | 786 | } |
787 | else { | |
b0a41e80 | 788 | of++; |
ecf39416 | 789 | } |
dfd03fc3 | 790 | } |
791 | } | |
792 | ||
793 | if( of != 0 ) return -of; else return nw; | |
794 | } | |
795 | ||
ce4786b9 | 796 | Int_t AliTRDmcmSim::ProduceTrackletStream( UInt_t *buf, Int_t bufSize ) |
987ba9a3 | 797 | { |
798 | // | |
b0a41e80 | 799 | // Produce tracklet data stream from this MCM and put in buf |
5f006bd7 | 800 | // Returns number of words filled, or negative value |
987ba9a3 | 801 | // with -1 * number of overflowed words |
802 | // | |
803 | ||
5f006bd7 | 804 | if( !CheckInitialized() ) |
ce4786b9 | 805 | return 0; |
806 | ||
987ba9a3 | 807 | Int_t nw = 0; // Number of written words |
808 | Int_t of = 0; // Number of overflowed words | |
5f006bd7 | 809 | |
810 | // Produce tracklet data. A maximum of four 32 Bit words will be written per MCM | |
b0a41e80 | 811 | // fMCMT is filled continuously until no more tracklet words available |
987ba9a3 | 812 | |
f793c83d | 813 | for (Int_t iTracklet = 0; iTracklet < fTrackletArray->GetEntriesFast(); iTracklet++) { |
5f006bd7 | 814 | if (nw < bufSize) |
f793c83d | 815 | buf[nw++] = ((AliTRDtrackletMCM*) (*fTrackletArray)[iTracklet])->GetTrackletWord(); |
5f006bd7 | 816 | else |
f793c83d | 817 | of++; |
987ba9a3 | 818 | } |
5f006bd7 | 819 | |
b0a41e80 | 820 | if( of != 0 ) return -of; else return nw; |
821 | } | |
987ba9a3 | 822 | |
b0a41e80 | 823 | void AliTRDmcmSim::Filter() |
824 | { | |
825 | // | |
826 | // Filter the raw ADC values. The active filter stages and their | |
827 | // parameters are taken from AliTRDtrapConfig. | |
5f006bd7 | 828 | // The raw data is stored separate from the filtered data. Thus, |
829 | // it is possible to run the filters on a set of raw values | |
b0a41e80 | 830 | // sequentially for parameter tuning. |
831 | // | |
987ba9a3 | 832 | |
5f006bd7 | 833 | if( !CheckInitialized() ) |
b0a41e80 | 834 | return; |
987ba9a3 | 835 | |
b0a41e80 | 836 | // Apply filters sequentially. Bypass is handled by filters |
5f006bd7 | 837 | // since counters and internal registers may be updated even |
b0a41e80 | 838 | // if the filter is bypassed. |
5f006bd7 | 839 | // The first filter takes the data from fADCR and |
840 | // outputs to fADCF. | |
841 | ||
b0a41e80 | 842 | // Non-linearity filter not implemented. |
843 | FilterPedestal(); | |
844 | FilterGain(); | |
845 | FilterTail(); | |
846 | // Crosstalk filter not implemented. | |
847 | } | |
987ba9a3 | 848 | |
5f006bd7 | 849 | void AliTRDmcmSim::FilterPedestalInit(Int_t baseline) |
b0a41e80 | 850 | { |
5f006bd7 | 851 | // Initializes the pedestal filter assuming that the input has |
b0a41e80 | 852 | // been constant for a long time (compared to the time constant). |
987ba9a3 | 853 | |
759042e7 | 854 | UShort_t fptc = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPTC, fDetector, fRobPos, fMcmPos); // 0..3, 0 - fastest, 3 - slowest |
987ba9a3 | 855 | |
6170d369 | 856 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) |
5f006bd7 | 857 | fPedAcc[iAdc] = (baseline << 2) * (1 << fgkFPshifts[fptc]); |
987ba9a3 | 858 | } |
859 | ||
b0a41e80 | 860 | UShort_t AliTRDmcmSim::FilterPedestalNextSample(Int_t adc, Int_t timebin, UShort_t value) |
1d93b218 | 861 | { |
b0a41e80 | 862 | // Returns the output of the pedestal filter given the input value. |
5f006bd7 | 863 | // The output depends on the internal registers and, thus, the |
b0a41e80 | 864 | // history of the filter. |
1d93b218 | 865 | |
759042e7 | 866 | UShort_t fpnp = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP, fDetector, fRobPos, fMcmPos); // 0..511 -> 0..127.75, pedestal at the output |
867 | UShort_t fptc = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPTC, fDetector, fRobPos, fMcmPos); // 0..3, 0 - fastest, 3 - slowest | |
868 | UShort_t fpby = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPBY, fDetector, fRobPos, fMcmPos); // 0..1 bypass, active low | |
1d93b218 | 869 | |
b0a41e80 | 870 | UShort_t accumulatorShifted; |
871 | Int_t correction; | |
872 | UShort_t inpAdd; | |
5f006bd7 | 873 | |
b0a41e80 | 874 | inpAdd = value + fpnp; |
1d93b218 | 875 | |
ce4786b9 | 876 | accumulatorShifted = (fPedAcc[adc] >> fgkFPshifts[fptc]) & 0x3FF; // 10 bits |
b0a41e80 | 877 | if (timebin == 0) // the accumulator is disabled in the drift time |
878 | { | |
879 | correction = (value & 0x3FF) - accumulatorShifted; | |
880 | fPedAcc[adc] = (fPedAcc[adc] + correction) & 0x7FFFFFFF; // 31 bits | |
1d93b218 | 881 | } |
5f006bd7 | 882 | |
ce4786b9 | 883 | if (fpby == 0) |
884 | return value; | |
885 | ||
b0a41e80 | 886 | if (inpAdd <= accumulatorShifted) |
887 | return 0; | |
888 | else | |
889 | { | |
890 | inpAdd = inpAdd - accumulatorShifted; | |
5f006bd7 | 891 | if (inpAdd > 0xFFF) |
b0a41e80 | 892 | return 0xFFF; |
5f006bd7 | 893 | else |
b0a41e80 | 894 | return inpAdd; |
895 | } | |
1d93b218 | 896 | } |
897 | ||
b0a41e80 | 898 | void AliTRDmcmSim::FilterPedestal() |
dfd03fc3 | 899 | { |
0c349049 | 900 | // |
b0a41e80 | 901 | // Apply pedestal filter |
0c349049 | 902 | // |
5f006bd7 | 903 | // As the first filter in the chain it reads data from fADCR |
904 | // and outputs to fADCF. | |
905 | // It has only an effect if previous samples have been fed to | |
906 | // find the pedestal. Currently, the simulation assumes that | |
b0a41e80 | 907 | // the input has been stable for a sufficiently long time. |
dfd03fc3 | 908 | |
b0a41e80 | 909 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
6170d369 | 910 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
b0a41e80 | 911 | fADCF[iAdc][iTimeBin] = FilterPedestalNextSample(iAdc, iTimeBin, fADCR[iAdc][iTimeBin]); |
dfd03fc3 | 912 | } |
913 | } | |
b0a41e80 | 914 | } |
915 | ||
916 | void AliTRDmcmSim::FilterGainInit() | |
917 | { | |
5f006bd7 | 918 | // Initializes the gain filter. In this case, only threshold |
b0a41e80 | 919 | // counters are reset. |
dfd03fc3 | 920 | |
6170d369 | 921 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
5f006bd7 | 922 | // these are counters which in hardware continue |
b0a41e80 | 923 | // until maximum or reset |
924 | fGainCounterA[iAdc] = 0; | |
925 | fGainCounterB[iAdc] = 0; | |
926 | } | |
dfd03fc3 | 927 | } |
928 | ||
b0a41e80 | 929 | UShort_t AliTRDmcmSim::FilterGainNextSample(Int_t adc, UShort_t value) |
dfd03fc3 | 930 | { |
b0a41e80 | 931 | // Apply the gain filter to the given value. |
932 | // BEGIN_LATEX O_{i}(t) = #gamma_{i} * I_{i}(t) + a_{i} END_LATEX | |
5f006bd7 | 933 | // The output depends on the internal registers and, thus, the |
b0a41e80 | 934 | // history of the filter. |
23200400 | 935 | |
759042e7 | 936 | UShort_t fgby = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFGBY, fDetector, fRobPos, fMcmPos); // bypass, active low |
937 | UShort_t fgf = fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGF0 + adc), fDetector, fRobPos, fMcmPos); // 0x700 + (0 & 0x1ff); | |
938 | UShort_t fga = fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGA0 + adc), fDetector, fRobPos, fMcmPos); // 40; | |
939 | UShort_t fgta = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFGTA, fDetector, fRobPos, fMcmPos); // 20; | |
940 | UShort_t fgtb = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFGTB, fDetector, fRobPos, fMcmPos); // 2060; | |
dfd03fc3 | 941 | |
5f7c3c48 | 942 | UInt_t fgfExtended = 0x700 + fgf; // The corr factor which is finally applied has to be extended by 0x700 (hex) or 0.875 (dec) |
943 | // because fgf=0 correspons to 0.875 and fgf=511 correspons to 1.125 - 2^(-11) | |
944 | // (see TRAP User Manual for details) | |
945 | ||
ce4786b9 | 946 | UInt_t corr; // corrected value |
dfd03fc3 | 947 | |
b0a41e80 | 948 | value &= 0xFFF; |
5f7c3c48 | 949 | corr = (value * fgfExtended) >> 11; |
ce4786b9 | 950 | corr = corr > 0xfff ? 0xfff : corr; |
951 | corr = AddUintClipping(corr, fga, 12); | |
b0a41e80 | 952 | |
5f006bd7 | 953 | // Update threshold counters |
b0a41e80 | 954 | // not really useful as they are cleared with every new event |
ce4786b9 | 955 | if (!((fGainCounterA[adc] == 0x3FFFFFF) || (fGainCounterB[adc] == 0x3FFFFFF))) |
956 | // stop when full | |
b0a41e80 | 957 | { |
5f006bd7 | 958 | if (corr >= fgtb) |
b0a41e80 | 959 | fGainCounterB[adc]++; |
5f006bd7 | 960 | else if (corr >= fgta) |
b0a41e80 | 961 | fGainCounterA[adc]++; |
dfd03fc3 | 962 | } |
b0a41e80 | 963 | |
ce4786b9 | 964 | if (fgby == 1) |
5f006bd7 | 965 | return corr; |
ce4786b9 | 966 | else |
967 | return value; | |
dfd03fc3 | 968 | } |
969 | ||
dfd03fc3 | 970 | void AliTRDmcmSim::FilterGain() |
971 | { | |
b0a41e80 | 972 | // Read data from fADCF and apply gain filter. |
0c349049 | 973 | |
6170d369 | 974 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
b0a41e80 | 975 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
976 | fADCF[iAdc][iTimeBin] = FilterGainNextSample(iAdc, fADCF[iAdc][iTimeBin]); | |
977 | } | |
978 | } | |
dfd03fc3 | 979 | } |
980 | ||
b0a41e80 | 981 | void AliTRDmcmSim::FilterTailInit(Int_t baseline) |
dfd03fc3 | 982 | { |
5f006bd7 | 983 | // Initializes the tail filter assuming that the input has |
984 | // been at the baseline value (configured by FTFP) for a | |
b0a41e80 | 985 | // sufficiently long time. |
986 | ||
987 | // exponents and weight calculated from configuration | |
759042e7 | 988 | UShort_t alphaLong = 0x3ff & fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTAL, fDetector, fRobPos, fMcmPos); // the weight of the long component |
989 | UShort_t lambdaLong = (1 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLL, fDetector, fRobPos, fMcmPos) & 0x1FF); // the multiplier | |
990 | UShort_t lambdaShort = (0 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLS, fDetector, fRobPos, fMcmPos) & 0x1FF); // the multiplier | |
b0a41e80 | 991 | |
992 | Float_t lambdaL = lambdaLong * 1.0 / (1 << 11); | |
993 | Float_t lambdaS = lambdaShort * 1.0 / (1 << 11); | |
994 | Float_t alphaL = alphaLong * 1.0 / (1 << 11); | |
995 | Float_t qup, qdn; | |
996 | qup = (1 - lambdaL) * (1 - lambdaS); | |
997 | qdn = 1 - lambdaS * alphaL - lambdaL * (1 - alphaL); | |
998 | Float_t kdc = qup/qdn; | |
999 | ||
1000 | Float_t kt, ql, qs; | |
1001 | UShort_t aout; | |
ce4786b9 | 1002 | |
1003 | if (baseline < 0) | |
759042e7 | 1004 | baseline = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP, fDetector, fRobPos, fMcmPos); |
5f006bd7 | 1005 | |
b0a41e80 | 1006 | ql = lambdaL * (1 - lambdaS) * alphaL; |
1007 | qs = lambdaS * (1 - lambdaL) * (1 - alphaL); | |
1008 | ||
6170d369 | 1009 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
ce4786b9 | 1010 | Int_t value = baseline & 0xFFF; |
759042e7 | 1011 | Int_t corr = (value * fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGF0 + iAdc), fDetector, fRobPos, fMcmPos)) >> 11; |
ce4786b9 | 1012 | corr = corr > 0xfff ? 0xfff : corr; |
759042e7 | 1013 | corr = AddUintClipping(corr, fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGA0 + iAdc), fDetector, fRobPos, fMcmPos), 12); |
ce4786b9 | 1014 | |
1015 | kt = kdc * baseline; | |
1016 | aout = baseline - (UShort_t) kt; | |
1017 | ||
b0a41e80 | 1018 | fTailAmplLong[iAdc] = (UShort_t) (aout * ql / (ql + qs)); |
1019 | fTailAmplShort[iAdc] = (UShort_t) (aout * qs / (ql + qs)); | |
1020 | } | |
1021 | } | |
dfd03fc3 | 1022 | |
b0a41e80 | 1023 | UShort_t AliTRDmcmSim::FilterTailNextSample(Int_t adc, UShort_t value) |
1024 | { | |
5f006bd7 | 1025 | // Returns the output of the tail filter for the given input value. |
1026 | // The output depends on the internal registers and, thus, the | |
b0a41e80 | 1027 | // history of the filter. |
1028 | ||
1029 | // exponents and weight calculated from configuration | |
759042e7 | 1030 | UShort_t alphaLong = 0x3ff & fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTAL, fDetector, fRobPos, fMcmPos); // the weight of the long component |
1031 | UShort_t lambdaLong = (1 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLL, fDetector, fRobPos, fMcmPos) & 0x1FF); // the multiplier of the long component | |
1032 | UShort_t lambdaShort = (0 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLS, fDetector, fRobPos, fMcmPos) & 0x1FF); // the multiplier of the short component | |
b0a41e80 | 1033 | |
ce4786b9 | 1034 | // intermediate signals |
1035 | UInt_t aDiff; | |
1036 | UInt_t alInpv; | |
b0a41e80 | 1037 | UShort_t aQ; |
ce4786b9 | 1038 | UInt_t tmp; |
5f006bd7 | 1039 | |
ab9f7002 | 1040 | UShort_t inpVolt = value & 0xFFF; // 12 bits |
5f006bd7 | 1041 | |
ce4786b9 | 1042 | // add the present generator outputs |
1043 | aQ = AddUintClipping(fTailAmplLong[adc], fTailAmplShort[adc], 12); | |
1044 | ||
1045 | // calculate the difference between the input and the generated signal | |
5f006bd7 | 1046 | if (inpVolt > aQ) |
ce4786b9 | 1047 | aDiff = inpVolt - aQ; |
5f006bd7 | 1048 | else |
ce4786b9 | 1049 | aDiff = 0; |
5f006bd7 | 1050 | |
ce4786b9 | 1051 | // the inputs to the two generators, weighted |
1052 | alInpv = (aDiff * alphaLong) >> 11; | |
5f006bd7 | 1053 | |
ce4786b9 | 1054 | // the new values of the registers, used next time |
1055 | // long component | |
1056 | tmp = AddUintClipping(fTailAmplLong[adc], alInpv, 12); | |
1057 | tmp = (tmp * lambdaLong) >> 11; | |
1058 | fTailAmplLong[adc] = tmp & 0xFFF; | |
1059 | // short component | |
1060 | tmp = AddUintClipping(fTailAmplShort[adc], aDiff - alInpv, 12); | |
1061 | tmp = (tmp * lambdaShort) >> 11; | |
1062 | fTailAmplShort[adc] = tmp & 0xFFF; | |
5f006bd7 | 1063 | |
ce4786b9 | 1064 | // the output of the filter |
759042e7 | 1065 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTBY, fDetector, fRobPos, fMcmPos) == 0) // bypass mode, active low |
b0a41e80 | 1066 | return value; |
1067 | else | |
b0a41e80 | 1068 | return aDiff; |
b0a41e80 | 1069 | } |
dfd03fc3 | 1070 | |
b0a41e80 | 1071 | void AliTRDmcmSim::FilterTail() |
1072 | { | |
5f006bd7 | 1073 | // Apply tail cancellation filter to all data. |
dfd03fc3 | 1074 | |
b0a41e80 | 1075 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
6170d369 | 1076 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
b0a41e80 | 1077 | fADCF[iAdc][iTimeBin] = FilterTailNextSample(iAdc, fADCF[iAdc][iTimeBin]); |
dfd03fc3 | 1078 | } |
dfd03fc3 | 1079 | } |
dfd03fc3 | 1080 | } |
1081 | ||
dfd03fc3 | 1082 | void AliTRDmcmSim::ZSMapping() |
1083 | { | |
0c349049 | 1084 | // |
dfd03fc3 | 1085 | // Zero Suppression Mapping implemented in TRAP chip |
ce4786b9 | 1086 | // only implemented for up to 30 timebins |
dfd03fc3 | 1087 | // |
1088 | // See detail TRAP manual "Data Indication" section: | |
1089 | // http://www.kip.uni-heidelberg.de/ti/TRD/doc/trap/TRAP-UserManual.pdf | |
0c349049 | 1090 | // |
dfd03fc3 | 1091 | |
5f006bd7 | 1092 | if( !CheckInitialized() ) |
ce4786b9 | 1093 | return; |
1094 | ||
759042e7 | 1095 | Int_t eBIS = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIS, fDetector, fRobPos, fMcmPos); |
1096 | Int_t eBIT = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIT, fDetector, fRobPos, fMcmPos); | |
1097 | Int_t eBIL = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIL, fDetector, fRobPos, fMcmPos); | |
1098 | Int_t eBIN = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIN, fDetector, fRobPos, fMcmPos); | |
ecf39416 | 1099 | |
b0a41e80 | 1100 | Int_t **adc = fADCF; |
dfd03fc3 | 1101 | |
6170d369 | 1102 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) |
ce4786b9 | 1103 | fZSMap[iAdc] = -1; |
b0a41e80 | 1104 | |
1105 | for( Int_t it = 0 ; it < fNTimeBin ; it++ ) { | |
ce4786b9 | 1106 | Int_t iAdc; // current ADC channel |
1107 | Int_t ap; | |
1108 | Int_t ac; | |
1109 | Int_t an; | |
1110 | Int_t mask; | |
1111 | Int_t supp; // suppression of the current channel (low active) | |
5f006bd7 | 1112 | |
ce4786b9 | 1113 | // ----- first channel ----- |
1114 | iAdc = 0; | |
5f006bd7 | 1115 | |
ce4786b9 | 1116 | ap = 0; // previous |
1117 | ac = adc[iAdc ][it]; // current | |
1118 | an = adc[iAdc+1][it]; // next | |
5f006bd7 | 1119 | |
ce4786b9 | 1120 | mask = ( ac >= ap && ac >= an ) ? 0 : 0x1; // peak center detection |
1121 | mask += ( ap + ac + an > eBIT ) ? 0 : 0x2; // cluster | |
1122 | mask += ( ac > eBIS ) ? 0 : 0x4; // absolute large peak | |
5f006bd7 | 1123 | |
ce4786b9 | 1124 | supp = (eBIL >> mask) & 1; |
5f006bd7 | 1125 | |
ce4786b9 | 1126 | fZSMap[iAdc] &= ~((1-supp) << it); |
1127 | if( eBIN == 0 ) { // neighbour sensitivity | |
1128 | fZSMap[iAdc+1] &= ~((1-supp) << it); | |
dfd03fc3 | 1129 | } |
5f006bd7 | 1130 | |
ce4786b9 | 1131 | // ----- last channel ----- |
6170d369 | 1132 | iAdc = AliTRDfeeParam::GetNadcMcm() - 1; |
5f006bd7 | 1133 | |
ce4786b9 | 1134 | ap = adc[iAdc-1][it]; // previous |
1135 | ac = adc[iAdc ][it]; // current | |
1136 | an = 0; // next | |
5f006bd7 | 1137 | |
ce4786b9 | 1138 | mask = ( ac >= ap && ac >= an ) ? 0 : 0x1; // peak center detection |
1139 | mask += ( ap + ac + an > eBIT ) ? 0 : 0x2; // cluster | |
1140 | mask += ( ac > eBIS ) ? 0 : 0x4; // absolute large peak | |
5f006bd7 | 1141 | |
ce4786b9 | 1142 | supp = (eBIL >> mask) & 1; |
5f006bd7 | 1143 | |
ce4786b9 | 1144 | fZSMap[iAdc] &= ~((1-supp) << it); |
1145 | if( eBIN == 0 ) { // neighbour sensitivity | |
1146 | fZSMap[iAdc-1] &= ~((1-supp) << it); | |
ecf39416 | 1147 | } |
5f006bd7 | 1148 | |
ce4786b9 | 1149 | // ----- middle channels ----- |
6170d369 | 1150 | for( iAdc = 1 ; iAdc < AliTRDfeeParam::GetNadcMcm()-1; iAdc++ ) { |
ce4786b9 | 1151 | ap = adc[iAdc-1][it]; // previous |
1152 | ac = adc[iAdc ][it]; // current | |
1153 | an = adc[iAdc+1][it]; // next | |
5f006bd7 | 1154 | |
ce4786b9 | 1155 | mask = ( ac >= ap && ac >= an ) ? 0 : 0x1; // peak center detection |
1156 | mask += ( ap + ac + an > eBIT ) ? 0 : 0x2; // cluster | |
1157 | mask += ( ac > eBIS ) ? 0 : 0x4; // absolute large peak | |
5f006bd7 | 1158 | |
ce4786b9 | 1159 | supp = (eBIL >> mask) & 1; |
5f006bd7 | 1160 | |
ce4786b9 | 1161 | fZSMap[iAdc] &= ~((1-supp) << it); |
1162 | if( eBIN == 0 ) { // neighbour sensitivity | |
1163 | fZSMap[iAdc-1] &= ~((1-supp) << it); | |
1164 | fZSMap[iAdc+1] &= ~((1-supp) << it); | |
ecf39416 | 1165 | } |
dfd03fc3 | 1166 | } |
ce4786b9 | 1167 | |
dfd03fc3 | 1168 | } |
1169 | } | |
1170 | ||
25b41f6f | 1171 | void AliTRDmcmSim::AddHitToFitreg(Int_t adc, UShort_t timebin, UShort_t qtot, Short_t ypos, Int_t label[]) |
dfd03fc3 | 1172 | { |
5f006bd7 | 1173 | // Add the given hit to the fit register which is lateron used for |
1174 | // the tracklet calculation. | |
1175 | // In addition to the fit sums in the fit register MC information | |
b0a41e80 | 1176 | // is stored. |
1177 | ||
759042e7 | 1178 | if ((timebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0, fDetector, fRobPos, fMcmPos)) && |
1179 | (timebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE0, fDetector, fRobPos, fMcmPos))) | |
ab9f7002 | 1180 | fFitReg[adc].fQ0 += qtot; |
5f006bd7 | 1181 | |
759042e7 | 1182 | if ((timebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS1, fDetector, fRobPos, fMcmPos)) && |
1183 | (timebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1, fDetector, fRobPos, fMcmPos))) | |
ab9f7002 | 1184 | fFitReg[adc].fQ1 += qtot; |
5f006bd7 | 1185 | |
759042e7 | 1186 | if ((timebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFS, fDetector, fRobPos, fMcmPos) ) && |
1187 | (timebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFE, fDetector, fRobPos, fMcmPos))) | |
b0a41e80 | 1188 | { |
ab9f7002 | 1189 | fFitReg[adc].fSumX += timebin; |
1190 | fFitReg[adc].fSumX2 += timebin*timebin; | |
1191 | fFitReg[adc].fNhits++; | |
1192 | fFitReg[adc].fSumY += ypos; | |
1193 | fFitReg[adc].fSumY2 += ypos*ypos; | |
1194 | fFitReg[adc].fSumXY += timebin*ypos; | |
a10c6981 | 1195 | AliDebug(10, Form("fitreg[%2i] in timebin %2i: X=%i, X2=%i, N=%i, Y=%i, Y2=%i, XY=%i, Q0=%i, Q1=%i", |
1196 | adc, timebin, fFitReg[adc].fSumX, fFitReg[adc].fSumX2, fFitReg[adc].fNhits, | |
1197 | fFitReg[adc].fSumY, fFitReg[adc].fSumY2, fFitReg[adc].fSumXY, fFitReg[adc].fQ0, fFitReg[adc].fQ1)); | |
b0a41e80 | 1198 | } |
1199 | ||
1200 | // register hits (MC info) | |
ab9f7002 | 1201 | fHits[fNHits].fChannel = adc; |
1202 | fHits[fNHits].fQtot = qtot; | |
1203 | fHits[fNHits].fYpos = ypos; | |
1204 | fHits[fNHits].fTimebin = timebin; | |
25b41f6f | 1205 | fHits[fNHits].fLabel[0] = label[0]; |
1206 | fHits[fNHits].fLabel[1] = label[1]; | |
1207 | fHits[fNHits].fLabel[2] = label[2]; | |
b0a41e80 | 1208 | fNHits++; |
1209 | } | |
dfd03fc3 | 1210 | |
5f006bd7 | 1211 | void AliTRDmcmSim::CalcFitreg() |
b0a41e80 | 1212 | { |
1213 | // Preprocessing. | |
1214 | // Detect the hits and fill the fit registers. | |
5f006bd7 | 1215 | // Requires 12-bit data from fADCF which means Filter() |
b0a41e80 | 1216 | // has to be called before even if all filters are bypassed. |
1217 | ||
b0a41e80 | 1218 | //??? to be clarified: |
64e3d742 | 1219 | UInt_t adcMask = 0xffffffff; |
5f006bd7 | 1220 | |
2b2b540f | 1221 | Bool_t hitQual; |
1222 | Int_t adcLeft, adcCentral, adcRight; | |
1223 | UShort_t timebin, adcch, timebin1, timebin2, qtotTemp; | |
b0a41e80 | 1224 | Short_t ypos, fromLeft, fromRight, found; |
5ac2e3b1 | 1225 | UShort_t qTotal[19+1]; // the last is dummy |
ab9f7002 | 1226 | UShort_t marked[6], qMarked[6], worse1, worse2; |
5f006bd7 | 1227 | |
dc1f2681 | 1228 | if (fgStoreClusters) { |
1229 | timebin1 = 0; | |
1230 | timebin2 = fNTimeBin - 1; | |
1231 | } | |
1232 | else { | |
1233 | // find first timebin to be looked at | |
1234 | timebin1 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFS, fDetector, fRobPos, fMcmPos); | |
1235 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0, fDetector, fRobPos, fMcmPos) | |
1236 | < timebin1) | |
1237 | timebin1 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0, fDetector, fRobPos, fMcmPos); | |
1238 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS1, fDetector, fRobPos, fMcmPos) | |
1239 | < timebin1) | |
1240 | timebin1 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS1, fDetector, fRobPos, fMcmPos); | |
1241 | ||
1242 | // find last timebin to be looked at | |
1243 | timebin2 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFE, fDetector, fRobPos, fMcmPos); | |
1244 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE0, fDetector, fRobPos, fMcmPos) | |
1245 | > timebin2) | |
1246 | timebin2 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE0, fDetector, fRobPos, fMcmPos); | |
1247 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1, fDetector, fRobPos, fMcmPos) | |
1248 | > timebin2) | |
1249 | timebin2 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1, fDetector, fRobPos, fMcmPos); | |
1250 | } | |
b0a41e80 | 1251 | |
1252 | // reset the fit registers | |
5f006bd7 | 1253 | fNHits = 0; |
6170d369 | 1254 | for (adcch = 0; adcch < AliTRDfeeParam::GetNadcMcm()-2; adcch++) // due to border channels |
b0a41e80 | 1255 | { |
ab9f7002 | 1256 | fFitReg[adcch].fNhits = 0; |
1257 | fFitReg[adcch].fQ0 = 0; | |
1258 | fFitReg[adcch].fQ1 = 0; | |
1259 | fFitReg[adcch].fSumX = 0; | |
1260 | fFitReg[adcch].fSumY = 0; | |
1261 | fFitReg[adcch].fSumX2 = 0; | |
1262 | fFitReg[adcch].fSumY2 = 0; | |
1263 | fFitReg[adcch].fSumXY = 0; | |
b0a41e80 | 1264 | } |
5f006bd7 | 1265 | |
b0a41e80 | 1266 | for (timebin = timebin1; timebin < timebin2; timebin++) |
1267 | { | |
ab9f7002 | 1268 | // first find the hit candidates and store the total cluster charge in qTotal array |
b0a41e80 | 1269 | // in case of not hit store 0 there. |
6170d369 | 1270 | for (adcch = 0; adcch < AliTRDfeeParam::GetNadcMcm()-2; adcch++) { |
ab9f7002 | 1271 | if ( ( (adcMask >> adcch) & 7) == 7) //??? all 3 channels are present in case of ZS |
b0a41e80 | 1272 | { |
ab9f7002 | 1273 | adcLeft = fADCF[adcch ][timebin]; |
1274 | adcCentral = fADCF[adcch+1][timebin]; | |
1275 | adcRight = fADCF[adcch+2][timebin]; | |
2b2b540f | 1276 | |
1277 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPVBY, fDetector, fRobPos, fMcmPos) == 0) { | |
1278 | // bypass the cluster verification | |
1279 | hitQual = kTRUE; | |
1280 | } | |
1281 | else { | |
5f006bd7 | 1282 | hitQual = ( (adcLeft * adcRight) < |
2b2b540f | 1283 | ((fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPVT, fDetector, fRobPos, fMcmPos) * adcCentral*adcCentral) >> 10) ); |
1284 | if (hitQual) | |
1285 | AliDebug(5, Form("cluster quality cut passed with %3i, %3i, %3i - threshold %3i -> %i", | |
1286 | adcLeft, adcCentral, adcRight, | |
1287 | fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPVT, fDetector, fRobPos, fMcmPos), | |
1288 | fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPVT, fDetector, fRobPos, fMcmPos) * adcCentral*adcCentral)); | |
1289 | } | |
1290 | ||
b0a41e80 | 1291 | // The accumulated charge is with the pedestal!!! |
ab9f7002 | 1292 | qtotTemp = adcLeft + adcCentral + adcRight; |
1293 | if ( (hitQual) && | |
759042e7 | 1294 | (qtotTemp >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPHT, fDetector, fRobPos, fMcmPos)) && |
ab9f7002 | 1295 | (adcLeft <= adcCentral) && |
1296 | (adcCentral > adcRight) ) | |
1297 | qTotal[adcch] = qtotTemp; | |
b0a41e80 | 1298 | else |
ab9f7002 | 1299 | qTotal[adcch] = 0; |
b0a41e80 | 1300 | } |
1301 | else | |
ab9f7002 | 1302 | qTotal[adcch] = 0; //jkl |
5f006bd7 | 1303 | if (qTotal[adcch] != 0) |
ce4786b9 | 1304 | AliDebug(10,Form("ch %2d qTotal %5d",adcch, qTotal[adcch])); |
b0a41e80 | 1305 | } |
dfd03fc3 | 1306 | |
b0a41e80 | 1307 | fromLeft = -1; |
1308 | adcch = 0; | |
1309 | found = 0; | |
1310 | marked[4] = 19; // invalid channel | |
1311 | marked[5] = 19; // invalid channel | |
ab9f7002 | 1312 | qTotal[19] = 0; |
b0a41e80 | 1313 | while ((adcch < 16) && (found < 3)) |
1314 | { | |
ab9f7002 | 1315 | if (qTotal[adcch] > 0) |
b0a41e80 | 1316 | { |
1317 | fromLeft = adcch; | |
1318 | marked[2*found+1]=adcch; | |
1319 | found++; | |
1320 | } | |
1321 | adcch++; | |
1322 | } | |
5f006bd7 | 1323 | |
b0a41e80 | 1324 | fromRight = -1; |
1325 | adcch = 18; | |
1326 | found = 0; | |
1327 | while ((adcch > 2) && (found < 3)) | |
1328 | { | |
ab9f7002 | 1329 | if (qTotal[adcch] > 0) |
b0a41e80 | 1330 | { |
1331 | marked[2*found]=adcch; | |
1332 | found++; | |
1333 | fromRight = adcch; | |
1334 | } | |
1335 | adcch--; | |
1336 | } | |
dfd03fc3 | 1337 | |
4ff7ed2b | 1338 | AliDebug(10,Form("Fromleft=%d, Fromright=%d",fromLeft, fromRight)); |
b0a41e80 | 1339 | // here mask the hit candidates in the middle, if any |
1340 | if ((fromLeft >= 0) && (fromRight >= 0) && (fromLeft < fromRight)) | |
1341 | for (adcch = fromLeft+1; adcch < fromRight; adcch++) | |
ab9f7002 | 1342 | qTotal[adcch] = 0; |
5f006bd7 | 1343 | |
b0a41e80 | 1344 | found = 0; |
1345 | for (adcch = 0; adcch < 19; adcch++) | |
ab9f7002 | 1346 | if (qTotal[adcch] > 0) found++; |
b0a41e80 | 1347 | // NOT READY |
1348 | ||
1349 | if (found > 4) // sorting like in the TRAP in case of 5 or 6 candidates! | |
1350 | { | |
1351 | if (marked[4] == marked[5]) marked[5] = 19; | |
1352 | for (found=0; found<6; found++) | |
1353 | { | |
ab9f7002 | 1354 | qMarked[found] = qTotal[marked[found]] >> 4; |
4ff7ed2b | 1355 | AliDebug(10,Form("ch_%d qTotal %d qTotals %d",marked[found],qTotal[marked[found]],qMarked[found])); |
b0a41e80 | 1356 | } |
5f006bd7 | 1357 | |
b0a41e80 | 1358 | Sort6To2Worst(marked[0], marked[3], marked[4], marked[1], marked[2], marked[5], |
ab9f7002 | 1359 | qMarked[0], |
1360 | qMarked[3], | |
1361 | qMarked[4], | |
1362 | qMarked[1], | |
1363 | qMarked[2], | |
1364 | qMarked[5], | |
b0a41e80 | 1365 | &worse1, &worse2); |
1366 | // Now mask the two channels with the smallest charge | |
1367 | if (worse1 < 19) | |
1368 | { | |
ab9f7002 | 1369 | qTotal[worse1] = 0; |
4ff7ed2b | 1370 | AliDebug(10,Form("Kill ch %d\n",worse1)); |
b0a41e80 | 1371 | } |
1372 | if (worse2 < 19) | |
1373 | { | |
ab9f7002 | 1374 | qTotal[worse2] = 0; |
4ff7ed2b | 1375 | AliDebug(10,Form("Kill ch %d\n",worse2)); |
b0a41e80 | 1376 | } |
1377 | } | |
5f006bd7 | 1378 | |
b0a41e80 | 1379 | for (adcch = 0; adcch < 19; adcch++) { |
ab9f7002 | 1380 | if (qTotal[adcch] > 0) // the channel is marked for processing |
b0a41e80 | 1381 | { |
ab9f7002 | 1382 | adcLeft = fADCF[adcch ][timebin]; |
1383 | adcCentral = fADCF[adcch+1][timebin]; | |
1384 | adcRight = fADCF[adcch+2][timebin]; | |
b0a41e80 | 1385 | // hit detected, in TRAP we have 4 units and a hit-selection, here we proceed all channels! |
1386 | // subtract the pedestal TPFP, clipping instead of wrapping | |
5f006bd7 | 1387 | |
759042e7 | 1388 | Int_t regTPFP = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP, fDetector, fRobPos, fMcmPos); |
4ff7ed2b | 1389 | AliDebug(10, Form("Hit found, time=%d, adcch=%d/%d/%d, adc values=%d/%d/%d, regTPFP=%d, TPHT=%d\n", |
5f006bd7 | 1390 | timebin, adcch, adcch+1, adcch+2, adcLeft, adcCentral, adcRight, regTPFP, |
759042e7 | 1391 | fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPHT, fDetector, fRobPos, fMcmPos))); |
b0a41e80 | 1392 | |
ab9f7002 | 1393 | if (adcLeft < regTPFP) adcLeft = 0; else adcLeft -= regTPFP; |
1394 | if (adcCentral < regTPFP) adcCentral = 0; else adcCentral -= regTPFP; | |
1395 | if (adcRight < regTPFP) adcRight = 0; else adcRight -= regTPFP; | |
f793c83d | 1396 | |
b0a41e80 | 1397 | // Calculate the center of gravity |
f793c83d | 1398 | // checking for adcCentral != 0 (in case of "bad" configuration) |
1399 | if (adcCentral == 0) | |
1400 | continue; | |
a10c6981 | 1401 | ypos = 128*(adcRight - adcLeft) / adcCentral; |
b0a41e80 | 1402 | if (ypos < 0) ypos = -ypos; |
ce4786b9 | 1403 | // make the correction using the position LUT |
25b41f6f | 1404 | ypos = ypos + fTrapConfig->GetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + (ypos & 0x7F)), |
1405 | fDetector, fRobPos, fMcmPos); | |
ab9f7002 | 1406 | if (adcLeft > adcRight) ypos = -ypos; |
40bd6ee4 | 1407 | |
25b41f6f | 1408 | // label calculation (up to 3) |
1409 | Int_t mcLabel[] = {-1, -1, -1}; | |
40bd6ee4 | 1410 | if (fDigitsManager) { |
25b41f6f | 1411 | const Int_t maxLabels = 9; |
1412 | Int_t label[maxLabels] = { 0 }; // up to 9 different labels possible | |
1413 | Int_t count[maxLabels] = { 0 }; | |
40bd6ee4 | 1414 | Int_t nLabels = 0; |
5f006bd7 | 1415 | Int_t padcol[3]; |
40bd6ee4 | 1416 | padcol[0] = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adcch); |
1417 | padcol[1] = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adcch+1); | |
1418 | padcol[2] = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adcch+2); | |
1419 | Int_t padrow = fFeeParam->GetPadRowFromMCM(fRobPos, fMcmPos); | |
1420 | for (Int_t iDict = 0; iDict < 3; iDict++) { | |
ce4786b9 | 1421 | if (!fDict[iDict]) |
40bd6ee4 | 1422 | continue; |
40bd6ee4 | 1423 | for (Int_t iPad = 0; iPad < 3; iPad++) { |
5f006bd7 | 1424 | if (padcol[iPad] < 0) |
40bd6ee4 | 1425 | continue; |
25b41f6f | 1426 | Int_t currLabel = fDict[iDict]->GetData(padrow, padcol[iPad], timebin); |
4ff7ed2b | 1427 | AliDebug(10, Form("Read label: %4i for det: %3i, row: %i, col: %i, tb: %i\n", currLabel, fDetector, padrow, padcol[iPad], timebin)); |
40bd6ee4 | 1428 | for (Int_t iLabel = 0; iLabel < nLabels; iLabel++) { |
1429 | if (currLabel == label[iLabel]) { | |
1430 | count[iLabel]++; | |
ce51199c | 1431 | currLabel = -1; |
40bd6ee4 | 1432 | break; |
1433 | } | |
5f006bd7 | 1434 | } |
ce51199c | 1435 | if (currLabel >= 0) { |
25b41f6f | 1436 | label[nLabels] = currLabel; |
1437 | count[nLabels] = 1; | |
1438 | nLabels++; | |
40bd6ee4 | 1439 | } |
1440 | } | |
1441 | } | |
637666cd | 1442 | Int_t index[2*maxLabels]; |
25b41f6f | 1443 | TMath::Sort(maxLabels, count, index); |
1444 | for (Int_t i = 0; i < 3; i++) { | |
1445 | if (count[index[i]] <= 0) | |
1446 | break; | |
1447 | mcLabel[i] = label[index[i]]; | |
1448 | } | |
40bd6ee4 | 1449 | } |
1450 | ||
1451 | // add the hit to the fitregister | |
a10c6981 | 1452 | AddHitToFitreg(adcch, timebin, qTotal[adcch] >> fgkAddDigits, ypos, mcLabel); |
b0a41e80 | 1453 | } |
dfd03fc3 | 1454 | } |
1455 | } | |
ce4786b9 | 1456 | |
6170d369 | 1457 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
ce4786b9 | 1458 | if (fFitReg[iAdc].fNhits != 0) { |
1459 | AliDebug(2, Form("fitreg[%i]: nHits = %i, sumX = %i, sumY = %i, sumX2 = %i, sumY2 = %i, sumXY = %i", iAdc, | |
1460 | fFitReg[iAdc].fNhits, | |
1461 | fFitReg[iAdc].fSumX, | |
1462 | fFitReg[iAdc].fSumY, | |
1463 | fFitReg[iAdc].fSumX2, | |
1464 | fFitReg[iAdc].fSumY2, | |
1465 | fFitReg[iAdc].fSumXY | |
1466 | )); | |
1467 | } | |
1468 | } | |
dfd03fc3 | 1469 | } |
1470 | ||
5f006bd7 | 1471 | void AliTRDmcmSim::TrackletSelection() |
dfd03fc3 | 1472 | { |
5f006bd7 | 1473 | // Select up to 4 tracklet candidates from the fit registers |
b0a41e80 | 1474 | // and assign them to the CPUs. |
1475 | ||
ab9f7002 | 1476 | UShort_t adcIdx, i, j, ntracks, tmp; |
1477 | UShort_t trackletCand[18][2]; // store the adcch[0] and number of hits[1] for all tracklet candidates | |
b0a41e80 | 1478 | |
1479 | ntracks = 0; | |
ab9f7002 | 1480 | for (adcIdx = 0; adcIdx < 18; adcIdx++) // ADCs |
5f006bd7 | 1481 | if ( (fFitReg[adcIdx].fNhits |
759042e7 | 1482 | >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPCL, fDetector, fRobPos, fMcmPos)) && |
ab9f7002 | 1483 | (fFitReg[adcIdx].fNhits+fFitReg[adcIdx+1].fNhits |
759042e7 | 1484 | >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPCT, fDetector, fRobPos, fMcmPos))) |
b0a41e80 | 1485 | { |
ab9f7002 | 1486 | trackletCand[ntracks][0] = adcIdx; |
1487 | trackletCand[ntracks][1] = fFitReg[adcIdx].fNhits+fFitReg[adcIdx+1].fNhits; | |
4ff7ed2b | 1488 | AliDebug(10,Form("%d %2d %4d\n", ntracks, trackletCand[ntracks][0], trackletCand[ntracks][1])); |
b0a41e80 | 1489 | ntracks++; |
1490 | }; | |
1491 | ||
5f006bd7 | 1492 | for (i=0; i<ntracks;i++) |
4ff7ed2b | 1493 | AliDebug(10,Form("%d %d %d\n",i,trackletCand[i][0], trackletCand[i][1])); |
b0a41e80 | 1494 | |
1495 | if (ntracks > 4) | |
1496 | { | |
1497 | // primitive sorting according to the number of hits | |
1498 | for (j = 0; j < (ntracks-1); j++) | |
1499 | { | |
1500 | for (i = j+1; i < ntracks; i++) | |
1501 | { | |
ab9f7002 | 1502 | if ( (trackletCand[j][1] < trackletCand[i][1]) || |
1503 | ( (trackletCand[j][1] == trackletCand[i][1]) && (trackletCand[j][0] < trackletCand[i][0]) ) ) | |
b0a41e80 | 1504 | { |
1505 | // swap j & i | |
ab9f7002 | 1506 | tmp = trackletCand[j][1]; |
1507 | trackletCand[j][1] = trackletCand[i][1]; | |
1508 | trackletCand[i][1] = tmp; | |
1509 | tmp = trackletCand[j][0]; | |
1510 | trackletCand[j][0] = trackletCand[i][0]; | |
1511 | trackletCand[i][0] = tmp; | |
b0a41e80 | 1512 | } |
1513 | } | |
1514 | } | |
1515 | ntracks = 4; // cut the rest, 4 is the max | |
dfd03fc3 | 1516 | } |
b0a41e80 | 1517 | // else is not necessary to sort |
5f006bd7 | 1518 | |
b0a41e80 | 1519 | // now sort, so that the first tracklet going to CPU0 corresponds to the highest adc channel - as in the TRAP |
1520 | for (j = 0; j < (ntracks-1); j++) | |
1521 | { | |
1522 | for (i = j+1; i < ntracks; i++) | |
1523 | { | |
ab9f7002 | 1524 | if (trackletCand[j][0] < trackletCand[i][0]) |
b0a41e80 | 1525 | { |
1526 | // swap j & i | |
ab9f7002 | 1527 | tmp = trackletCand[j][1]; |
1528 | trackletCand[j][1] = trackletCand[i][1]; | |
1529 | trackletCand[i][1] = tmp; | |
1530 | tmp = trackletCand[j][0]; | |
1531 | trackletCand[j][0] = trackletCand[i][0]; | |
1532 | trackletCand[i][0] = tmp; | |
b0a41e80 | 1533 | } |
dfd03fc3 | 1534 | } |
b0a41e80 | 1535 | } |
1536 | for (i = 0; i < ntracks; i++) // CPUs with tracklets. | |
ab9f7002 | 1537 | fFitPtr[i] = trackletCand[i][0]; // pointer to the left channel with tracklet for CPU[i] |
b0a41e80 | 1538 | for (i = ntracks; i < 4; i++) // CPUs without tracklets |
1539 | fFitPtr[i] = 31; // pointer to the left channel with tracklet for CPU[i] = 31 (invalid) | |
4ff7ed2b | 1540 | AliDebug(10,Form("found %i tracklet candidates\n", ntracks)); |
1541 | for (i = 0; i < 4; i++) | |
1542 | AliDebug(10,Form("fitPtr[%i]: %i\n", i, fFitPtr[i])); | |
b0a41e80 | 1543 | } |
dfd03fc3 | 1544 | |
b0a41e80 | 1545 | void AliTRDmcmSim::FitTracklet() |
1546 | { | |
5f006bd7 | 1547 | // Perform the actual tracklet fit based on the fit sums |
1548 | // which have been filled in the fit registers. | |
b0a41e80 | 1549 | |
1550 | // parameters in fitred.asm (fit program) | |
b0a41e80 | 1551 | Int_t rndAdd = 0; |
78c94f0b | 1552 | Int_t decPlaces = 5; // must be larger than 1 or change the following code |
1553 | // if (decPlaces > 1) | |
b0a41e80 | 1554 | rndAdd = (1 << (decPlaces-1)) + 1; |
78c94f0b | 1555 | // else if (decPlaces == 1) |
1556 | // rndAdd = 1; | |
1557 | ||
4ff7ed2b | 1558 | Int_t ndriftDp = 5; // decimal places for drift time |
1559 | Long64_t shift = ((Long64_t) 1 << 32); | |
1560 | ||
4ff7ed2b | 1561 | // calculated in fitred.asm |
1562 | Int_t padrow = ((fRobPos >> 1) << 2) | (fMcmPos >> 2); | |
5f006bd7 | 1563 | Int_t yoffs = (((((fRobPos & 0x1) << 2) + (fMcmPos & 0x3)) * 18) << 8) - |
4ff7ed2b | 1564 | ((18*4*2 - 18*2 - 1) << 7); |
1565 | yoffs = yoffs << decPlaces; // holds position of ADC channel 1 | |
1566 | Int_t layer = fDetector % 6; | |
1567 | UInt_t scaleY = (UInt_t) ((0.635 + 0.03 * layer)/(256.0 * 160.0e-4) * shift); | |
1568 | UInt_t scaleD = (UInt_t) ((0.635 + 0.03 * layer)/(256.0 * 140.0e-4) * shift); | |
4ff7ed2b | 1569 | |
2b2b540f | 1570 | Int_t deflCorr = (Int_t) fTrapConfig->GetDmemUnsigned(fgkDmemAddrDeflCorr, fDetector, fRobPos, fMcmPos); |
1571 | Int_t ndrift = (Int_t) fTrapConfig->GetDmemUnsigned(fgkDmemAddrNdrift, fDetector, fRobPos, fMcmPos); | |
b0a41e80 | 1572 | |
1573 | // local variables for calculation | |
1574 | Long64_t mult, temp, denom; //??? | |
8ea391e3 | 1575 | UInt_t q0, q1, pid; // charges in the two windows and total charge |
b0a41e80 | 1576 | UShort_t nHits; // number of hits |
1577 | Int_t slope, offset; // slope and offset of the tracklet | |
1578 | Int_t sumX, sumY, sumXY, sumX2; // fit sums from fit registers | |
ce51199c | 1579 | Int_t sumY2; // not used in the current TRAP program, now used for error calculation (simulation only) |
1580 | Float_t fitError, fitSlope, fitOffset; | |
b0a41e80 | 1581 | FitReg_t *fit0, *fit1; // pointers to relevant fit registers |
5f006bd7 | 1582 | |
b0a41e80 | 1583 | // const uint32_t OneDivN[32] = { // 2**31/N : exactly like in the TRAP, the simple division here gives the same result! |
1584 | // 0x00000000, 0x80000000, 0x40000000, 0x2AAAAAA0, 0x20000000, 0x19999990, 0x15555550, 0x12492490, | |
1585 | // 0x10000000, 0x0E38E380, 0x0CCCCCC0, 0x0BA2E8B0, 0x0AAAAAA0, 0x09D89D80, 0x09249240, 0x08888880, | |
1586 | // 0x08000000, 0x07878780, 0x071C71C0, 0x06BCA1A0, 0x06666660, 0x06186180, 0x05D17450, 0x0590B210, | |
1587 | // 0x05555550, 0x051EB850, 0x04EC4EC0, 0x04BDA120, 0x04924920, 0x0469EE50, 0x04444440, 0x04210840}; | |
1588 | ||
1589 | for (Int_t cpu = 0; cpu < 4; cpu++) { | |
1590 | if (fFitPtr[cpu] == 31) | |
1591 | { | |
5f006bd7 | 1592 | fMCMT[cpu] = 0x10001000; //??? AliTRDfeeParam::GetTrackletEndmarker(); |
dfd03fc3 | 1593 | } |
b0a41e80 | 1594 | else |
1595 | { | |
1596 | fit0 = &fFitReg[fFitPtr[cpu] ]; | |
1597 | fit1 = &fFitReg[fFitPtr[cpu]+1]; // next channel | |
1598 | ||
1599 | mult = 1; | |
1600 | mult = mult << (32 + decPlaces); | |
1601 | mult = -mult; | |
1602 | ||
1603 | // Merging | |
ab9f7002 | 1604 | nHits = fit0->fNhits + fit1->fNhits; // number of hits |
1605 | sumX = fit0->fSumX + fit1->fSumX; | |
1606 | sumX2 = fit0->fSumX2 + fit1->fSumX2; | |
f5821bdb | 1607 | denom = ((Long64_t) nHits)*((Long64_t) sumX2) - ((Long64_t) sumX)*((Long64_t) sumX); |
b0a41e80 | 1608 | |
1609 | mult = mult / denom; // exactly like in the TRAP program | |
ab9f7002 | 1610 | q0 = fit0->fQ0 + fit1->fQ0; |
1611 | q1 = fit0->fQ1 + fit1->fQ1; | |
1612 | sumY = fit0->fSumY + fit1->fSumY + 256*fit1->fNhits; | |
1613 | sumXY = fit0->fSumXY + fit1->fSumXY + 256*fit1->fSumX; | |
ce51199c | 1614 | sumY2 = fit0->fSumY2 + fit1->fSumY2 + 512*fit1->fSumY + 256*256*fit1->fNhits; |
b0a41e80 | 1615 | |
1616 | slope = nHits*sumXY - sumX * sumY; | |
1617 | offset = sumX2*sumY - sumX * sumXY; | |
1618 | temp = mult * slope; | |
1619 | slope = temp >> 32; // take the upper 32 bits | |
4ff7ed2b | 1620 | slope = -slope; |
b0a41e80 | 1621 | temp = mult * offset; |
1622 | offset = temp >> 32; // take the upper 32 bits | |
1623 | ||
4ff7ed2b | 1624 | offset = offset + yoffs; |
5f006bd7 | 1625 | AliDebug(10, Form("slope = %i, slope * ndrift = %i, deflCorr: %i", |
ce4786b9 | 1626 | slope, slope * ndrift, deflCorr)); |
1627 | slope = ((slope * ndrift) >> ndriftDp) + deflCorr; | |
b0a41e80 | 1628 | offset = offset - (fFitPtr[cpu] << (8 + decPlaces)); |
5f006bd7 | 1629 | |
4ff7ed2b | 1630 | temp = slope; |
1631 | temp = temp * scaleD; | |
1632 | slope = (temp >> 32); | |
4ff7ed2b | 1633 | temp = offset; |
1634 | temp = temp * scaleY; | |
1635 | offset = (temp >> 32); | |
5f006bd7 | 1636 | |
4ff7ed2b | 1637 | // rounding, like in the TRAP |
1638 | slope = (slope + rndAdd) >> decPlaces; | |
4ff7ed2b | 1639 | offset = (offset + rndAdd) >> decPlaces; |
1640 | ||
5f006bd7 | 1641 | AliDebug(5, Form("Det: %3i, ROB: %i, MCM: %2i: deflection: %i, min: %i, max: %i", |
1642 | fDetector, fRobPos, fMcmPos, slope, | |
2b2b540f | 1643 | (Int_t) fTrapConfig->GetDmemUnsigned(fgkDmemAddrDeflCutStart + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos), |
1644 | (Int_t) fTrapConfig->GetDmemUnsigned(fgkDmemAddrDeflCutStart + 1 + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos))); | |
ce4786b9 | 1645 | |
5f006bd7 | 1646 | AliDebug(5, Form("Fit sums: x = %i, X = %i, y = %i, Y = %i, Z = %i", |
ce51199c | 1647 | sumX, sumX2, sumY, sumY2, sumXY)); |
1648 | ||
1649 | fitSlope = (Float_t) (nHits * sumXY - sumX * sumY) / (nHits * sumX2 - sumX*sumX); | |
1650 | ||
1651 | fitOffset = (Float_t) (sumX2 * sumY - sumX * sumXY) / (nHits * sumX2 - sumX*sumX); | |
1652 | ||
1653 | Float_t sx = (Float_t) sumX; | |
1654 | Float_t sx2 = (Float_t) sumX2; | |
1655 | Float_t sy = (Float_t) sumY; | |
1656 | Float_t sy2 = (Float_t) sumY2; | |
1657 | Float_t sxy = (Float_t) sumXY; | |
1658 | fitError = sy2 - (sx2 * sy*sy - 2 * sx * sxy * sy + nHits * sxy*sxy) / (nHits * sx2 - sx*sx); | |
1659 | //fitError = (Float_t) sumY2 - (Float_t) (sumY*sumY) / nHits - fitSlope * ((Float_t) (sumXY - sumX*sumY) / nHits); | |
1660 | ||
40bd6ee4 | 1661 | Bool_t rejected = kFALSE; |
ce4786b9 | 1662 | // deflection range table from DMEM |
2b2b540f | 1663 | if ((slope < ((Int_t) fTrapConfig->GetDmemUnsigned(fgkDmemAddrDeflCutStart + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos))) || |
1664 | (slope > ((Int_t) fTrapConfig->GetDmemUnsigned(fgkDmemAddrDeflCutStart + 1 + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos)))) | |
40bd6ee4 | 1665 | rejected = kTRUE; |
4ff7ed2b | 1666 | |
1667 | if (rejected && GetApplyCut()) | |
b0a41e80 | 1668 | { |
1669 | fMCMT[cpu] = 0x10001000; //??? AliTRDfeeParam::GetTrackletEndmarker(); | |
1670 | } | |
1671 | else | |
1672 | { | |
4ff7ed2b | 1673 | if (slope > 63 || slope < -64) { // wrapping in TRAP! |
27a030ab | 1674 | AliDebug(1,Form("Overflow in slope: %i, tracklet discarded!", slope)); |
40bd6ee4 | 1675 | fMCMT[cpu] = 0x10001000; |
1676 | continue; | |
1677 | } | |
b0a41e80 | 1678 | |
4ff7ed2b | 1679 | slope = slope & 0x7F; // 7 bit |
5f006bd7 | 1680 | |
1681 | if (offset > 0xfff || offset < -0xfff) | |
b0a41e80 | 1682 | AliWarning("Overflow in offset"); |
1683 | offset = offset & 0x1FFF; // 13 bit | |
1684 | ||
a10c6981 | 1685 | pid = GetPID(q0, q1); |
4ff7ed2b | 1686 | |
8ea391e3 | 1687 | if (pid > 0xff) |
1688 | AliWarning("Overflow in PID"); | |
1689 | pid = pid & 0xFF; // 8 bit, exactly like in the TRAP program | |
5f006bd7 | 1690 | |
b0a41e80 | 1691 | // assemble and store the tracklet word |
8ea391e3 | 1692 | fMCMT[cpu] = (pid << 24) | (padrow << 20) | (slope << 13) | offset; |
40bd6ee4 | 1693 | |
1694 | // calculate MC label | |
25b41f6f | 1695 | Int_t mcLabel[] = { -1, -1, -1}; |
4ff7ed2b | 1696 | Int_t nHits0 = 0; |
1697 | Int_t nHits1 = 0; | |
40bd6ee4 | 1698 | if (fDigitsManager) { |
25b41f6f | 1699 | const Int_t maxLabels = 30; |
1700 | Int_t label[maxLabels] = {0}; // up to 30 different labels possible | |
1701 | Int_t count[maxLabels] = {0}; | |
40bd6ee4 | 1702 | Int_t nLabels = 0; |
1703 | for (Int_t iHit = 0; iHit < fNHits; iHit++) { | |
1704 | if ((fHits[iHit].fChannel - fFitPtr[cpu] < 0) || | |
1705 | (fHits[iHit].fChannel - fFitPtr[cpu] > 1)) | |
1706 | continue; | |
4ff7ed2b | 1707 | |
1708 | // counting contributing hits | |
759042e7 | 1709 | if (fHits[iHit].fTimebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0, fDetector, fRobPos, fMcmPos) && |
1710 | fHits[iHit].fTimebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE0, fDetector, fRobPos, fMcmPos)) | |
4ff7ed2b | 1711 | nHits0++; |
759042e7 | 1712 | if (fHits[iHit].fTimebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS1, fDetector, fRobPos, fMcmPos) && |
1713 | fHits[iHit].fTimebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1, fDetector, fRobPos, fMcmPos)) | |
4ff7ed2b | 1714 | nHits1++; |
1715 | ||
25b41f6f | 1716 | for (Int_t i = 0; i < 3; i++) { |
1717 | Int_t currLabel = fHits[iHit].fLabel[i]; | |
1718 | for (Int_t iLabel = 0; iLabel < nLabels; iLabel++) { | |
1719 | if (currLabel == label[iLabel]) { | |
1720 | count[iLabel]++; | |
1721 | currLabel = -1; | |
1722 | break; | |
1723 | } | |
1724 | } | |
1725 | if (currLabel >= 0 && nLabels < maxLabels) { | |
1726 | label[nLabels] = currLabel; | |
1727 | count[nLabels]++; | |
1728 | nLabels++; | |
1729 | } | |
1730 | } | |
1731 | } | |
637666cd | 1732 | Int_t index[2*maxLabels]; |
25b41f6f | 1733 | TMath::Sort(maxLabels, count, index); |
1734 | for (Int_t i = 0; i < 3; i++) { | |
1735 | if (count[index[i]] <= 0) | |
1736 | break; | |
1737 | mcLabel[i] = label[index[i]]; | |
1738 | } | |
40bd6ee4 | 1739 | } |
f793c83d | 1740 | new ((*fTrackletArray)[fTrackletArray->GetEntriesFast()]) AliTRDtrackletMCM((UInt_t) fMCMT[cpu], fDetector*2 + fRobPos%2, fRobPos, fMcmPos); |
40bd6ee4 | 1741 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetLabel(mcLabel); |
4ff7ed2b | 1742 | |
5f006bd7 | 1743 | |
4ff7ed2b | 1744 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetNHits(fit0->fNhits + fit1->fNhits); |
1745 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetNHits0(nHits0); | |
1746 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetNHits1(nHits1); | |
a10c6981 | 1747 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetQ0(q0); |
1748 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetQ1(q1); | |
ce51199c | 1749 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetSlope(fitSlope); |
1750 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetOffset(fitOffset); | |
1751 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetError(TMath::Sqrt(TMath::Abs(fitError)/nHits)); | |
1752 | ||
dc1f2681 | 1753 | // store cluster information (if requested) |
1754 | if (fgStoreClusters) { | |
1755 | Float_t *res = new Float_t[fNTimeBin]; | |
1756 | Float_t *qtot = new Float_t[fNTimeBin]; | |
1757 | for (Int_t iTimebin = 0; iTimebin < fNTimeBin; ++iTimebin) { | |
1758 | res[iTimebin] = 0; | |
1759 | qtot[iTimebin] = 0; | |
1760 | } | |
1761 | for (Int_t iHit = 0; iHit < fNHits; iHit++) { | |
1762 | Int_t timebin = fHits[iHit].fTimebin; | |
1763 | ||
1764 | // check if hit contributes | |
1765 | if (fHits[iHit].fChannel == fFitPtr[cpu]) { | |
1766 | res[timebin] = fHits[iHit].fYpos - (fitSlope * timebin + fitOffset); | |
1767 | qtot[timebin] = fHits[iHit].fQtot; | |
1768 | } | |
1769 | else if (fHits[iHit].fChannel == fFitPtr[cpu] + 1) { | |
1770 | res[timebin] = fHits[iHit].fYpos + 256 - (fitSlope * timebin + fitOffset); | |
1771 | qtot[timebin] = fHits[iHit].fQtot; | |
1772 | } | |
1773 | } | |
1774 | ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetClusters(res, qtot, fNTimeBin); | |
1775 | delete [] res; | |
1776 | delete [] qtot; | |
1777 | } | |
ce51199c | 1778 | |
1779 | if (fitError < 0) | |
1780 | AliError(Form("Strange fit error: %f from Sx: %i, Sy: %i, Sxy: %i, Sx2: %i, Sy2: %i, nHits: %i", | |
1781 | fitError, sumX, sumY, sumXY, sumX2, sumY2, nHits)); | |
5f006bd7 | 1782 | AliDebug(3, Form("fit slope: %f, offset: %f, error: %f", |
ce51199c | 1783 | fitSlope, fitOffset, TMath::Sqrt(TMath::Abs(fitError)/nHits))); |
b0a41e80 | 1784 | } |
dfd03fc3 | 1785 | } |
dfd03fc3 | 1786 | } |
1787 | } | |
1788 | ||
b0a41e80 | 1789 | void AliTRDmcmSim::Tracklet() |
dfd03fc3 | 1790 | { |
ab9f7002 | 1791 | // Run the tracklet calculation by calling sequentially: |
1792 | // CalcFitreg(); TrackletSelection(); FitTracklet() | |
5f006bd7 | 1793 | // and store the tracklets |
ab9f7002 | 1794 | |
b0a41e80 | 1795 | if (!fInitialized) { |
ab9f7002 | 1796 | AliError("Called uninitialized! Nothing done!"); |
b0a41e80 | 1797 | return; |
dfd03fc3 | 1798 | } |
1799 | ||
b0a41e80 | 1800 | fTrackletArray->Delete(); |
dfd03fc3 | 1801 | |
b0a41e80 | 1802 | CalcFitreg(); |
40bd6ee4 | 1803 | if (fNHits == 0) |
1804 | return; | |
b0a41e80 | 1805 | TrackletSelection(); |
1806 | FitTracklet(); | |
c8b1590d | 1807 | } |
1808 | ||
5f006bd7 | 1809 | Bool_t AliTRDmcmSim::StoreTracklets() |
c8b1590d | 1810 | { |
36dc3337 | 1811 | // store the found tracklets via the loader |
1812 | ||
5f006bd7 | 1813 | if (fTrackletArray->GetEntriesFast() == 0) |
c8b1590d | 1814 | return kTRUE; |
dfd03fc3 | 1815 | |
b0a41e80 | 1816 | AliRunLoader *rl = AliRunLoader::Instance(); |
1817 | AliDataLoader *dl = 0x0; | |
1818 | if (rl) | |
1819 | dl = rl->GetLoader("TRDLoader")->GetDataLoader("tracklets"); | |
1820 | if (!dl) { | |
1821 | AliError("Could not get the tracklets data loader!"); | |
c8b1590d | 1822 | return kFALSE; |
dfd03fc3 | 1823 | } |
b0a41e80 | 1824 | |
c8b1590d | 1825 | TTree *trackletTree = dl->Tree(); |
1826 | if (!trackletTree) { | |
1827 | dl->MakeTree(); | |
1828 | trackletTree = dl->Tree(); | |
1829 | } | |
5f006bd7 | 1830 | |
c8b1590d | 1831 | AliTRDtrackletMCM *trkl = 0x0; |
6b094867 | 1832 | TBranch *trkbranch = trackletTree->GetBranch(fTrklBranchName.Data()); |
c8b1590d | 1833 | if (!trkbranch) |
6b094867 | 1834 | trkbranch = trackletTree->Branch(fTrklBranchName.Data(), "AliTRDtrackletMCM", &trkl, 32000); |
5f006bd7 | 1835 | |
c8b1590d | 1836 | for (Int_t iTracklet = 0; iTracklet < fTrackletArray->GetEntriesFast(); iTracklet++) { |
1837 | trkl = ((AliTRDtrackletMCM*) (*fTrackletArray)[iTracklet]); | |
1838 | trkbranch->SetAddress(&trkl); | |
c8b1590d | 1839 | trkbranch->Fill(); |
b0a41e80 | 1840 | } |
c8b1590d | 1841 | |
1842 | return kTRUE; | |
dfd03fc3 | 1843 | } |
1844 | ||
b0a41e80 | 1845 | void AliTRDmcmSim::WriteData(AliTRDarrayADC *digits) |
dfd03fc3 | 1846 | { |
b0a41e80 | 1847 | // write back the processed data configured by EBSF |
1848 | // EBSF = 1: unfiltered data; EBSF = 0: filtered data | |
1849 | // zero-suppressed valued are written as -1 to digits | |
dfd03fc3 | 1850 | |
5f006bd7 | 1851 | if( !CheckInitialized() ) |
b0a41e80 | 1852 | return; |
dfd03fc3 | 1853 | |
ce4786b9 | 1854 | Int_t offset = (fMcmPos % 4 + 1) * 21 + (fRobPos % 2) * 84 - 1; |
dfd03fc3 | 1855 | |
759042e7 | 1856 | if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBSF, fDetector, fRobPos, fMcmPos) != 0) // store unfiltered data |
b0a41e80 | 1857 | { |
6170d369 | 1858 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
ce4786b9 | 1859 | if (~fZSMap[iAdc] == 0) { |
b0a41e80 | 1860 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
ce4786b9 | 1861 | digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, -1); |
b0a41e80 | 1862 | } |
1863 | } | |
ce51199c | 1864 | else if (iAdc < 2 || iAdc == 20) { |
1865 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
1866 | digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, (fADCR[iAdc][iTimeBin] >> fgkAddDigits) - fgAddBaseline); | |
1867 | } | |
1868 | } | |
b0a41e80 | 1869 | } |
1870 | } | |
1871 | else { | |
6170d369 | 1872 | for (Int_t iAdc = 0; iAdc < AliTRDfeeParam::GetNadcMcm(); iAdc++) { |
ce4786b9 | 1873 | if (~fZSMap[iAdc] != 0) { |
b0a41e80 | 1874 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
ce4786b9 | 1875 | digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, (fADCF[iAdc][iTimeBin] >> fgkAddDigits) - fgAddBaseline); |
b0a41e80 | 1876 | } |
1877 | } | |
1878 | else { | |
1879 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
ce4786b9 | 1880 | digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, -1); |
b0a41e80 | 1881 | } |
1882 | } | |
1883 | } | |
dfd03fc3 | 1884 | } |
b0a41e80 | 1885 | } |
dfd03fc3 | 1886 | |
8ea391e3 | 1887 | |
1888 | // ****************************** | |
1889 | // PID section | |
1890 | // | |
1891 | // Memory area for the LUT: 0xC100 to 0xC3FF | |
1892 | // | |
1893 | // The addresses for the parameters (the order is optimized for maximum calculation speed in the MCMs): | |
1894 | // 0xC028: cor1 | |
1895 | // 0xC029: nBins(sF) | |
1896 | // 0xC02A: cor0 | |
1897 | // 0xC02B: TableLength | |
1898 | // Defined in AliTRDtrapConfig.h | |
1899 | // | |
1900 | // The algorithm implemented in the TRAP program of the MCMs (Venelin Angelov) | |
1901 | // 1) set the read pointer to the beginning of the Parameters in DMEM | |
1902 | // 2) shift right the FitReg with the Q0 + (Q1 << 16) to get Q1 | |
1903 | // 3) read cor1 with rpointer++ | |
1904 | // 4) start cor1*Q1 | |
1905 | // 5) read nBins with rpointer++ | |
1906 | // 6) start nBins*cor1*Q1 | |
1907 | // 7) read cor0 with rpointer++ | |
1908 | // 8) swap hi-low parts in FitReg, now is Q1 + (Q0 << 16) | |
1909 | // 9) shift right to get Q0 | |
1910 | // 10) start cor0*Q0 | |
1911 | // 11) read TableLength | |
1912 | // 12) compare cor0*Q0 with nBins | |
1913 | // 13) if >=, clip cor0*Q0 to nBins-1 | |
1914 | // 14) add cor0*Q0 to nBins*cor1*Q1 | |
1915 | // 15) compare the result with TableLength | |
1916 | // 16) if >=, clip to TableLength-1 | |
1917 | // 17) read from the LUT 8 bits | |
1918 | ||
1919 | ||
1920 | Int_t AliTRDmcmSim::GetPID(Int_t q0, Int_t q1) | |
1921 | { | |
6b094867 | 1922 | // return PID calculated from charges accumulated in two time windows |
1923 | ||
8ea391e3 | 1924 | ULong64_t addrQ0; |
1925 | ULong64_t addr; | |
1926 | ||
2b2b540f | 1927 | UInt_t nBinsQ0 = fTrapConfig->GetDmemUnsigned(fgkDmemAddrLUTnbins, fDetector, fRobPos, fMcmPos); // number of bins in q0 / 4 !! |
1928 | UInt_t pidTotalSize = fTrapConfig->GetDmemUnsigned(fgkDmemAddrLUTLength, fDetector, fRobPos, fMcmPos); | |
27a030ab | 1929 | if(nBinsQ0==0 || pidTotalSize==0) // make sure we don't run into trouble if the value for Q0 is not configured |
1930 | return 0; // Q1 not configured is ok for 1D LUT | |
8ea391e3 | 1931 | |
2b2b540f | 1932 | ULong_t corrQ0 = fTrapConfig->GetDmemUnsigned(fgkDmemAddrLUTcor0, fDetector, fRobPos, fMcmPos); |
1933 | ULong_t corrQ1 = fTrapConfig->GetDmemUnsigned(fgkDmemAddrLUTcor1, fDetector, fRobPos, fMcmPos); | |
27a030ab | 1934 | if(corrQ0==0) // make sure we don't run into trouble if one of the values is not configured |
5ac2e3b1 | 1935 | return 0; |
8ea391e3 | 1936 | |
1937 | addrQ0 = corrQ0; | |
1938 | addrQ0 = (((addrQ0*q0)>>16)>>16); // because addrQ0 = (q0 * corrQ0) >> 32; does not work for unknown reasons | |
8ea391e3 | 1939 | |
1940 | if(addrQ0 >= nBinsQ0) { // check for overflow | |
e3bd81f7 | 1941 | AliDebug(5,Form("Overflow in q0: %llu/4 is bigger then %u", addrQ0, nBinsQ0)); |
8ea391e3 | 1942 | addrQ0 = nBinsQ0 -1; |
5f006bd7 | 1943 | } |
8ea391e3 | 1944 | |
1945 | addr = corrQ1; | |
1946 | addr = (((addr*q1)>>16)>>16); | |
1947 | addr = addrQ0 + nBinsQ0*addr; // because addr = addrQ0 + nBinsQ0* (((corrQ1*q1)>>32); does not work | |
8ea391e3 | 1948 | |
1949 | if(addr >= pidTotalSize) { | |
e3bd81f7 | 1950 | AliDebug(5,Form("Overflow in q1. Address %llu/4 is bigger then %u", addr, pidTotalSize)); |
8ea391e3 | 1951 | addr = pidTotalSize -1; |
5f006bd7 | 1952 | } |
8ea391e3 | 1953 | |
1954 | // For a LUT with 11 input and 8 output bits, the first memory address is set to LUT[0] | (LUT[1] << 8) | (LUT[2] << 16) | (LUT[3] << 24) | |
1955 | // and so on | |
2b2b540f | 1956 | UInt_t result = fTrapConfig->GetDmemUnsigned(fgkDmemAddrLUTStart+(addr/4), fDetector, fRobPos, fMcmPos); |
8ea391e3 | 1957 | return (result>>((addr%4)*8)) & 0xFF; |
1958 | } | |
1959 | ||
1960 | ||
1961 | ||
b0a41e80 | 1962 | // help functions, to be cleaned up |
1963 | ||
ab9f7002 | 1964 | UInt_t AliTRDmcmSim::AddUintClipping(UInt_t a, UInt_t b, UInt_t nbits) const |
b0a41e80 | 1965 | { |
5f006bd7 | 1966 | // |
1967 | // This function adds a and b (unsigned) and clips to | |
1968 | // the specified number of bits. | |
1969 | // | |
b0a41e80 | 1970 | |
1971 | UInt_t sum = a + b; | |
1972 | if (nbits < 32) | |
1973 | { | |
1974 | UInt_t maxv = (1 << nbits) - 1;; | |
5f006bd7 | 1975 | if (sum > maxv) |
b0a41e80 | 1976 | sum = maxv; |
1977 | } | |
1978 | else | |
1979 | { | |
5f006bd7 | 1980 | if ((sum < a) || (sum < b)) |
b0a41e80 | 1981 | sum = 0xFFFFFFFF; |
1982 | } | |
1983 | return sum; | |
dfd03fc3 | 1984 | } |
1985 | ||
982869bc | 1986 | void AliTRDmcmSim::Sort2(UShort_t idx1i, UShort_t idx2i, \ |
1987 | UShort_t val1i, UShort_t val2i, \ | |
6b094867 | 1988 | UShort_t * const idx1o, UShort_t * const idx2o, \ |
1989 | UShort_t * const val1o, UShort_t * const val2o) const | |
dfd03fc3 | 1990 | { |
ab9f7002 | 1991 | // sorting for tracklet selection |
dfd03fc3 | 1992 | |
b0a41e80 | 1993 | if (val1i > val2i) |
1994 | { | |
1995 | *idx1o = idx1i; | |
1996 | *idx2o = idx2i; | |
1997 | *val1o = val1i; | |
1998 | *val2o = val2i; | |
1999 | } | |
2000 | else | |
2001 | { | |
2002 | *idx1o = idx2i; | |
2003 | *idx2o = idx1i; | |
2004 | *val1o = val2i; | |
2005 | *val2o = val1i; | |
2006 | } | |
2007 | } | |
2008 | ||
982869bc | 2009 | void AliTRDmcmSim::Sort3(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, \ |
2010 | UShort_t val1i, UShort_t val2i, UShort_t val3i, \ | |
6b094867 | 2011 | UShort_t * const idx1o, UShort_t * const idx2o, UShort_t * const idx3o, \ |
2012 | UShort_t * const val1o, UShort_t * const val2o, UShort_t * const val3o) | |
b0a41e80 | 2013 | { |
ab9f7002 | 2014 | // sorting for tracklet selection |
2015 | ||
4ff7ed2b | 2016 | Int_t sel; |
dfd03fc3 | 2017 | |
dfd03fc3 | 2018 | |
b0a41e80 | 2019 | if (val1i > val2i) sel=4; else sel=0; |
2020 | if (val2i > val3i) sel=sel + 2; | |
2021 | if (val3i > val1i) sel=sel + 1; | |
b0a41e80 | 2022 | switch(sel) |
2023 | { | |
2024 | case 6 : // 1 > 2 > 3 => 1 2 3 | |
2025 | case 0 : // 1 = 2 = 3 => 1 2 3 : in this case doesn't matter, but so is in hardware! | |
2026 | *idx1o = idx1i; | |
2027 | *idx2o = idx2i; | |
2028 | *idx3o = idx3i; | |
2029 | *val1o = val1i; | |
2030 | *val2o = val2i; | |
2031 | *val3o = val3i; | |
2032 | break; | |
2033 | ||
2034 | case 4 : // 1 > 2, 2 <= 3, 3 <= 1 => 1 3 2 | |
2035 | *idx1o = idx1i; | |
2036 | *idx2o = idx3i; | |
2037 | *idx3o = idx2i; | |
2038 | *val1o = val1i; | |
2039 | *val2o = val3i; | |
2040 | *val3o = val2i; | |
2041 | break; | |
2042 | ||
2043 | case 2 : // 1 <= 2, 2 > 3, 3 <= 1 => 2 1 3 | |
2044 | *idx1o = idx2i; | |
2045 | *idx2o = idx1i; | |
2046 | *idx3o = idx3i; | |
2047 | *val1o = val2i; | |
2048 | *val2o = val1i; | |
2049 | *val3o = val3i; | |
2050 | break; | |
2051 | ||
2052 | case 3 : // 1 <= 2, 2 > 3, 3 > 1 => 2 3 1 | |
2053 | *idx1o = idx2i; | |
2054 | *idx2o = idx3i; | |
2055 | *idx3o = idx1i; | |
2056 | *val1o = val2i; | |
2057 | *val2o = val3i; | |
2058 | *val3o = val1i; | |
2059 | break; | |
2060 | ||
2061 | case 1 : // 1 <= 2, 2 <= 3, 3 > 1 => 3 2 1 | |
2062 | *idx1o = idx3i; | |
2063 | *idx2o = idx2i; | |
2064 | *idx3o = idx1i; | |
2065 | *val1o = val3i; | |
2066 | *val2o = val2i; | |
2067 | *val3o = val1i; | |
2068 | break; | |
2069 | ||
2070 | case 5 : // 1 > 2, 2 <= 3, 3 > 1 => 3 1 2 | |
2071 | *idx1o = idx3i; | |
2072 | *idx2o = idx1i; | |
2073 | *idx3o = idx2i; | |
2074 | *val1o = val3i; | |
2075 | *val2o = val1i; | |
2076 | *val3o = val2i; | |
2077 | break; | |
2078 | ||
2079 | default: // the rest should NEVER happen! | |
40bd6ee4 | 2080 | AliError("ERROR in Sort3!!!\n"); |
b0a41e80 | 2081 | break; |
2082 | } | |
b0a41e80 | 2083 | } |
dfd03fc3 | 2084 | |
982869bc | 2085 | void AliTRDmcmSim::Sort6To4(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, UShort_t idx4i, UShort_t idx5i, UShort_t idx6i, \ |
2086 | UShort_t val1i, UShort_t val2i, UShort_t val3i, UShort_t val4i, UShort_t val5i, UShort_t val6i, \ | |
6b094867 | 2087 | UShort_t * const idx1o, UShort_t * const idx2o, UShort_t * const idx3o, UShort_t * const idx4o, \ |
2088 | UShort_t * const val1o, UShort_t * const val2o, UShort_t * const val3o, UShort_t * const val4o) | |
b0a41e80 | 2089 | { |
ab9f7002 | 2090 | // sorting for tracklet selection |
dfd03fc3 | 2091 | |
982869bc | 2092 | UShort_t idx21s, idx22s, idx23s, dummy; |
2093 | UShort_t val21s, val22s, val23s; | |
2094 | UShort_t idx23as, idx23bs; | |
2095 | UShort_t val23as, val23bs; | |
dfd03fc3 | 2096 | |
b0a41e80 | 2097 | Sort3(idx1i, idx2i, idx3i, val1i, val2i, val3i, |
2098 | idx1o, &idx21s, &idx23as, | |
2099 | val1o, &val21s, &val23as); | |
dfd03fc3 | 2100 | |
b0a41e80 | 2101 | Sort3(idx4i, idx5i, idx6i, val4i, val5i, val6i, |
2102 | idx2o, &idx22s, &idx23bs, | |
2103 | val2o, &val22s, &val23bs); | |
2104 | ||
2105 | Sort2(idx23as, idx23bs, val23as, val23bs, &idx23s, &dummy, &val23s, &dummy); | |
2106 | ||
2107 | Sort3(idx21s, idx22s, idx23s, val21s, val22s, val23s, | |
2108 | idx3o, idx4o, &dummy, | |
2109 | val3o, val4o, &dummy); | |
dfd03fc3 | 2110 | |
dfd03fc3 | 2111 | } |
2112 | ||
982869bc | 2113 | void AliTRDmcmSim::Sort6To2Worst(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, UShort_t idx4i, UShort_t idx5i, UShort_t idx6i, \ |
2114 | UShort_t val1i, UShort_t val2i, UShort_t val3i, UShort_t val4i, UShort_t val5i, UShort_t val6i, \ | |
6b094867 | 2115 | UShort_t * const idx5o, UShort_t * const idx6o) |
b0a41e80 | 2116 | { |
ab9f7002 | 2117 | // sorting for tracklet selection |
1d93b218 | 2118 | |
982869bc | 2119 | UShort_t idx21s, idx22s, idx23s, dummy1, dummy2, dummy3, dummy4, dummy5; |
2120 | UShort_t val21s, val22s, val23s; | |
2121 | UShort_t idx23as, idx23bs; | |
2122 | UShort_t val23as, val23bs; | |
1d93b218 | 2123 | |
b0a41e80 | 2124 | Sort3(idx1i, idx2i, idx3i, val1i, val2i, val3i, |
2125 | &dummy1, &idx21s, &idx23as, | |
2126 | &dummy2, &val21s, &val23as); | |
1d93b218 | 2127 | |
b0a41e80 | 2128 | Sort3(idx4i, idx5i, idx6i, val4i, val5i, val6i, |
2129 | &dummy1, &idx22s, &idx23bs, | |
2130 | &dummy2, &val22s, &val23bs); | |
1d93b218 | 2131 | |
b0a41e80 | 2132 | Sort2(idx23as, idx23bs, val23as, val23bs, &idx23s, idx5o, &val23s, &dummy1); |
b65e5048 | 2133 | |
b0a41e80 | 2134 | Sort3(idx21s, idx22s, idx23s, val21s, val22s, val23s, |
2135 | &dummy1, &dummy2, idx6o, | |
2136 | &dummy3, &dummy4, &dummy5); | |
0d64b05f | 2137 | } |
f793c83d | 2138 | |
2139 | ||
ce4786b9 | 2140 | // ----- I/O implementation ----- |
2141 | ||
59f78ad5 | 2142 | ostream& AliTRDmcmSim::Text(ostream& os) |
ce4786b9 | 2143 | { |
2144 | // manipulator to activate output in text format (default) | |
2145 | ||
2146 | os.iword(fgkFormatIndex) = 0; | |
2147 | return os; | |
2148 | } | |
2149 | ||
59f78ad5 | 2150 | ostream& AliTRDmcmSim::Cfdat(ostream& os) |
ce4786b9 | 2151 | { |
5f006bd7 | 2152 | // manipulator to activate output in CFDAT format |
ce4786b9 | 2153 | // to send to the FEE via SCSN |
2154 | ||
5f006bd7 | 2155 | os.iword(fgkFormatIndex) = 1; |
ce4786b9 | 2156 | return os; |
2157 | } | |
2158 | ||
59f78ad5 | 2159 | ostream& AliTRDmcmSim::Raw(ostream& os) |
ce4786b9 | 2160 | { |
2161 | // manipulator to activate output as raw data dump | |
2162 | ||
2163 | os.iword(fgkFormatIndex) = 2; | |
2164 | return os; | |
2165 | } | |
2166 | ||
2167 | ostream& operator<<(ostream& os, const AliTRDmcmSim& mcm) | |
2168 | { | |
2169 | // output implementation | |
5f006bd7 | 2170 | |
ce4786b9 | 2171 | // no output for non-initialized MCM |
2172 | if (!mcm.CheckInitialized()) | |
2173 | return os; | |
2174 | ||
2175 | // ----- human-readable output ----- | |
2176 | if (os.iword(AliTRDmcmSim::fgkFormatIndex) == 0) { | |
5f006bd7 | 2177 | |
2178 | os << "MCM " << mcm.fMcmPos << " on ROB " << mcm.fRobPos << | |
ce4786b9 | 2179 | " in detector " << mcm.fDetector << std::endl; |
5f006bd7 | 2180 | |
ce4786b9 | 2181 | os << "----- Unfiltered ADC data (10 bit) -----" << std::endl; |
2182 | os << "ch "; | |
6170d369 | 2183 | for (Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) |
ce4786b9 | 2184 | os << std::setw(5) << iChannel; |
2185 | os << std::endl; | |
2186 | for (Int_t iTimeBin = 0; iTimeBin < mcm.fNTimeBin; iTimeBin++) { | |
2187 | os << "tb " << std::setw(2) << iTimeBin << ":"; | |
6170d369 | 2188 | for (Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) { |
ce4786b9 | 2189 | os << std::setw(5) << (mcm.fADCR[iChannel][iTimeBin] >> mcm.fgkAddDigits); |
2190 | } | |
2191 | os << std::endl; | |
2192 | } | |
5f006bd7 | 2193 | |
ce4786b9 | 2194 | os << "----- Filtered ADC data (10+2 bit) -----" << std::endl; |
2195 | os << "ch "; | |
6170d369 | 2196 | for (Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) |
ce4786b9 | 2197 | os << std::setw(4) << iChannel |
2198 | << ((~mcm.fZSMap[iChannel] != 0) ? "!" : " "); | |
2199 | os << std::endl; | |
2200 | for (Int_t iTimeBin = 0; iTimeBin < mcm.fNTimeBin; iTimeBin++) { | |
2201 | os << "tb " << std::setw(2) << iTimeBin << ":"; | |
6170d369 | 2202 | for (Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) { |
ce4786b9 | 2203 | os << std::setw(4) << (mcm.fADCF[iChannel][iTimeBin]) |
2204 | << (((mcm.fZSMap[iChannel] & (1 << iTimeBin)) == 0) ? "!" : " "); | |
2205 | } | |
2206 | os << std::endl; | |
2207 | } | |
2208 | } | |
2209 | ||
2210 | // ----- CFDAT output ----- | |
2211 | else if(os.iword(AliTRDmcmSim::fgkFormatIndex) == 1) { | |
2212 | Int_t dest = 127; | |
2213 | Int_t addrOffset = 0x2000; | |
2214 | Int_t addrStep = 0x80; | |
5f006bd7 | 2215 | |
ce4786b9 | 2216 | for (Int_t iTimeBin = 0; iTimeBin < mcm.fNTimeBin; iTimeBin++) { |
6170d369 | 2217 | for (Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) { |
5f006bd7 | 2218 | os << std::setw(5) << 10 |
2219 | << std::setw(5) << addrOffset + iChannel * addrStep + iTimeBin | |
ce4786b9 | 2220 | << std::setw(5) << (mcm.fADCF[iChannel][iTimeBin]) |
2221 | << std::setw(5) << dest << std::endl; | |
2222 | } | |
2223 | os << std::endl; | |
2224 | } | |
2225 | } | |
2226 | ||
2227 | // ----- raw data ouptut ----- | |
2228 | else if (os.iword(AliTRDmcmSim::fgkFormatIndex) == 2) { | |
2229 | Int_t bufSize = 300; | |
2230 | UInt_t *buf = new UInt_t[bufSize]; | |
5f006bd7 | 2231 | |
ce4786b9 | 2232 | Int_t bufLength = mcm.ProduceRawStream(&buf[0], bufSize); |
5f006bd7 | 2233 | |
2234 | for (Int_t i = 0; i < bufLength; i++) | |
78c94f0b | 2235 | std::cout << "0x" << std::hex << buf[i] << std::dec << std::endl; |
5f006bd7 | 2236 | |
ce4786b9 | 2237 | delete [] buf; |
2238 | } | |
2239 | ||
2240 | else { | |
2241 | os << "unknown format set" << std::endl; | |
2242 | } | |
2243 | ||
2244 | return os; | |
2245 | } | |
8ea391e3 | 2246 | |
2247 | ||
2248 | void AliTRDmcmSim::PrintFitRegXml(ostream& os) const | |
2249 | { | |
6b094867 | 2250 | // print fit registres in XML format |
2251 | ||
8ea391e3 | 2252 | bool tracklet=false; |
2253 | ||
2254 | for (Int_t cpu = 0; cpu < 4; cpu++) { | |
2255 | if(fFitPtr[cpu] != 31) | |
2256 | tracklet=true; | |
2257 | } | |
2258 | ||
2259 | if(tracklet==true) { | |
2260 | os << "<nginject>" << std::endl; | |
2261 | os << "<ack roc=\""<< fDetector << "\" cmndid=\"0\">" << std::endl; | |
2262 | os << "<dmem-readout>" << std::endl; | |
2263 | os << "<d det=\"" << fDetector << "\">" << std::endl; | |
2264 | os << " <ro-board rob=\"" << fRobPos << "\">" << std::endl; | |
2265 | os << " <m mcm=\"" << fMcmPos << "\">" << std::endl; | |
5f006bd7 | 2266 | |
8ea391e3 | 2267 | for(int cpu=0; cpu<4; cpu++) { |
2268 | os << " <c cpu=\"" << cpu << "\">" << std::endl; | |
2269 | if(fFitPtr[cpu] != 31) { | |
2270 | for(int adcch=fFitPtr[cpu]; adcch<fFitPtr[cpu]+2; adcch++) { | |
5ac2e3b1 | 2271 | os << " <ch chnr=\"" << adcch << "\">"<< std::endl; |
8ea391e3 | 2272 | os << " <hits>" << fFitReg[adcch].fNhits << "</hits>"<< std::endl; |
2273 | os << " <q0>" << fFitReg[adcch].fQ0/4 << "</q0>"<< std::endl; // divided by 4 because in simulation we have 2 additional decimal places | |
5f006bd7 | 2274 | os << " <q1>" << fFitReg[adcch].fQ1/4 << "</q1>"<< std::endl; // in the output |
8ea391e3 | 2275 | os << " <sumx>" << fFitReg[adcch].fSumX << "</sumx>"<< std::endl; |
2276 | os << " <sumxsq>" << fFitReg[adcch].fSumX2 << "</sumxsq>"<< std::endl; | |
2277 | os << " <sumy>" << fFitReg[adcch].fSumY << "</sumy>"<< std::endl; | |
2278 | os << " <sumysq>" << fFitReg[adcch].fSumY2 << "</sumysq>"<< std::endl; | |
2279 | os << " <sumxy>" << fFitReg[adcch].fSumXY << "</sumxy>"<< std::endl; | |
2280 | os << " </ch>" << std::endl; | |
2281 | } | |
2282 | } | |
2283 | os << " </c>" << std::endl; | |
2284 | } | |
2285 | os << " </m>" << std::endl; | |
2286 | os << " </ro-board>" << std::endl; | |
2287 | os << "</d>" << std::endl; | |
2288 | os << "</dmem-readout>" << std::endl; | |
2289 | os << "</ack>" << std::endl; | |
2290 | os << "</nginject>" << std::endl; | |
2291 | } | |
2292 | } | |
2293 | ||
2294 | ||
2295 | void AliTRDmcmSim::PrintTrackletsXml(ostream& os) const | |
2296 | { | |
6b094867 | 2297 | // print tracklets in XML format |
2298 | ||
8ea391e3 | 2299 | os << "<nginject>" << std::endl; |
2300 | os << "<ack roc=\""<< fDetector << "\" cmndid=\"0\">" << std::endl; | |
2301 | os << "<dmem-readout>" << std::endl; | |
2302 | os << "<d det=\"" << fDetector << "\">" << std::endl; | |
2303 | os << " <ro-board rob=\"" << fRobPos << "\">" << std::endl; | |
2304 | os << " <m mcm=\"" << fMcmPos << "\">" << std::endl; | |
2305 | ||
2306 | Int_t pid, padrow, slope, offset; | |
2307 | for(Int_t cpu=0; cpu<4; cpu++) { | |
2308 | if(fMCMT[cpu] == 0x10001000) { | |
2309 | pid=-1; | |
2310 | padrow=-1; | |
2311 | slope=-1; | |
2312 | offset=-1; | |
2313 | } | |
2314 | else { | |
2315 | pid = (fMCMT[cpu] & 0xFF000000) >> 24; | |
2316 | padrow = (fMCMT[cpu] & 0xF00000 ) >> 20; | |
2317 | slope = (fMCMT[cpu] & 0xFE000 ) >> 13; | |
2318 | offset = (fMCMT[cpu] & 0x1FFF ) ; | |
2319 | ||
2320 | } | |
5f006bd7 | 2321 | os << " <trk> <pid>" << pid << "</pid>" << " <padrow>" << padrow << "</padrow>" |
5ac2e3b1 | 2322 | << " <slope>" << slope << "</slope>" << " <offset>" << offset << "</offset>" << "</trk>" << std::endl; |
8ea391e3 | 2323 | } |
2324 | ||
2325 | os << " </m>" << std::endl; | |
2326 | os << " </ro-board>" << std::endl; | |
2327 | os << "</d>" << std::endl; | |
2328 | os << "</dmem-readout>" << std::endl; | |
2329 | os << "</ack>" << std::endl; | |
2330 | os << "</nginject>" << std::endl; | |
2331 | } | |
2332 | ||
2333 | ||
2334 | void AliTRDmcmSim::PrintAdcDatHuman(ostream& os) const | |
2335 | { | |
6b094867 | 2336 | // print ADC data in human-readable format |
2337 | ||
5f006bd7 | 2338 | os << "MCM " << fMcmPos << " on ROB " << fRobPos << |
8ea391e3 | 2339 | " in detector " << fDetector << std::endl; |
5f006bd7 | 2340 | |
8ea391e3 | 2341 | os << "----- Unfiltered ADC data (10 bit) -----" << std::endl; |
2342 | os << "ch "; | |
6170d369 | 2343 | for (Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) |
8ea391e3 | 2344 | os << std::setw(5) << iChannel; |
2345 | os << std::endl; | |
2346 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
2347 | os << "tb " << std::setw(2) << iTimeBin << ":"; | |
6170d369 | 2348 | for (Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) { |
8ea391e3 | 2349 | os << std::setw(5) << (fADCR[iChannel][iTimeBin] >> fgkAddDigits); |
2350 | } | |
2351 | os << std::endl; | |
2352 | } | |
5f006bd7 | 2353 | |
8ea391e3 | 2354 | os << "----- Filtered ADC data (10+2 bit) -----" << std::endl; |
2355 | os << "ch "; | |
6170d369 | 2356 | for (Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) |
8ea391e3 | 2357 | os << std::setw(4) << iChannel |
2358 | << ((~fZSMap[iChannel] != 0) ? "!" : " "); | |
2359 | os << std::endl; | |
2360 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
2361 | os << "tb " << std::setw(2) << iTimeBin << ":"; | |
6170d369 | 2362 | for (Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) { |
8ea391e3 | 2363 | os << std::setw(4) << (fADCF[iChannel][iTimeBin]) |
2364 | << (((fZSMap[iChannel] & (1 << iTimeBin)) == 0) ? "!" : " "); | |
2365 | } | |
2366 | os << std::endl; | |
2367 | } | |
2368 | } | |
2369 | ||
2370 | ||
2371 | void AliTRDmcmSim::PrintAdcDatXml(ostream& os) const | |
2372 | { | |
5f006bd7 | 2373 | // print ADC data in XML format |
6b094867 | 2374 | |
8ea391e3 | 2375 | os << "<nginject>" << std::endl; |
2376 | os << "<ack roc=\""<< fDetector << "\" cmndid=\"0\">" << std::endl; | |
2377 | os << "<dmem-readout>" << std::endl; | |
2378 | os << "<d det=\"" << fDetector << "\">" << std::endl; | |
2379 | os << " <ro-board rob=\"" << fRobPos << "\">" << std::endl; | |
2380 | os << " <m mcm=\"" << fMcmPos << "\">" << std::endl; | |
2381 | ||
6170d369 | 2382 | for(Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) { |
8ea391e3 | 2383 | os << " <ch chnr=\"" << iChannel << "\">" << std::endl; |
2384 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { | |
2385 | os << "<tb>" << fADCF[iChannel][iTimeBin]/4 << "</tb>"; | |
2386 | } | |
2387 | os << " </ch>" << std::endl; | |
2388 | } | |
2389 | ||
2390 | os << " </m>" << std::endl; | |
2391 | os << " </ro-board>" << std::endl; | |
2392 | os << "</d>" << std::endl; | |
2393 | os << "</dmem-readout>" << std::endl; | |
2394 | os << "</ack>" << std::endl; | |
2395 | os << "</nginject>" << std::endl; | |
2396 | } | |
2397 | ||
2398 | ||
2399 | ||
a10c6981 | 2400 | void AliTRDmcmSim::PrintAdcDatDatx(ostream& os, Bool_t broadcast, Int_t timeBinOffset) const |
8ea391e3 | 2401 | { |
6b094867 | 2402 | // print ADC data in datx format (to send to FEE) |
2403 | ||
8ea391e3 | 2404 | fTrapConfig->PrintDatx(os, 2602, 1, 0, 127); // command to enable the ADC clock - necessary to write ADC values to MCM |
2405 | os << std::endl; | |
2406 | ||
2407 | Int_t addrOffset = 0x2000; | |
2408 | Int_t addrStep = 0x80; | |
2409 | Int_t addrOffsetEBSIA = 0x20; | |
5f006bd7 | 2410 | |
8ea391e3 | 2411 | for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) { |
6170d369 | 2412 | for (Int_t iChannel = 0; iChannel < AliTRDfeeParam::GetNadcMcm(); iChannel++) { |
a10c6981 | 2413 | if ((iTimeBin < timeBinOffset) || (iTimeBin >= fNTimeBin+timeBinOffset)) { |
8ea391e3 | 2414 | if(broadcast==kFALSE) |
a10c6981 | 2415 | fTrapConfig->PrintDatx(os, addrOffset+iChannel*addrStep+addrOffsetEBSIA+iTimeBin, 10, GetRobPos(), GetMcmPos()); |
8ea391e3 | 2416 | else |
a10c6981 | 2417 | fTrapConfig->PrintDatx(os, addrOffset+iChannel*addrStep+addrOffsetEBSIA+iTimeBin, 10, 0, 127); |
2418 | } | |
2419 | else { | |
2420 | if(broadcast==kFALSE) | |
2421 | fTrapConfig->PrintDatx(os, addrOffset+iChannel*addrStep+addrOffsetEBSIA+iTimeBin, (fADCF[iChannel][iTimeBin-timeBinOffset]/4), GetRobPos(), GetMcmPos()); | |
2422 | else | |
2423 | fTrapConfig->PrintDatx(os, addrOffset+iChannel*addrStep+addrOffsetEBSIA+iTimeBin, (fADCF[iChannel][iTimeBin-timeBinOffset]/4), 0, 127); | |
2424 | } | |
2425 | } | |
2426 | os << std::endl; | |
8ea391e3 | 2427 | } |
2428 | } | |
2429 | ||
2430 | ||
2431 | void AliTRDmcmSim::PrintPidLutHuman() | |
2432 | { | |
6b094867 | 2433 | // print PID LUT in human readable format |
2434 | ||
8ea391e3 | 2435 | UInt_t result; |
2436 | ||
2b2b540f | 2437 | UInt_t addrEnd = fgkDmemAddrLUTStart + fTrapConfig->GetDmemUnsigned(fgkDmemAddrLUTLength, fDetector, fRobPos, fMcmPos)/4; // /4 because each addr contains 4 values |
2438 | UInt_t nBinsQ0 = fTrapConfig->GetDmemUnsigned(fgkDmemAddrLUTnbins, fDetector, fRobPos, fMcmPos); | |
8ea391e3 | 2439 | |
2440 | std::cout << "nBinsQ0: " << nBinsQ0 << std::endl; | |
2b2b540f | 2441 | std::cout << "LUT table length: " << fTrapConfig->GetDmemUnsigned(fgkDmemAddrLUTLength, fDetector, fRobPos, fMcmPos) << std::endl; |
5f006bd7 | 2442 | |
eaf6dbb0 | 2443 | if (nBinsQ0>0) { |
2b2b540f | 2444 | for(UInt_t addr=fgkDmemAddrLUTStart; addr< addrEnd; addr++) { |
2445 | result = fTrapConfig->GetDmemUnsigned(addr, fDetector, fRobPos, fMcmPos); | |
2446 | std::cout << addr << " # x: " << ((addr-fgkDmemAddrLUTStart)%((nBinsQ0)/4))*4 << ", y: " <<(addr-fgkDmemAddrLUTStart)/(nBinsQ0/4) | |
eaf6dbb0 | 2447 | << " # " <<((result>>0)&0xFF) |
2448 | << " | " << ((result>>8)&0xFF) | |
2449 | << " | " << ((result>>16)&0xFF) | |
2450 | << " | " << ((result>>24)&0xFF) << std::endl; | |
2451 | } | |
8ea391e3 | 2452 | } |
2453 | } | |
2b2b540f | 2454 | |
2455 | ||
2456 | Bool_t AliTRDmcmSim::ReadPackedConfig(AliTRDtrapConfig *cfg, Int_t hc, UInt_t *data, Int_t size) | |
2457 | { | |
2458 | // Read the packed configuration from the passed memory block | |
2459 | // | |
2460 | // To be used to retrieve the TRAP configuration from the | |
2461 | // configuration as sent in the raw data. | |
2462 | ||
2463 | AliDebugClass(1, "Reading packed configuration"); | |
2464 | ||
2465 | Int_t det = hc/2; | |
2466 | ||
2467 | Int_t idx = 0; | |
2468 | Int_t err = 0; | |
2469 | Int_t step, bwidth, nwords, exitFlag, bitcnt; | |
2470 | ||
2471 | UShort_t caddr; | |
2472 | UInt_t dat, msk, header, dataHi; | |
2473 | ||
2474 | while (idx < size && *data != 0x00000000) { | |
2475 | ||
2476 | Int_t rob = (*data >> 28) & 0x7; | |
2477 | Int_t mcm = (*data >> 24) & 0xf; | |
2478 | ||
2479 | AliDebugClass(1, Form("Config of det. %3i MCM %i:%02i (0x%08x)", det, rob, mcm, *data)); | |
2480 | data++; | |
2481 | ||
2482 | while (idx < size && *data != 0x00000000) { | |
2483 | ||
2484 | header = *data; | |
2485 | data++; | |
2486 | idx++; | |
2487 | ||
2488 | AliDebugClass(5, Form("read: 0x%08x", header)); | |
2489 | ||
2490 | if (header & 0x01) // single data | |
2491 | { | |
2492 | dat = (header >> 2) & 0xFFFF; // 16 bit data | |
2493 | caddr = (header >> 18) & 0x3FFF; // 14 bit address | |
2494 | ||
2495 | if (caddr != 0x1FFF) // temp!!! because the end marker was wrong | |
2496 | { | |
2497 | if (header & 0x02) // check if > 16 bits | |
2498 | { | |
2499 | dataHi = *data; | |
2500 | AliDebugClass(5, Form("read: 0x%08x", dataHi)); | |
2501 | data++; | |
2502 | idx++; | |
2503 | err += ((dataHi ^ (dat | 1)) & 0xFFFF) != 0; | |
2504 | dat = (dataHi & 0xFFFF0000) | dat; | |
2505 | } | |
2506 | AliDebugClass(5, Form("addr=0x%04x (%s) data=0x%08x\n", caddr, cfg->GetRegName(cfg->GetRegByAddress(caddr)), dat)); | |
2507 | if ( ! cfg->Poke(caddr, dat, det, rob, mcm) ) | |
2508 | AliDebugClass(5, Form("(single-write): non-existing address 0x%04x containing 0x%08x\n", caddr, header)); | |
2509 | if (idx > size) | |
2510 | { | |
2511 | AliDebugClass(5, Form("(single-write): no more data, missing end marker\n")); | |
2512 | return -err; | |
2513 | } | |
2514 | } | |
2515 | else | |
2516 | { | |
2517 | AliDebugClass(5, Form("(single-write): address 0x%04x => old endmarker?\n", caddr)); | |
2518 | return err; | |
2519 | } | |
2520 | } | |
2521 | ||
2522 | else // block of data | |
2523 | { | |
2524 | step = (header >> 1) & 0x0003; | |
2525 | bwidth = ((header >> 3) & 0x001F) + 1; | |
2526 | nwords = (header >> 8) & 0x00FF; | |
2527 | caddr = (header >> 16) & 0xFFFF; | |
2528 | exitFlag = (step == 0) || (step == 3) || (nwords == 0); | |
2529 | ||
2530 | if (exitFlag) | |
2531 | break; | |
2532 | ||
2533 | switch (bwidth) | |
2534 | { | |
2535 | case 15: | |
2536 | case 10: | |
2537 | case 7: | |
2538 | case 6: | |
2539 | case 5: | |
2540 | { | |
2541 | msk = (1 << bwidth) - 1; | |
2542 | bitcnt = 0; | |
2543 | while (nwords > 0) | |
2544 | { | |
2545 | nwords--; | |
2546 | bitcnt -= bwidth; | |
2547 | if (bitcnt < 0) | |
2548 | { | |
2549 | header = *data; | |
2550 | AliDebugClass(5, Form("read 0x%08x", header)); | |
2551 | data++; | |
2552 | idx++; | |
2553 | err += (header & 1); | |
2554 | header = header >> 1; | |
2555 | bitcnt = 31 - bwidth; | |
2556 | } | |
2557 | AliDebugClass(5, Form("addr=0x%04x (%s) data=0x%08x\n", caddr, cfg->GetRegName(cfg->GetRegByAddress(caddr)), header & msk)); | |
2558 | if ( ! cfg->Poke(caddr, header & msk, det, rob, mcm) ) | |
2559 | AliDebugClass(5, Form("(single-write): non-existing address 0x%04x containing 0x%08x\n", caddr, header)); | |
2560 | ||
2561 | caddr += step; | |
2562 | header = header >> bwidth; | |
2563 | if (idx >= size) | |
2564 | { | |
2565 | AliDebugClass(5, Form("(block-write): no end marker! %d words read\n", idx)); | |
2566 | return -err; | |
2567 | } | |
2568 | } | |
2569 | break; | |
2570 | } // end case 5-15 | |
2571 | case 31: | |
2572 | { | |
2573 | while (nwords > 0) | |
2574 | { | |
2575 | header = *data; | |
2576 | AliDebugClass(5, Form("read 0x%08x", header)); | |
2577 | data++; | |
2578 | idx++; | |
2579 | nwords--; | |
2580 | err += (header & 1); | |
2581 | ||
2582 | AliDebugClass(5, Form("addr=0x%04x (%s) data=0x%08x", caddr, cfg->GetRegName(cfg->GetRegByAddress(caddr)), header >> 1)); | |
2583 | if ( ! cfg->Poke(caddr, header >> 1, det, rob, mcm) ) | |
2584 | AliDebugClass(5, Form("(single-write): non-existing address 0x%04x containing 0x%08x\n", caddr, header)); | |
2585 | ||
2586 | caddr += step; | |
2587 | if (idx >= size) | |
2588 | { | |
2589 | AliDebugClass(5, Form("no end marker! %d words read", idx)); | |
2590 | return -err; | |
2591 | } | |
2592 | } | |
2593 | break; | |
2594 | } | |
2595 | default: return err; | |
2596 | } // end switch | |
2597 | } // end block case | |
2598 | } | |
2599 | } // end while | |
2600 | AliDebugClass(5, Form("no end marker! %d words read", idx)); | |
2601 | return -err; // only if the max length of the block reached! | |
2602 | } |