1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // TRD MCM (Multi Chip Module) simulator //
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. //
25 ///////////////////////////////////////////////////////////////////////////////
36 #include "TClonesArray.h"
40 #include "AliRunLoader.h"
41 #include "AliLoader.h"
43 #include "AliTRDfeeParam.h"
44 #include "AliTRDtrapConfig.h"
45 #include "AliTRDdigitsManager.h"
46 #include "AliTRDarrayADC.h"
47 #include "AliTRDarrayDictionary.h"
48 #include "AliTRDtrackletMCM.h"
49 #include "AliTRDmcmSim.h"
51 ClassImp(AliTRDmcmSim)
53 Bool_t AliTRDmcmSim::fgApplyCut = kTRUE;
54 Int_t AliTRDmcmSim::fgAddBaseline = 0;
56 const Int_t AliTRDmcmSim::fgkFormatIndex = std::ios_base::xalloc();
58 const Int_t AliTRDmcmSim::fgkNADC = AliTRDfeeParam::GetNadcMcm();
59 const UShort_t AliTRDmcmSim::fgkFPshifts[4] = {11, 14, 17, 21};
62 AliTRDmcmSim::AliTRDmcmSim() :
87 // AliTRDmcmSim default constructor
88 // By default, nothing is initialized.
89 // It is necessary to issue Init before use.
92 AliTRDmcmSim::~AliTRDmcmSim()
95 // AliTRDmcmSim destructor
99 for( Int_t iAdc = 0 ; iAdc < fgkNADC; iAdc++ ) {
100 delete [] fADCR[iAdc];
101 delete [] fADCF[iAdc];
109 delete [] fGainCounterA;
110 delete [] fGainCounterB;
111 delete [] fTailAmplLong;
112 delete [] fTailAmplShort;
115 fTrackletArray->Delete();
116 delete fTrackletArray;
120 void AliTRDmcmSim::Init( Int_t det, Int_t robPos, Int_t mcmPos, Bool_t /* newEvent */ )
123 // Initialize the class with new MCM position information
124 // memory is allocated in the first initialization
128 fFeeParam = AliTRDfeeParam::Instance();
129 fTrapConfig = AliTRDtrapConfig::Instance();
135 fNTimeBin = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kC13CPUA);
136 fRow = fFeeParam->GetPadRowFromMCM( fRobPos, fMcmPos );
139 fADCR = new Int_t *[fgkNADC];
140 fADCF = new Int_t *[fgkNADC];
141 fZSMap = new Int_t [fgkNADC];
142 fGainCounterA = new UInt_t[fgkNADC];
143 fGainCounterB = new UInt_t[fgkNADC];
144 for( Int_t iAdc = 0 ; iAdc < fgkNADC; iAdc++ ) {
145 fADCR[iAdc] = new Int_t[fNTimeBin];
146 fADCF[iAdc] = new Int_t[fNTimeBin];
150 fPedAcc = new UInt_t[fgkNADC]; // accumulator for pedestal filter
151 fTailAmplLong = new UShort_t[fgkNADC];
152 fTailAmplShort = new UShort_t[fgkNADC];
154 // tracklet calculation
155 fFitReg = new FitReg_t[fgkNADC];
156 fTrackletArray = new TClonesArray("AliTRDtrackletMCM", fgkMaxTracklets);
158 fMCMT = new UInt_t[fgkMaxTracklets];
161 fInitialized = kTRUE;
166 void AliTRDmcmSim::Reset()
168 // Resets the data values and internal filter registers
169 // by re-initialising them
171 if( !CheckInitialized() )
174 for( Int_t iAdc = 0 ; iAdc < fgkNADC; iAdc++ ) {
175 for( Int_t it = 0 ; it < fNTimeBin ; it++ ) {
179 fZSMap[iAdc] = -1; // Default unread, low active bit mask
180 fGainCounterA[iAdc] = 0;
181 fGainCounterB[iAdc] = 0;
184 for(Int_t i = 0; i < fgkMaxTracklets; i++) {
188 for (Int_t iDict = 0; iDict < 3; iDict++)
191 FilterPedestalInit();
196 void AliTRDmcmSim::SetNTimebins(Int_t ntimebins)
198 // Reallocate memory if a change in the number of timebins
199 // is needed (should not be the case for real data)
201 if( !CheckInitialized() )
204 fNTimeBin = ntimebins;
205 for( Int_t iAdc = 0 ; iAdc < fgkNADC; iAdc++ ) {
208 fADCR[iAdc] = new Int_t[fNTimeBin];
209 fADCF[iAdc] = new Int_t[fNTimeBin];
213 Bool_t AliTRDmcmSim::LoadMCM(AliRunLoader* const runloader, Int_t det, Int_t rob, Int_t mcm)
215 // loads the ADC data as obtained from the digitsManager for the specified MCM.
216 // This method is meant for rare execution, e.g. in the visualization. When called
217 // frequently use SetData(...) instead.
222 AliError("No Runloader given");
226 AliLoader *trdLoader = runloader->GetLoader("TRDLoader");
228 AliError("Could not get TRDLoader");
232 Bool_t retval = kTRUE;
233 trdLoader->LoadDigits();
234 fDigitsManager = 0x0;
235 AliTRDdigitsManager *digMgr = new AliTRDdigitsManager();
236 digMgr->SetSDigits(0);
237 digMgr->CreateArrays();
238 digMgr->ReadDigits(trdLoader->TreeD());
239 AliTRDarrayADC *digits = (AliTRDarrayADC*) digMgr->GetDigits(det);
240 if (digits->HasData()) {
243 if (fNTimeBin != digits->GetNtime()) {
244 AliWarning(Form("Changing no. of timebins from %i to %i", fNTimeBin, digits->GetNtime()));
245 SetNTimebins(digits->GetNtime());
258 void AliTRDmcmSim::NoiseTest(Int_t nsamples, Int_t mean, Int_t sigma, Int_t inputGain, Int_t inputTail)
260 // This function can be used to test the filters.
261 // It feeds nsamples of ADC values with a gaussian distribution specified by mean and sigma.
262 // The filter chain implemented here consists of:
263 // Pedestal -> Gain -> Tail
264 // With inputGain and inputTail the input to the gain and tail filter, respectively,
265 // can be chosen where
267 // 1: pedestal output
269 // The input has to be chosen from a stage before.
270 // The filter behaviour is controlled by the TRAP parameters from AliTRDtrapConfig in the
271 // same way as in normal simulation.
272 // The functions produces four histograms with the values at the different stages.
274 if( !CheckInitialized() )
277 TString nameInputGain;
278 TString nameInputTail;
282 nameInputGain = "Noise";
286 nameInputGain = "Pedestal";
290 AliError("Undefined input to tail cancellation filter");
296 nameInputTail = "Noise";
300 nameInputTail = "Pedestal";
304 nameInputTail = "Gain";
308 AliError("Undefined input to tail cancellation filter");
312 TH1F *h = new TH1F("noise", "Gaussian Noise;sample;ADC count",
313 nsamples, 0, nsamples);
314 TH1F *hfp = new TH1F("ped", "Noise #rightarrow Pedestal filter;sample;ADC count", nsamples, 0, nsamples);
315 TH1F *hfg = new TH1F("gain",
316 (nameInputGain + "#rightarrow Gain;sample;ADC count").Data(),
317 nsamples, 0, nsamples);
318 TH1F *hft = new TH1F("tail",
319 (nameInputTail + "#rightarrow Tail;sample;ADC count").Data(),
320 nsamples, 0, nsamples);
322 hfp->SetStats(kFALSE);
323 hfg->SetStats(kFALSE);
324 hft->SetStats(kFALSE);
326 Int_t value; // ADC count with noise (10 bit)
327 Int_t valuep; // pedestal filter output (12 bit)
328 Int_t valueg; // gain filter output (12 bit)
329 Int_t valuet; // tail filter value (12 bit)
331 for (Int_t i = 0; i < nsamples; i++) {
332 value = (Int_t) gRandom->Gaus(mean, sigma); // generate noise with gaussian distribution
333 h->SetBinContent(i, value);
335 valuep = FilterPedestalNextSample(1, 0, ((Int_t) value) << 2);
338 valueg = FilterGainNextSample(1, ((Int_t) value) << 2);
340 valueg = FilterGainNextSample(1, valuep);
343 valuet = FilterTailNextSample(1, ((Int_t) value) << 2);
344 else if (inputTail == 1)
345 valuet = FilterTailNextSample(1, valuep);
347 valuet = FilterTailNextSample(1, valueg);
349 hfp->SetBinContent(i, valuep >> 2);
350 hfg->SetBinContent(i, valueg >> 2);
351 hft->SetBinContent(i, valuet >> 2);
354 TCanvas *c = new TCanvas;
366 Bool_t AliTRDmcmSim::CheckInitialized() const
369 // Check whether object is initialized
373 AliError(Form ("AliTRDmcmSim is not initialized but function other than Init() is called."));
378 void AliTRDmcmSim::Print(Option_t* const option) const
380 // Prints the data stored and/or calculated for this MCM.
381 // The output is controlled by option which can be a sequence of any of
382 // the following characters:
383 // R - prints raw ADC data
384 // F - prints filtered data
385 // H - prints detected hits
386 // T - prints found tracklets
387 // The later stages are only meaningful after the corresponding calculations
388 // have been performed.
390 if ( !CheckInitialized() )
393 printf("MCM %i on ROB %i in detector %i\n", fMcmPos, fRobPos, fDetector);
395 TString opt = option;
396 if (opt.Contains("R") || opt.Contains("F")) {
400 if (opt.Contains("H")) {
401 printf("Found %i hits:\n", fNHits);
402 for (Int_t iHit = 0; iHit < fNHits; iHit++) {
403 printf("Hit %3i in timebin %2i, ADC %2i has charge %3i and position %3i\n",
404 iHit, fHits[iHit].fTimebin, fHits[iHit].fChannel, fHits[iHit].fQtot, fHits[iHit].fYpos);
408 if (opt.Contains("T")) {
409 printf("Tracklets:\n");
410 for (Int_t iTrkl = 0; iTrkl < fTrackletArray->GetEntriesFast(); iTrkl++) {
411 printf("tracklet %i: 0x%08x\n", iTrkl, ((AliTRDtrackletMCM*) (*fTrackletArray)[iTrkl])->GetTrackletWord());
416 void AliTRDmcmSim::Draw(Option_t* const option)
418 // Plots the data stored in a 2-dim. timebin vs. ADC channel plot.
419 // The option selects what data is plotted and can be a sequence of
420 // the following characters:
421 // R - plot raw data (default)
422 // F - plot filtered data (meaningless if R is specified)
423 // In addition to the ADC values:
425 // T - plot tracklets
427 if( !CheckInitialized() )
430 TString opt = option;
432 TH2F *hist = new TH2F("mcmdata", Form("Data of MCM %i on ROB %i in detector %i", \
433 fMcmPos, fRobPos, fDetector), \
434 fgkNADC, -0.5, fgkNADC-.5, fNTimeBin, -.5, fNTimeBin-.5);
435 hist->GetXaxis()->SetTitle("ADC Channel");
436 hist->GetYaxis()->SetTitle("Timebin");
437 hist->SetStats(kFALSE);
439 if (opt.Contains("R")) {
440 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
441 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
442 hist->SetBinContent(iAdc+1, iTimeBin+1, fADCR[iAdc][iTimeBin] >> fgkAddDigits);
447 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
448 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
449 hist->SetBinContent(iAdc+1, iTimeBin+1, fADCF[iAdc][iTimeBin] >> fgkAddDigits);
455 if (opt.Contains("H")) {
456 TGraph *grHits = new TGraph();
457 for (Int_t iHit = 0; iHit < fNHits; iHit++) {
458 grHits->SetPoint(iHit,
459 fHits[iHit].fChannel + 1 + fHits[iHit].fYpos/256.,
460 fHits[iHit].fTimebin);
465 if (opt.Contains("T")) {
466 TLine *trklLines = new TLine[4];
467 for (Int_t iTrkl = 0; iTrkl < fTrackletArray->GetEntries(); iTrkl++) {
468 AliTRDtrackletMCM *trkl = (AliTRDtrackletMCM*) (*fTrackletArray)[iTrkl];
469 Float_t padWidth = 0.635 + 0.03 * (fDetector % 6);
470 Float_t offset = padWidth/256. * ((((((fRobPos & 0x1) << 2) + (fMcmPos & 0x3)) * 18) << 8) - ((18*4*2 - 18*2 - 3) << 7)); // revert adding offset in FitTracklet
471 Int_t ndrift = fTrapConfig->GetDmem(0xc025, fDetector, fRobPos, fMcmPos) >> 5;
472 Float_t slope = trkl->GetdY() * 140e-4 / ndrift;
474 Int_t t0 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFS);
475 Int_t t1 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFE);
477 trklLines[iTrkl].SetX1((offset - (trkl->GetY() - slope * t0)) / padWidth); // ??? sign?
478 trklLines[iTrkl].SetY1(t0);
479 trklLines[iTrkl].SetX2((offset - (trkl->GetY() - slope * t1)) / padWidth); // ??? sign?
480 trklLines[iTrkl].SetY2(t1);
481 trklLines[iTrkl].SetLineColor(2);
482 trklLines[iTrkl].SetLineWidth(2);
483 printf("Tracklet %i: y = %f, dy = %f, offset = %f\n", iTrkl, trkl->GetY(), (trkl->GetdY() * 140e-4), offset);
484 trklLines[iTrkl].Draw();
489 void AliTRDmcmSim::SetData( Int_t adc, Int_t* const data )
492 // Store ADC data into array of raw data
495 if( !CheckInitialized() ) return;
497 if( adc < 0 || adc >= fgkNADC ) {
498 AliError(Form ("Error: ADC %i is out of range (0 .. %d).", adc, fgkNADC-1));
502 for( Int_t it = 0 ; it < fNTimeBin ; it++ ) {
503 fADCR[adc][it] = (Int_t) (data[it]) << fgkAddDigits;
504 fADCF[adc][it] = (Int_t) (data[it]) << fgkAddDigits;
508 void AliTRDmcmSim::SetData( Int_t adc, Int_t it, Int_t data )
511 // Store ADC data into array of raw data
514 if( !CheckInitialized() ) return;
516 if( adc < 0 || adc >= fgkNADC ) {
517 AliError(Form ("Error: ADC %i is out of range (0 .. %d).", adc, fgkNADC-1));
521 fADCR[adc][it] = data << fgkAddDigits;
522 fADCF[adc][it] = data << fgkAddDigits;
525 void AliTRDmcmSim::SetData(AliTRDarrayADC* const adcArray, AliTRDdigitsManager *digitsManager)
527 // Set the ADC data from an AliTRDarrayADC
529 if( !CheckInitialized() )
532 fDigitsManager = digitsManager;
533 if (fDigitsManager) {
534 for (Int_t iDict = 0; iDict < 3; iDict++) {
535 AliTRDarrayDictionary *newDict = (AliTRDarrayDictionary*) fDigitsManager->GetDictionary(fDetector, iDict);
536 if (fDict[iDict] != 0x0 && newDict != 0x0) {
538 if (fDict[iDict] == newDict)
541 fDict[iDict] = newDict;
543 if (fDict[iDict]->GetDim() == 0) {
544 AliError(Form("Dictionary %i of det. %i has dim. 0", fDetector, iDict));
547 fDict[iDict]->Expand();
550 fDict[iDict] = newDict;
552 fDict[iDict]->Expand();
557 if (fNTimeBin != adcArray->GetNtime())
558 SetNTimebins(adcArray->GetNtime());
560 Int_t offset = (fMcmPos % 4 + 1) * 21 + (fRobPos % 2) * 84 - 1;
562 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
563 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
564 Int_t value = adcArray->GetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin);
565 if (value < 0 || (offset - iAdc < 1) || (offset - iAdc > 165)) {
566 fADCR[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP) + (fgAddBaseline << fgkAddDigits);
567 fADCF[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP) + (fgAddBaseline << fgkAddDigits);
571 fADCR[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits);
572 fADCF[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits);
578 void AliTRDmcmSim::SetDataByPad(AliTRDarrayADC* const adcArray, AliTRDdigitsManager *digitsManager)
580 // Set the ADC data from an AliTRDarrayADC
581 // (by pad, to be used during initial reading in simulation)
583 if( !CheckInitialized() )
586 fDigitsManager = digitsManager;
587 if (fDigitsManager) {
588 for (Int_t iDict = 0; iDict < 3; iDict++) {
589 AliTRDarrayDictionary *newDict = (AliTRDarrayDictionary*) fDigitsManager->GetDictionary(fDetector, iDict);
590 if (fDict[iDict] != 0x0 && newDict != 0x0) {
592 if (fDict[iDict] == newDict)
595 fDict[iDict] = newDict;
597 if (fDict[iDict]->GetDim() == 0) {
598 AliError(Form("Dictionary %i of det. %i has dim. 0", fDetector, iDict));
601 fDict[iDict]->Expand();
604 fDict[iDict] = newDict;
606 fDict[iDict]->Expand();
611 if (fNTimeBin != adcArray->GetNtime())
612 SetNTimebins(adcArray->GetNtime());
614 Int_t offset = (fMcmPos % 4 + 1) * 18 + (fRobPos % 2) * 72 + 1;
616 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
617 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
619 Int_t pad = offset - iAdc;
620 if (pad > -1 && pad < 144)
621 value = adcArray->GetData(GetRow(), offset - iAdc, iTimeBin);
622 // Int_t value = adcArray->GetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin);
623 if (value < 0 || (offset - iAdc < 1) || (offset - iAdc > 165)) {
624 fADCR[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP) + (fgAddBaseline << fgkAddDigits);
625 fADCF[iAdc][iTimeBin] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP) + (fgAddBaseline << fgkAddDigits);
629 fADCR[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits);
630 fADCF[iAdc][iTimeBin] = (value << fgkAddDigits) + (fgAddBaseline << fgkAddDigits);
636 void AliTRDmcmSim::SetDataPedestal( Int_t adc )
639 // Store ADC data into array of raw data
642 if( !CheckInitialized() )
645 if( adc < 0 || adc >= fgkNADC ) {
649 for( Int_t it = 0 ; it < fNTimeBin ; it++ ) {
650 fADCR[adc][it] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP) + (fgAddBaseline << fgkAddDigits);
651 fADCF[adc][it] = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP) + (fgAddBaseline << fgkAddDigits);
655 Bool_t AliTRDmcmSim::GetHit(Int_t index, Int_t &channel, Int_t &timebin, Int_t &qtot, Int_t &ypos, Float_t &y, Int_t &label) const
657 // retrieve the MC hit information (not available in TRAP hardware)
659 if (index < 0 || index >= fNHits)
662 channel = fHits[index].fChannel;
663 timebin = fHits[index].fTimebin;
664 qtot = fHits[index].fQtot;
665 ypos = fHits[index].fYpos;
666 y = (Float_t) ((((((fRobPos & 0x1) << 2) + (fMcmPos & 0x3)) * 18) << 8) - ((18*4*2 - 18*2 - 1) << 7) -
667 (channel << 8) - ypos)
668 * (0.635 + 0.03 * (fDetector % 6))
670 label = fHits[index].fLabel;
675 Int_t AliTRDmcmSim::GetCol( Int_t adc )
678 // Return column id of the pad for the given ADC channel
681 if( !CheckInitialized() )
684 Int_t col = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adc);
685 if (col < 0 || col >= fFeeParam->GetNcol())
691 Int_t AliTRDmcmSim::ProduceRawStream( UInt_t *buf, Int_t bufSize, UInt_t iEv) const
694 // Produce raw data stream from this MCM and put in buf
695 // Returns number of words filled, or negative value
696 // with -1 * number of overflowed words
699 if( !CheckInitialized() )
703 Int_t nw = 0; // Number of written words
704 Int_t of = 0; // Number of overflowed words
705 Int_t rawVer = fFeeParam->GetRAWversion();
707 Int_t nActiveADC = 0; // number of activated ADC bits in a word
709 if( !CheckInitialized() )
712 if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBSF) != 0) // store unfiltered data
717 // Produce MCM header
718 x = (1<<31) | (fRobPos << 28) | (fMcmPos << 24) | ((iEv % 0x100000) << 4) | 0xC;
727 // Produce ADC mask : nncc cccm mmmm mmmm mmmm mmmm mmmm 1100
728 // n : unused , c : ADC count, m : selected ADCs
731 for( Int_t iAdc = 0 ; iAdc < fgkNADC ; iAdc++ ) {
732 if( ~fZSMap[iAdc] != 0 ) { // 0 means not suppressed
733 x = x | (1 << (iAdc+4) ); // last 4 digit reserved for 1100=0xc
734 nActiveADC++; // number of 1 in mmm....m
737 x = x | (1 << 30) | ( ( 0x3FFFFFFC ) & (~(nActiveADC) << 25) ) | 0xC; // nn = 01, ccccc are inverted, 0xc=1100
747 // Produce ADC data. 3 timebins are packed into one 32 bits word
748 // In this version, different ADC channel will NOT share the same word
750 UInt_t aa=0, a1=0, a2=0, a3=0;
752 for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
753 if( rawVer>= 3 && ~fZSMap[iAdc] == 0 ) continue; // Zero Suppression, 0 means not suppressed
754 aa = !(iAdc & 1) + 2;
755 for (Int_t iT = 0; iT < fNTimeBin; iT+=3 ) {
756 a1 = ((iT ) < fNTimeBin ) ? adc[iAdc][iT ] >> fgkAddDigits : 0;
757 a2 = ((iT + 1) < fNTimeBin ) ? adc[iAdc][iT+1] >> fgkAddDigits : 0;
758 a3 = ((iT + 2) < fNTimeBin ) ? adc[iAdc][iT+2] >> fgkAddDigits : 0;
759 x = (a3 << 22) | (a2 << 12) | (a1 << 2) | aa;
769 if( of != 0 ) return -of; else return nw;
772 Int_t AliTRDmcmSim::ProduceTrackletStream( UInt_t *buf, Int_t bufSize )
775 // Produce tracklet data stream from this MCM and put in buf
776 // Returns number of words filled, or negative value
777 // with -1 * number of overflowed words
780 if( !CheckInitialized() )
783 Int_t nw = 0; // Number of written words
784 Int_t of = 0; // Number of overflowed words
786 // Produce tracklet data. A maximum of four 32 Bit words will be written per MCM
787 // fMCMT is filled continuously until no more tracklet words available
789 for (Int_t iTracklet = 0; iTracklet < fTrackletArray->GetEntriesFast(); iTracklet++) {
791 buf[nw++] = ((AliTRDtrackletMCM*) (*fTrackletArray)[iTracklet])->GetTrackletWord();
796 if( of != 0 ) return -of; else return nw;
799 void AliTRDmcmSim::Filter()
802 // Filter the raw ADC values. The active filter stages and their
803 // parameters are taken from AliTRDtrapConfig.
804 // The raw data is stored separate from the filtered data. Thus,
805 // it is possible to run the filters on a set of raw values
806 // sequentially for parameter tuning.
809 if( !CheckInitialized() )
812 // Apply filters sequentially. Bypass is handled by filters
813 // since counters and internal registers may be updated even
814 // if the filter is bypassed.
815 // The first filter takes the data from fADCR and
818 // Non-linearity filter not implemented.
822 // Crosstalk filter not implemented.
825 void AliTRDmcmSim::FilterPedestalInit(Int_t baseline)
827 // Initializes the pedestal filter assuming that the input has
828 // been constant for a long time (compared to the time constant).
830 UShort_t fptc = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPTC); // 0..3, 0 - fastest, 3 - slowest
832 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++)
833 fPedAcc[iAdc] = (baseline << 2) * (1 << fgkFPshifts[fptc]);
836 UShort_t AliTRDmcmSim::FilterPedestalNextSample(Int_t adc, Int_t timebin, UShort_t value)
838 // Returns the output of the pedestal filter given the input value.
839 // The output depends on the internal registers and, thus, the
840 // history of the filter.
842 UShort_t fpnp = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP); // 0..511 -> 0..127.75, pedestal at the output
843 UShort_t fptc = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPTC); // 0..3, 0 - fastest, 3 - slowest
844 UShort_t fpby = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPBY); // 0..1 bypass, active low
846 UShort_t accumulatorShifted;
850 inpAdd = value + fpnp;
852 accumulatorShifted = (fPedAcc[adc] >> fgkFPshifts[fptc]) & 0x3FF; // 10 bits
853 if (timebin == 0) // the accumulator is disabled in the drift time
855 correction = (value & 0x3FF) - accumulatorShifted;
856 fPedAcc[adc] = (fPedAcc[adc] + correction) & 0x7FFFFFFF; // 31 bits
862 if (inpAdd <= accumulatorShifted)
866 inpAdd = inpAdd - accumulatorShifted;
874 void AliTRDmcmSim::FilterPedestal()
877 // Apply pedestal filter
879 // As the first filter in the chain it reads data from fADCR
880 // and outputs to fADCF.
881 // It has only an effect if previous samples have been fed to
882 // find the pedestal. Currently, the simulation assumes that
883 // the input has been stable for a sufficiently long time.
885 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
886 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
887 fADCF[iAdc][iTimeBin] = FilterPedestalNextSample(iAdc, iTimeBin, fADCR[iAdc][iTimeBin]);
892 void AliTRDmcmSim::FilterGainInit()
894 // Initializes the gain filter. In this case, only threshold
895 // counters are reset.
897 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
898 // these are counters which in hardware continue
899 // until maximum or reset
900 fGainCounterA[iAdc] = 0;
901 fGainCounterB[iAdc] = 0;
905 UShort_t AliTRDmcmSim::FilterGainNextSample(Int_t adc, UShort_t value)
907 // Apply the gain filter to the given value.
908 // BEGIN_LATEX O_{i}(t) = #gamma_{i} * I_{i}(t) + a_{i} END_LATEX
909 // The output depends on the internal registers and, thus, the
910 // history of the filter.
912 UShort_t fgby = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFGBY); // bypass, active low
913 UShort_t fgf = fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGF0 + adc)); // 0x700 + (0 & 0x1ff);
914 UShort_t fga = fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGA0 + adc)); // 40;
915 UShort_t fgta = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFGTA); // 20;
916 UShort_t fgtb = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFGTB); // 2060;
918 UInt_t corr; // corrected value
921 corr = (value * fgf) >> 11;
922 corr = corr > 0xfff ? 0xfff : corr;
923 corr = AddUintClipping(corr, fga, 12);
925 // Update threshold counters
926 // not really useful as they are cleared with every new event
927 if (!((fGainCounterA[adc] == 0x3FFFFFF) || (fGainCounterB[adc] == 0x3FFFFFF)))
931 fGainCounterB[adc]++;
932 else if (corr >= fgta)
933 fGainCounterA[adc]++;
942 void AliTRDmcmSim::FilterGain()
944 // Read data from fADCF and apply gain filter.
946 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
947 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
948 fADCF[iAdc][iTimeBin] = FilterGainNextSample(iAdc, fADCF[iAdc][iTimeBin]);
953 void AliTRDmcmSim::FilterTailInit(Int_t baseline)
955 // Initializes the tail filter assuming that the input has
956 // been at the baseline value (configured by FTFP) for a
957 // sufficiently long time.
959 // exponents and weight calculated from configuration
960 UShort_t alphaLong = 0x3ff & fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTAL); // the weight of the long component
961 UShort_t lambdaLong = (1 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLL) & 0x1FF); // the multiplier
962 UShort_t lambdaShort = (0 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLS) & 0x1FF); // the multiplier
964 Float_t lambdaL = lambdaLong * 1.0 / (1 << 11);
965 Float_t lambdaS = lambdaShort * 1.0 / (1 << 11);
966 Float_t alphaL = alphaLong * 1.0 / (1 << 11);
968 qup = (1 - lambdaL) * (1 - lambdaS);
969 qdn = 1 - lambdaS * alphaL - lambdaL * (1 - alphaL);
970 Float_t kdc = qup/qdn;
976 baseline = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFPNP);
978 ql = lambdaL * (1 - lambdaS) * alphaL;
979 qs = lambdaS * (1 - lambdaL) * (1 - alphaL);
981 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
982 Int_t value = baseline & 0xFFF;
983 Int_t corr = (value * fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGF0 + iAdc))) >> 11;
984 corr = corr > 0xfff ? 0xfff : corr;
985 corr = AddUintClipping(corr, fTrapConfig->GetTrapReg(AliTRDtrapConfig::TrapReg_t(AliTRDtrapConfig::kFGA0 + iAdc)), 12);
988 aout = baseline - (UShort_t) kt;
990 fTailAmplLong[iAdc] = (UShort_t) (aout * ql / (ql + qs));
991 fTailAmplShort[iAdc] = (UShort_t) (aout * qs / (ql + qs));
995 UShort_t AliTRDmcmSim::FilterTailNextSample(Int_t adc, UShort_t value)
997 // Returns the output of the tail filter for the given input value.
998 // The output depends on the internal registers and, thus, the
999 // history of the filter.
1001 // exponents and weight calculated from configuration
1002 UShort_t alphaLong = 0x3ff & fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTAL); // the weight of the long component
1003 UShort_t lambdaLong = (1 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLL) & 0x1FF); // the multiplier of the long component
1004 UShort_t lambdaShort = (0 << 10) | (1 << 9) | (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTLS) & 0x1FF); // the multiplier of the short component
1006 // intermediate signals
1012 UShort_t inpVolt = value & 0xFFF; // 12 bits
1014 // add the present generator outputs
1015 aQ = AddUintClipping(fTailAmplLong[adc], fTailAmplShort[adc], 12);
1017 // calculate the difference between the input and the generated signal
1019 aDiff = inpVolt - aQ;
1023 // the inputs to the two generators, weighted
1024 alInpv = (aDiff * alphaLong) >> 11;
1026 // the new values of the registers, used next time
1028 tmp = AddUintClipping(fTailAmplLong[adc], alInpv, 12);
1029 tmp = (tmp * lambdaLong) >> 11;
1030 fTailAmplLong[adc] = tmp & 0xFFF;
1032 tmp = AddUintClipping(fTailAmplShort[adc], aDiff - alInpv, 12);
1033 tmp = (tmp * lambdaShort) >> 11;
1034 fTailAmplShort[adc] = tmp & 0xFFF;
1036 // the output of the filter
1037 if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kFTBY) == 0) // bypass mode, active low
1043 void AliTRDmcmSim::FilterTail()
1045 // Apply tail cancellation filter to all data.
1047 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
1048 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
1049 fADCF[iAdc][iTimeBin] = FilterTailNextSample(iAdc, fADCF[iAdc][iTimeBin]);
1054 void AliTRDmcmSim::ZSMapping()
1057 // Zero Suppression Mapping implemented in TRAP chip
1058 // only implemented for up to 30 timebins
1060 // See detail TRAP manual "Data Indication" section:
1061 // http://www.kip.uni-heidelberg.de/ti/TRD/doc/trap/TRAP-UserManual.pdf
1064 if( !CheckInitialized() )
1067 Int_t eBIS = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIS);
1068 Int_t eBIT = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIT);
1069 Int_t eBIL = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIL);
1070 Int_t eBIN = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBIN);
1072 Int_t **adc = fADCF;
1074 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++)
1077 for( Int_t it = 0 ; it < fNTimeBin ; it++ ) {
1078 Int_t iAdc; // current ADC channel
1083 Int_t supp; // suppression of the current channel (low active)
1085 // ----- first channel -----
1089 ac = adc[iAdc ][it]; // current
1090 an = adc[iAdc+1][it]; // next
1092 mask = ( ac >= ap && ac >= an ) ? 0 : 0x1; // peak center detection
1093 mask += ( ap + ac + an > eBIT ) ? 0 : 0x2; // cluster
1094 mask += ( ac > eBIS ) ? 0 : 0x4; // absolute large peak
1096 supp = (eBIL >> mask) & 1;
1098 fZSMap[iAdc] &= ~((1-supp) << it);
1099 if( eBIN == 0 ) { // neighbour sensitivity
1100 fZSMap[iAdc+1] &= ~((1-supp) << it);
1103 // ----- last channel -----
1106 ap = adc[iAdc-1][it]; // previous
1107 ac = adc[iAdc ][it]; // current
1110 mask = ( ac >= ap && ac >= an ) ? 0 : 0x1; // peak center detection
1111 mask += ( ap + ac + an > eBIT ) ? 0 : 0x2; // cluster
1112 mask += ( ac > eBIS ) ? 0 : 0x4; // absolute large peak
1114 supp = (eBIL >> mask) & 1;
1116 fZSMap[iAdc] &= ~((1-supp) << it);
1117 if( eBIN == 0 ) { // neighbour sensitivity
1118 fZSMap[iAdc-1] &= ~((1-supp) << it);
1121 // ----- middle channels -----
1122 for( iAdc = 1 ; iAdc < fgkNADC-1; iAdc++ ) {
1123 ap = adc[iAdc-1][it]; // previous
1124 ac = adc[iAdc ][it]; // current
1125 an = adc[iAdc+1][it]; // next
1127 mask = ( ac >= ap && ac >= an ) ? 0 : 0x1; // peak center detection
1128 mask += ( ap + ac + an > eBIT ) ? 0 : 0x2; // cluster
1129 mask += ( ac > eBIS ) ? 0 : 0x4; // absolute large peak
1131 supp = (eBIL >> mask) & 1;
1133 fZSMap[iAdc] &= ~((1-supp) << it);
1134 if( eBIN == 0 ) { // neighbour sensitivity
1135 fZSMap[iAdc-1] &= ~((1-supp) << it);
1136 fZSMap[iAdc+1] &= ~((1-supp) << it);
1143 void AliTRDmcmSim::AddHitToFitreg(Int_t adc, UShort_t timebin, UShort_t qtot, Short_t ypos, Int_t label)
1145 // Add the given hit to the fit register which is lateron used for
1146 // the tracklet calculation.
1147 // In addition to the fit sums in the fit register MC information
1150 if ((timebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0)) &&
1151 (timebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE0)))
1152 fFitReg[adc].fQ0 += qtot;
1154 if ((timebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS1)) &&
1155 (timebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1)))
1156 fFitReg[adc].fQ1 += qtot;
1158 if ((timebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFS) ) &&
1159 (timebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFE)))
1161 fFitReg[adc].fSumX += timebin;
1162 fFitReg[adc].fSumX2 += timebin*timebin;
1163 fFitReg[adc].fNhits++;
1164 fFitReg[adc].fSumY += ypos;
1165 fFitReg[adc].fSumY2 += ypos*ypos;
1166 fFitReg[adc].fSumXY += timebin*ypos;
1169 // register hits (MC info)
1170 fHits[fNHits].fChannel = adc;
1171 fHits[fNHits].fQtot = qtot;
1172 fHits[fNHits].fYpos = ypos;
1173 fHits[fNHits].fTimebin = timebin;
1174 fHits[fNHits].fLabel = label;
1178 void AliTRDmcmSim::CalcFitreg()
1181 // Detect the hits and fill the fit registers.
1182 // Requires 12-bit data from fADCF which means Filter()
1183 // has to be called before even if all filters are bypassed.
1185 //??? to be clarified:
1186 UInt_t adcMask = 0xffffffff;
1188 UShort_t timebin, adcch, adcLeft, adcCentral, adcRight, hitQual, timebin1, timebin2, qtotTemp;
1189 Short_t ypos, fromLeft, fromRight, found;
1190 UShort_t qTotal[19]; // the last is dummy
1191 UShort_t marked[6], qMarked[6], worse1, worse2;
1193 timebin1 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFS);
1194 if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0)
1196 timebin1 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0);
1197 timebin2 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFE);
1198 if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1)
1200 timebin2 = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1);
1202 // reset the fit registers
1204 for (adcch = 0; adcch < fgkNADC-2; adcch++) // due to border channels
1206 fFitReg[adcch].fNhits = 0;
1207 fFitReg[adcch].fQ0 = 0;
1208 fFitReg[adcch].fQ1 = 0;
1209 fFitReg[adcch].fSumX = 0;
1210 fFitReg[adcch].fSumY = 0;
1211 fFitReg[adcch].fSumX2 = 0;
1212 fFitReg[adcch].fSumY2 = 0;
1213 fFitReg[adcch].fSumXY = 0;
1216 for (timebin = timebin1; timebin < timebin2; timebin++)
1218 // first find the hit candidates and store the total cluster charge in qTotal array
1219 // in case of not hit store 0 there.
1220 for (adcch = 0; adcch < fgkNADC-2; adcch++) {
1221 if ( ( (adcMask >> adcch) & 7) == 7) //??? all 3 channels are present in case of ZS
1223 adcLeft = fADCF[adcch ][timebin];
1224 adcCentral = fADCF[adcch+1][timebin];
1225 adcRight = fADCF[adcch+2][timebin];
1226 if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPVBY) == 1)
1227 hitQual = ( (adcLeft * adcRight) <
1228 (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPVT) * adcCentral) );
1231 // The accumulated charge is with the pedestal!!!
1232 qtotTemp = adcLeft + adcCentral + adcRight;
1234 (qtotTemp >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPHT)) &&
1235 (adcLeft <= adcCentral) &&
1236 (adcCentral > adcRight) )
1237 qTotal[adcch] = qtotTemp;
1242 qTotal[adcch] = 0; //jkl
1243 if (qTotal[adcch] != 0)
1244 AliDebug(10,Form("ch %2d qTotal %5d",adcch, qTotal[adcch]));
1250 marked[4] = 19; // invalid channel
1251 marked[5] = 19; // invalid channel
1253 while ((adcch < 16) && (found < 3))
1255 if (qTotal[adcch] > 0)
1258 marked[2*found+1]=adcch;
1267 while ((adcch > 2) && (found < 3))
1269 if (qTotal[adcch] > 0)
1271 marked[2*found]=adcch;
1278 AliDebug(10,Form("Fromleft=%d, Fromright=%d",fromLeft, fromRight));
1279 // here mask the hit candidates in the middle, if any
1280 if ((fromLeft >= 0) && (fromRight >= 0) && (fromLeft < fromRight))
1281 for (adcch = fromLeft+1; adcch < fromRight; adcch++)
1285 for (adcch = 0; adcch < 19; adcch++)
1286 if (qTotal[adcch] > 0) found++;
1289 if (found > 4) // sorting like in the TRAP in case of 5 or 6 candidates!
1291 if (marked[4] == marked[5]) marked[5] = 19;
1292 for (found=0; found<6; found++)
1294 qMarked[found] = qTotal[marked[found]] >> 4;
1295 AliDebug(10,Form("ch_%d qTotal %d qTotals %d",marked[found],qTotal[marked[found]],qMarked[found]));
1298 Sort6To2Worst(marked[0], marked[3], marked[4], marked[1], marked[2], marked[5],
1306 // Now mask the two channels with the smallest charge
1310 AliDebug(10,Form("Kill ch %d\n",worse1));
1315 AliDebug(10,Form("Kill ch %d\n",worse2));
1319 for (adcch = 0; adcch < 19; adcch++) {
1320 if (qTotal[adcch] > 0) // the channel is marked for processing
1322 adcLeft = fADCF[adcch ][timebin];
1323 adcCentral = fADCF[adcch+1][timebin];
1324 adcRight = fADCF[adcch+2][timebin];
1325 // hit detected, in TRAP we have 4 units and a hit-selection, here we proceed all channels!
1326 // subtract the pedestal TPFP, clipping instead of wrapping
1328 Int_t regTPFP = fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPFP);
1329 AliDebug(10, Form("Hit found, time=%d, adcch=%d/%d/%d, adc values=%d/%d/%d, regTPFP=%d, TPHT=%d\n",
1330 timebin, adcch, adcch+1, adcch+2, adcLeft, adcCentral, adcRight, regTPFP,
1331 fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPHT)));
1333 if (adcLeft < regTPFP) adcLeft = 0; else adcLeft -= regTPFP;
1334 if (adcCentral < regTPFP) adcCentral = 0; else adcCentral -= regTPFP;
1335 if (adcRight < regTPFP) adcRight = 0; else adcRight -= regTPFP;
1337 // Calculate the center of gravity
1338 // checking for adcCentral != 0 (in case of "bad" configuration)
1339 if (adcCentral == 0)
1341 ypos = 128*(adcLeft - adcRight) / adcCentral;
1342 if (ypos < 0) ypos = -ypos;
1343 // make the correction using the position LUT
1344 ypos = ypos + fTrapConfig->GetTrapReg((AliTRDtrapConfig::TrapReg_t) (AliTRDtrapConfig::kTPL00 + (ypos & 0x7F)));
1345 if (adcLeft > adcRight) ypos = -ypos;
1347 // label calculation
1349 if (fDigitsManager) {
1350 Int_t label[9] = { 0 }; // up to 9 different labels possible
1351 Int_t count[9] = { 0 };
1356 padcol[0] = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adcch);
1357 padcol[1] = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adcch+1);
1358 padcol[2] = fFeeParam->GetPadColFromADC(fRobPos, fMcmPos, adcch+2);
1359 Int_t padrow = fFeeParam->GetPadRowFromMCM(fRobPos, fMcmPos);
1360 for (Int_t iDict = 0; iDict < 3; iDict++) {
1363 for (Int_t iPad = 0; iPad < 3; iPad++) {
1364 if (padcol[iPad] < 0)
1366 Int_t currLabel = fDict[iDict]->GetData(padrow, padcol[iPad], timebin); //fDigitsManager->GetTrack(iDict, padrow, padcol, timebin, fDetector);
1367 AliDebug(10, Form("Read label: %4i for det: %3i, row: %i, col: %i, tb: %i\n", currLabel, fDetector, padrow, padcol[iPad], timebin));
1368 for (Int_t iLabel = 0; iLabel < nLabels; iLabel++) {
1369 if (currLabel == label[iLabel]) {
1371 if (count[iLabel] > maxCount) {
1372 maxCount = count[iLabel];
1379 if (currLabel >= 0) {
1380 label[nLabels++] = currLabel;
1385 mcLabel = label[maxIdx];
1388 // add the hit to the fitregister
1389 AddHitToFitreg(adcch, timebin, qTotal[adcch], ypos, mcLabel);
1394 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
1395 if (fFitReg[iAdc].fNhits != 0) {
1396 AliDebug(2, Form("fitreg[%i]: nHits = %i, sumX = %i, sumY = %i, sumX2 = %i, sumY2 = %i, sumXY = %i", iAdc,
1397 fFitReg[iAdc].fNhits,
1398 fFitReg[iAdc].fSumX,
1399 fFitReg[iAdc].fSumY,
1400 fFitReg[iAdc].fSumX2,
1401 fFitReg[iAdc].fSumY2,
1402 fFitReg[iAdc].fSumXY
1408 void AliTRDmcmSim::TrackletSelection()
1410 // Select up to 4 tracklet candidates from the fit registers
1411 // and assign them to the CPUs.
1413 UShort_t adcIdx, i, j, ntracks, tmp;
1414 UShort_t trackletCand[18][2]; // store the adcch[0] and number of hits[1] for all tracklet candidates
1417 for (adcIdx = 0; adcIdx < 18; adcIdx++) // ADCs
1418 if ( (fFitReg[adcIdx].fNhits
1419 >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPCL)) &&
1420 (fFitReg[adcIdx].fNhits+fFitReg[adcIdx+1].fNhits
1421 >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPCT)))
1423 trackletCand[ntracks][0] = adcIdx;
1424 trackletCand[ntracks][1] = fFitReg[adcIdx].fNhits+fFitReg[adcIdx+1].fNhits;
1425 AliDebug(10,Form("%d %2d %4d\n", ntracks, trackletCand[ntracks][0], trackletCand[ntracks][1]));
1429 for (i=0; i<ntracks;i++)
1430 AliDebug(10,Form("%d %d %d\n",i,trackletCand[i][0], trackletCand[i][1]));
1434 // primitive sorting according to the number of hits
1435 for (j = 0; j < (ntracks-1); j++)
1437 for (i = j+1; i < ntracks; i++)
1439 if ( (trackletCand[j][1] < trackletCand[i][1]) ||
1440 ( (trackletCand[j][1] == trackletCand[i][1]) && (trackletCand[j][0] < trackletCand[i][0]) ) )
1443 tmp = trackletCand[j][1];
1444 trackletCand[j][1] = trackletCand[i][1];
1445 trackletCand[i][1] = tmp;
1446 tmp = trackletCand[j][0];
1447 trackletCand[j][0] = trackletCand[i][0];
1448 trackletCand[i][0] = tmp;
1452 ntracks = 4; // cut the rest, 4 is the max
1454 // else is not necessary to sort
1456 // now sort, so that the first tracklet going to CPU0 corresponds to the highest adc channel - as in the TRAP
1457 for (j = 0; j < (ntracks-1); j++)
1459 for (i = j+1; i < ntracks; i++)
1461 if (trackletCand[j][0] < trackletCand[i][0])
1464 tmp = trackletCand[j][1];
1465 trackletCand[j][1] = trackletCand[i][1];
1466 trackletCand[i][1] = tmp;
1467 tmp = trackletCand[j][0];
1468 trackletCand[j][0] = trackletCand[i][0];
1469 trackletCand[i][0] = tmp;
1473 for (i = 0; i < ntracks; i++) // CPUs with tracklets.
1474 fFitPtr[i] = trackletCand[i][0]; // pointer to the left channel with tracklet for CPU[i]
1475 for (i = ntracks; i < 4; i++) // CPUs without tracklets
1476 fFitPtr[i] = 31; // pointer to the left channel with tracklet for CPU[i] = 31 (invalid)
1477 AliDebug(10,Form("found %i tracklet candidates\n", ntracks));
1478 for (i = 0; i < 4; i++)
1479 AliDebug(10,Form("fitPtr[%i]: %i\n", i, fFitPtr[i]));
1482 void AliTRDmcmSim::FitTracklet()
1484 // Perform the actual tracklet fit based on the fit sums
1485 // which have been filled in the fit registers.
1487 // parameters in fitred.asm (fit program)
1488 Int_t decPlaces = 5;
1491 rndAdd = (1 << (decPlaces-1)) + 1;
1492 else if (decPlaces == 1)
1494 Int_t ndriftDp = 5; // decimal places for drift time
1495 Long64_t shift = ((Long64_t) 1 << 32);
1497 // calculated in fitred.asm
1498 Int_t padrow = ((fRobPos >> 1) << 2) | (fMcmPos >> 2);
1499 Int_t yoffs = (((((fRobPos & 0x1) << 2) + (fMcmPos & 0x3)) * 18) << 8) -
1500 ((18*4*2 - 18*2 - 1) << 7);
1501 yoffs = yoffs << decPlaces; // holds position of ADC channel 1
1502 Int_t layer = fDetector % 6;
1503 UInt_t scaleY = (UInt_t) ((0.635 + 0.03 * layer)/(256.0 * 160.0e-4) * shift);
1504 UInt_t scaleD = (UInt_t) ((0.635 + 0.03 * layer)/(256.0 * 140.0e-4) * shift);
1506 Int_t deflCorr = fTrapConfig->GetDmem(0xc022, fDetector, fRobPos, fMcmPos);
1507 Int_t ndrift = fTrapConfig->GetDmem(0xc025, fDetector, fRobPos, fMcmPos);
1509 // local variables for calculation
1510 Long64_t mult, temp, denom; //???
1511 UInt_t q0, q1, qTotal; // charges in the two windows and total charge
1512 UShort_t nHits; // number of hits
1513 Int_t slope, offset; // slope and offset of the tracklet
1514 Int_t sumX, sumY, sumXY, sumX2; // fit sums from fit registers
1515 Int_t sumY2; // not used in the current TRAP program, now used for error calculation (simulation only)
1516 Float_t fitError, fitSlope, fitOffset;
1517 FitReg_t *fit0, *fit1; // pointers to relevant fit registers
1519 // const uint32_t OneDivN[32] = { // 2**31/N : exactly like in the TRAP, the simple division here gives the same result!
1520 // 0x00000000, 0x80000000, 0x40000000, 0x2AAAAAA0, 0x20000000, 0x19999990, 0x15555550, 0x12492490,
1521 // 0x10000000, 0x0E38E380, 0x0CCCCCC0, 0x0BA2E8B0, 0x0AAAAAA0, 0x09D89D80, 0x09249240, 0x08888880,
1522 // 0x08000000, 0x07878780, 0x071C71C0, 0x06BCA1A0, 0x06666660, 0x06186180, 0x05D17450, 0x0590B210,
1523 // 0x05555550, 0x051EB850, 0x04EC4EC0, 0x04BDA120, 0x04924920, 0x0469EE50, 0x04444440, 0x04210840};
1525 for (Int_t cpu = 0; cpu < 4; cpu++) {
1526 if (fFitPtr[cpu] == 31)
1528 fMCMT[cpu] = 0x10001000; //??? AliTRDfeeParam::GetTrackletEndmarker();
1532 fit0 = &fFitReg[fFitPtr[cpu] ];
1533 fit1 = &fFitReg[fFitPtr[cpu]+1]; // next channel
1536 mult = mult << (32 + decPlaces);
1540 nHits = fit0->fNhits + fit1->fNhits; // number of hits
1541 sumX = fit0->fSumX + fit1->fSumX;
1542 sumX2 = fit0->fSumX2 + fit1->fSumX2;
1543 denom = nHits*sumX2 - sumX*sumX;
1545 mult = mult / denom; // exactly like in the TRAP program
1546 q0 = fit0->fQ0 + fit1->fQ0;
1547 q1 = fit0->fQ1 + fit1->fQ1;
1548 sumY = fit0->fSumY + fit1->fSumY + 256*fit1->fNhits;
1549 sumXY = fit0->fSumXY + fit1->fSumXY + 256*fit1->fSumX;
1550 sumY2 = fit0->fSumY2 + fit1->fSumY2 + 512*fit1->fSumY + 256*256*fit1->fNhits;
1552 slope = nHits*sumXY - sumX * sumY;
1553 offset = sumX2*sumY - sumX * sumXY;
1554 temp = mult * slope;
1555 slope = temp >> 32; // take the upper 32 bits
1557 temp = mult * offset;
1558 offset = temp >> 32; // take the upper 32 bits
1560 offset = offset + yoffs;
1561 AliDebug(10, Form("slope = %i, slope * ndrift = %i, deflCorr: %i",
1562 slope, slope * ndrift, deflCorr));
1563 slope = ((slope * ndrift) >> ndriftDp) + deflCorr;
1564 offset = offset - (fFitPtr[cpu] << (8 + decPlaces));
1567 temp = temp * scaleD;
1568 slope = (temp >> 32);
1570 temp = temp * scaleY;
1571 offset = (temp >> 32);
1573 // rounding, like in the TRAP
1574 slope = (slope + rndAdd) >> decPlaces;
1575 offset = (offset + rndAdd) >> decPlaces;
1577 AliDebug(5, Form("Det: %3i, ROB: %i, MCM: %2i: deflection: %i, min: %i, max: %i",
1578 fDetector, fRobPos, fMcmPos, slope,
1579 fTrapConfig->GetDmem(0xc030 + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos),
1580 fTrapConfig->GetDmem(0xc031 + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos)));
1582 AliDebug(5, Form("Fit sums: x = %i, X = %i, y = %i, Y = %i, Z = %i",
1583 sumX, sumX2, sumY, sumY2, sumXY));
1585 fitSlope = (Float_t) (nHits * sumXY - sumX * sumY) / (nHits * sumX2 - sumX*sumX);
1587 fitOffset = (Float_t) (sumX2 * sumY - sumX * sumXY) / (nHits * sumX2 - sumX*sumX);
1589 Float_t sx = (Float_t) sumX;
1590 Float_t sx2 = (Float_t) sumX2;
1591 Float_t sy = (Float_t) sumY;
1592 Float_t sy2 = (Float_t) sumY2;
1593 Float_t sxy = (Float_t) sumXY;
1594 fitError = sy2 - (sx2 * sy*sy - 2 * sx * sxy * sy + nHits * sxy*sxy) / (nHits * sx2 - sx*sx);
1595 //fitError = (Float_t) sumY2 - (Float_t) (sumY*sumY) / nHits - fitSlope * ((Float_t) (sumXY - sumX*sumY) / nHits);
1597 Bool_t rejected = kFALSE;
1598 // deflection range table from DMEM
1599 if ((slope < fTrapConfig->GetDmem(0xc030 + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos)) ||
1600 (slope > fTrapConfig->GetDmem(0xc031 + 2*fFitPtr[cpu], fDetector, fRobPos, fMcmPos)))
1603 if (rejected && GetApplyCut())
1605 fMCMT[cpu] = 0x10001000; //??? AliTRDfeeParam::GetTrackletEndmarker();
1609 if (slope > 63 || slope < -64) { // wrapping in TRAP!
1610 AliError(Form("Overflow in slope: %i, tracklet discarded!", slope));
1611 fMCMT[cpu] = 0x10001000;
1615 slope = slope & 0x7F; // 7 bit
1617 if (offset > 0xfff || offset < -0xfff)
1618 AliWarning("Overflow in offset");
1619 offset = offset & 0x1FFF; // 13 bit
1621 qTotal = 0; // set to zero as long as no reasonable PID calculation is available
1622 // before: GetPID(q0/length/fgChargeNorm, q1/length/fgChargeNorm);
1625 AliWarning("Overflow in charge");
1626 qTotal = qTotal & 0xFF; // 8 bit, exactly like in the TRAP program
1628 // assemble and store the tracklet word
1629 fMCMT[cpu] = (qTotal << 24) | (padrow << 20) | (slope << 13) | offset;
1631 // calculate MC label
1635 if (fDigitsManager) {
1636 Int_t label[30] = {0}; // up to 30 different labels possible
1637 Int_t count[30] = {0};
1641 for (Int_t iHit = 0; iHit < fNHits; iHit++) {
1642 if ((fHits[iHit].fChannel - fFitPtr[cpu] < 0) ||
1643 (fHits[iHit].fChannel - fFitPtr[cpu] > 1))
1646 // counting contributing hits
1647 if (fHits[iHit].fTimebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS0) &&
1648 fHits[iHit].fTimebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE0))
1650 if (fHits[iHit].fTimebin >= fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQS1) &&
1651 fHits[iHit].fTimebin < fTrapConfig->GetTrapReg(AliTRDtrapConfig::kTPQE1))
1654 Int_t currLabel = fHits[iHit].fLabel;
1655 for (Int_t iLabel = 0; iLabel < nLabels; iLabel++) {
1656 if (currLabel == label[iLabel]) {
1658 if (count[iLabel] > maxCount) {
1659 maxCount = count[iLabel];
1666 if (currLabel >= 0) {
1667 label[nLabels++] = currLabel;
1671 mcLabel = label[maxIdx];
1673 new ((*fTrackletArray)[fTrackletArray->GetEntriesFast()]) AliTRDtrackletMCM((UInt_t) fMCMT[cpu], fDetector*2 + fRobPos%2, fRobPos, fMcmPos);
1674 ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetLabel(mcLabel);
1677 ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetNHits(fit0->fNhits + fit1->fNhits);
1678 ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetNHits0(nHits0);
1679 ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetNHits1(nHits1);
1680 ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetQ0(q0);
1681 ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetQ1(q1);
1682 ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetSlope(fitSlope);
1683 ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetOffset(fitOffset);
1684 ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetError(TMath::Sqrt(TMath::Abs(fitError)/nHits));
1686 // // cluster information
1687 // Float_t *res = new Float_t[nHits];
1688 // Float_t *qtot = new Float_t[nHits];
1690 // for (Int_t iHit = 0; iHit < fNHits; iHit++) {
1691 // // check if hit contributes
1692 // if (fHits[iHit].fChannel == fFitPtr[cpu]) {
1693 // res[nCls] = fHits[iHit].fYpos - (fitSlope * fHits[iHit].fTimebin + fitOffset);
1694 // qtot[nCls] = fHits[iHit].fQtot;
1697 // else if (fHits[iHit].fChannel == fFitPtr[cpu] + 1) {
1698 // res[nCls] = fHits[iHit].fYpos + 256 - (fitSlope * fHits[iHit].fTimebin + fitOffset);
1699 // qtot[nCls] = fHits[iHit].fQtot;
1703 // ((AliTRDtrackletMCM*) (*fTrackletArray)[fTrackletArray->GetEntriesFast()-1])->SetClusters(res, qtot, nCls);
1708 AliError(Form("Strange fit error: %f from Sx: %i, Sy: %i, Sxy: %i, Sx2: %i, Sy2: %i, nHits: %i",
1709 fitError, sumX, sumY, sumXY, sumX2, sumY2, nHits));
1710 AliDebug(3, Form("fit slope: %f, offset: %f, error: %f",
1711 fitSlope, fitOffset, TMath::Sqrt(TMath::Abs(fitError)/nHits)));
1717 void AliTRDmcmSim::Tracklet()
1719 // Run the tracklet calculation by calling sequentially:
1720 // CalcFitreg(); TrackletSelection(); FitTracklet()
1721 // and store the tracklets
1723 if (!fInitialized) {
1724 AliError("Called uninitialized! Nothing done!");
1728 fTrackletArray->Delete();
1733 TrackletSelection();
1737 Bool_t AliTRDmcmSim::StoreTracklets()
1739 // store the found tracklets via the loader
1741 if (fTrackletArray->GetEntriesFast() == 0)
1744 AliRunLoader *rl = AliRunLoader::Instance();
1745 AliDataLoader *dl = 0x0;
1747 dl = rl->GetLoader("TRDLoader")->GetDataLoader("tracklets");
1749 AliError("Could not get the tracklets data loader!");
1753 TTree *trackletTree = dl->Tree();
1754 if (!trackletTree) {
1756 trackletTree = dl->Tree();
1759 AliTRDtrackletMCM *trkl = 0x0;
1760 TBranch *trkbranch = trackletTree->GetBranch("mcmtrklbranch");
1762 trkbranch = trackletTree->Branch("mcmtrklbranch", "AliTRDtrackletMCM", &trkl, 32000);
1764 for (Int_t iTracklet = 0; iTracklet < fTrackletArray->GetEntriesFast(); iTracklet++) {
1765 trkl = ((AliTRDtrackletMCM*) (*fTrackletArray)[iTracklet]);
1766 trkbranch->SetAddress(&trkl);
1773 void AliTRDmcmSim::WriteData(AliTRDarrayADC *digits)
1775 // write back the processed data configured by EBSF
1776 // EBSF = 1: unfiltered data; EBSF = 0: filtered data
1777 // zero-suppressed valued are written as -1 to digits
1779 if( !CheckInitialized() )
1782 Int_t offset = (fMcmPos % 4 + 1) * 21 + (fRobPos % 2) * 84 - 1;
1784 if (fTrapConfig->GetTrapReg(AliTRDtrapConfig::kEBSF) != 0) // store unfiltered data
1786 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
1787 if (~fZSMap[iAdc] == 0) {
1788 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
1789 digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, -1);
1792 else if (iAdc < 2 || iAdc == 20) {
1793 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
1794 digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, (fADCR[iAdc][iTimeBin] >> fgkAddDigits) - fgAddBaseline);
1800 for (Int_t iAdc = 0; iAdc < fgkNADC; iAdc++) {
1801 if (~fZSMap[iAdc] != 0) {
1802 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
1803 digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, (fADCF[iAdc][iTimeBin] >> fgkAddDigits) - fgAddBaseline);
1807 for (Int_t iTimeBin = 0; iTimeBin < fNTimeBin; iTimeBin++) {
1808 digits->SetDataByAdcCol(GetRow(), offset - iAdc, iTimeBin, -1);
1815 // help functions, to be cleaned up
1817 UInt_t AliTRDmcmSim::AddUintClipping(UInt_t a, UInt_t b, UInt_t nbits) const
1820 // This function adds a and b (unsigned) and clips to
1821 // the specified number of bits.
1827 UInt_t maxv = (1 << nbits) - 1;;
1833 if ((sum < a) || (sum < b))
1839 void AliTRDmcmSim::Sort2(UShort_t idx1i, UShort_t idx2i, \
1840 UShort_t val1i, UShort_t val2i, \
1841 UShort_t *idx1o, UShort_t *idx2o, \
1842 UShort_t *val1o, UShort_t *val2o) const
1844 // sorting for tracklet selection
1862 void AliTRDmcmSim::Sort3(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, \
1863 UShort_t val1i, UShort_t val2i, UShort_t val3i, \
1864 UShort_t *idx1o, UShort_t *idx2o, UShort_t *idx3o, \
1865 UShort_t *val1o, UShort_t *val2o, UShort_t *val3o)
1867 // sorting for tracklet selection
1872 if (val1i > val2i) sel=4; else sel=0;
1873 if (val2i > val3i) sel=sel + 2;
1874 if (val3i > val1i) sel=sel + 1;
1877 case 6 : // 1 > 2 > 3 => 1 2 3
1878 case 0 : // 1 = 2 = 3 => 1 2 3 : in this case doesn't matter, but so is in hardware!
1887 case 4 : // 1 > 2, 2 <= 3, 3 <= 1 => 1 3 2
1896 case 2 : // 1 <= 2, 2 > 3, 3 <= 1 => 2 1 3
1905 case 3 : // 1 <= 2, 2 > 3, 3 > 1 => 2 3 1
1914 case 1 : // 1 <= 2, 2 <= 3, 3 > 1 => 3 2 1
1923 case 5 : // 1 > 2, 2 <= 3, 3 > 1 => 3 1 2
1932 default: // the rest should NEVER happen!
1933 AliError("ERROR in Sort3!!!\n");
1938 void AliTRDmcmSim::Sort6To4(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, UShort_t idx4i, UShort_t idx5i, UShort_t idx6i, \
1939 UShort_t val1i, UShort_t val2i, UShort_t val3i, UShort_t val4i, UShort_t val5i, UShort_t val6i, \
1940 UShort_t *idx1o, UShort_t *idx2o, UShort_t *idx3o, UShort_t *idx4o, \
1941 UShort_t *val1o, UShort_t *val2o, UShort_t *val3o, UShort_t *val4o)
1943 // sorting for tracklet selection
1945 UShort_t idx21s, idx22s, idx23s, dummy;
1946 UShort_t val21s, val22s, val23s;
1947 UShort_t idx23as, idx23bs;
1948 UShort_t val23as, val23bs;
1950 Sort3(idx1i, idx2i, idx3i, val1i, val2i, val3i,
1951 idx1o, &idx21s, &idx23as,
1952 val1o, &val21s, &val23as);
1954 Sort3(idx4i, idx5i, idx6i, val4i, val5i, val6i,
1955 idx2o, &idx22s, &idx23bs,
1956 val2o, &val22s, &val23bs);
1958 Sort2(idx23as, idx23bs, val23as, val23bs, &idx23s, &dummy, &val23s, &dummy);
1960 Sort3(idx21s, idx22s, idx23s, val21s, val22s, val23s,
1961 idx3o, idx4o, &dummy,
1962 val3o, val4o, &dummy);
1966 void AliTRDmcmSim::Sort6To2Worst(UShort_t idx1i, UShort_t idx2i, UShort_t idx3i, UShort_t idx4i, UShort_t idx5i, UShort_t idx6i, \
1967 UShort_t val1i, UShort_t val2i, UShort_t val3i, UShort_t val4i, UShort_t val5i, UShort_t val6i, \
1968 UShort_t *idx5o, UShort_t *idx6o)
1970 // sorting for tracklet selection
1972 UShort_t idx21s, idx22s, idx23s, dummy1, dummy2, dummy3, dummy4, dummy5;
1973 UShort_t val21s, val22s, val23s;
1974 UShort_t idx23as, idx23bs;
1975 UShort_t val23as, val23bs;
1977 Sort3(idx1i, idx2i, idx3i, val1i, val2i, val3i,
1978 &dummy1, &idx21s, &idx23as,
1979 &dummy2, &val21s, &val23as);
1981 Sort3(idx4i, idx5i, idx6i, val4i, val5i, val6i,
1982 &dummy1, &idx22s, &idx23bs,
1983 &dummy2, &val22s, &val23bs);
1985 Sort2(idx23as, idx23bs, val23as, val23bs, &idx23s, idx5o, &val23s, &dummy1);
1987 Sort3(idx21s, idx22s, idx23s, val21s, val22s, val23s,
1988 &dummy1, &dummy2, idx6o,
1989 &dummy3, &dummy4, &dummy5);
1993 // ----- I/O implementation -----
1995 ostream& AliTRDmcmSim::Text(ostream& os)
1997 // manipulator to activate output in text format (default)
1999 os.iword(fgkFormatIndex) = 0;
2003 ostream& AliTRDmcmSim::Cfdat(ostream& os)
2005 // manipulator to activate output in CFDAT format
2006 // to send to the FEE via SCSN
2008 os.iword(fgkFormatIndex) = 1;
2012 ostream& AliTRDmcmSim::Raw(ostream& os)
2014 // manipulator to activate output as raw data dump
2016 os.iword(fgkFormatIndex) = 2;
2020 ostream& operator<<(ostream& os, const AliTRDmcmSim& mcm)
2022 // output implementation
2024 // no output for non-initialized MCM
2025 if (!mcm.CheckInitialized())
2028 // ----- human-readable output -----
2029 if (os.iword(AliTRDmcmSim::fgkFormatIndex) == 0) {
2031 os << "MCM " << mcm.fMcmPos << " on ROB " << mcm.fRobPos <<
2032 " in detector " << mcm.fDetector << std::endl;
2034 os << "----- Unfiltered ADC data (10 bit) -----" << std::endl;
2036 for (Int_t iChannel = 0; iChannel < mcm.fgkNADC; iChannel++)
2037 os << std::setw(5) << iChannel;
2039 for (Int_t iTimeBin = 0; iTimeBin < mcm.fNTimeBin; iTimeBin++) {
2040 os << "tb " << std::setw(2) << iTimeBin << ":";
2041 for (Int_t iChannel = 0; iChannel < mcm.fgkNADC; iChannel++) {
2042 os << std::setw(5) << (mcm.fADCR[iChannel][iTimeBin] >> mcm.fgkAddDigits);
2047 os << "----- Filtered ADC data (10+2 bit) -----" << std::endl;
2049 for (Int_t iChannel = 0; iChannel < mcm.fgkNADC; iChannel++)
2050 os << std::setw(4) << iChannel
2051 << ((~mcm.fZSMap[iChannel] != 0) ? "!" : " ");
2053 for (Int_t iTimeBin = 0; iTimeBin < mcm.fNTimeBin; iTimeBin++) {
2054 os << "tb " << std::setw(2) << iTimeBin << ":";
2055 for (Int_t iChannel = 0; iChannel < mcm.fgkNADC; iChannel++) {
2056 os << std::setw(4) << (mcm.fADCF[iChannel][iTimeBin])
2057 << (((mcm.fZSMap[iChannel] & (1 << iTimeBin)) == 0) ? "!" : " ");
2063 // ----- CFDAT output -----
2064 else if(os.iword(AliTRDmcmSim::fgkFormatIndex) == 1) {
2066 Int_t addrOffset = 0x2000;
2067 Int_t addrStep = 0x80;
2069 for (Int_t iTimeBin = 0; iTimeBin < mcm.fNTimeBin; iTimeBin++) {
2070 for (Int_t iChannel = 0; iChannel < mcm.fgkNADC; iChannel++) {
2071 os << std::setw(5) << 10
2072 << std::setw(5) << addrOffset + iChannel * addrStep + iTimeBin
2073 << std::setw(5) << (mcm.fADCF[iChannel][iTimeBin])
2074 << std::setw(5) << dest << std::endl;
2080 // ----- raw data ouptut -----
2081 else if (os.iword(AliTRDmcmSim::fgkFormatIndex) == 2) {
2082 Int_t bufSize = 300;
2083 UInt_t *buf = new UInt_t[bufSize];
2085 Int_t bufLength = mcm.ProduceRawStream(&buf[0], bufSize);
2087 for (Int_t i = 0; i < bufLength; i++)
2088 std::cout << "0x" << std::hex << buf[i] << std::endl;
2094 os << "unknown format set" << std::endl;