From 7925de54d12b4c9ac667ad314c151d1597281a94 Mon Sep 17 00:00:00 2001 From: cblume Date: Tue, 6 Feb 2007 12:15:02 +0000 Subject: [PATCH] New TRD raw data reader (v1 + v2) by Christian --- TRD/AliTRDRawStream.cxx | 941 +++++++++++++++++++++++++++++++++++++++- TRD/AliTRDRawStream.h | 155 +++++-- TRD/AliTRDdigitizer.cxx | 106 ++--- TRD/AliTRDgeometry.cxx | 202 ++++++--- TRD/AliTRDgeometry.h | 47 +- TRD/AliTRDrawData.cxx | 241 ++++++---- TRD/AliTRDrawData.h | 24 +- 7 files changed, 1442 insertions(+), 274 deletions(-) diff --git a/TRD/AliTRDRawStream.cxx b/TRD/AliTRDRawStream.cxx index ad0bd6fefb0..6875f38a2ac 100644 --- a/TRD/AliTRDRawStream.cxx +++ b/TRD/AliTRDRawStream.cxx @@ -24,12 +24,18 @@ // it returns kFALSE. // // Several getters provide information about the current digit. // // // +// Author: C. Lippmann (C.Lippmann@gsi.de) // +// // /////////////////////////////////////////////////////////////////////////////// #include "AliLog.h" #include "AliRawReader.h" +#include "AliTRDdigitsManager.h" +#include "AliTRDdataArrayI.h" #include "AliTRDRawStream.h" +#include "AliTRDgeometry.h" +#include "AliTRDCommonParam.h" #include "AliTRDcalibDB.h" ClassImp(AliTRDRawStream) @@ -37,7 +43,43 @@ ClassImp(AliTRDRawStream) //_____________________________________________________________________________ AliTRDRawStream::AliTRDRawStream() :TObject() - ,fRawReader(0) + ,fSig() + ,fADC(0) + ,fTB(0) + ,fEv(0) + ,fROB(0) + ,fMCM(0) + ,fSM(0) + ,fLAYER(0) + ,fSTACK(0) + ,fROC(0) + ,fSIDE(0) + ,fDCS(0) + ,fROW(0) + ,fCOL(0) + ,fBCctr(0) + ,fPTctr(0) + ,fPTphase(0) + ,fRVmajor(0) + ,fRVminor(0) + ,fHCHWords(0) + ,fTBins(0) + ,fTCon(0) + ,fPEDon(0) + ,fGAINon(0) + ,fFiltered(0) + ,fHCHctr1(0) + ,fHCHctr2(0) + ,fMCMHctr1(0) + ,fMCMHctr2(0) + ,fGTUctr1(0) + ,fGTUctr2(0) + ,fTracklPID(0) + ,fTracklDefL(0) + ,fTracklPadPos(0) + ,fTracklPadRow(0) + ,fGTUlinkMask() + ,fRawReader(NULL) ,fCount(0) ,fDetector(-1) ,fPrevDetector(-1) @@ -48,16 +90,148 @@ AliTRDRawStream::AliTRDRawStream() ,fPrevColumn(-1) ,fTime(-1) ,fSignal(-1) + ,fRawVersion(1) + ,fDataWord(0) + ,fStatus(0) + ,fRowMax(0) + ,fColMax(0) + ,fChamberDone() + ,fGeo(NULL) + ,fDigitsManager(NULL) + ,fDigits(NULL) + ,fTrack0(NULL) + ,fTrack1(NULL) + ,fTrack2(NULL) { // // Default constructor // + for (Int_t i = 0; i < 540; i++) { + fChamberDone[i] = 0; + } + +} + +//_____________________________________________________________________________ +AliTRDRawStream::AliTRDRawStream(AliRawReader *rawReader + , AliTRDdigitsManager *man + , AliTRDdataArrayI *dig) + :TObject() + ,fSig() + ,fADC(0) + ,fTB(0) + ,fEv(0) + ,fROB(0) + ,fMCM(0) + ,fSM(0) + ,fLAYER(0) + ,fSTACK(0) + ,fROC(0) + ,fSIDE(0) + ,fDCS(0) + ,fROW(0) + ,fCOL(0) + ,fBCctr(0) + ,fPTctr(0) + ,fPTphase(0) + ,fRVmajor(0) + ,fRVminor(0) + ,fHCHWords(0) + ,fTBins(0) + ,fTCon(0) + ,fPEDon(0) + ,fGAINon(0) + ,fFiltered(0) + ,fHCHctr1(0) + ,fHCHctr2(0) + ,fMCMHctr1(0) + ,fMCMHctr2(0) + ,fGTUctr1(0) + ,fGTUctr2(0) + ,fTracklPID(0) + ,fTracklDefL(0) + ,fTracklPadPos(0) + ,fTracklPadRow(0) + ,fGTUlinkMask() + ,fRawReader(rawReader) + ,fCount(0) + ,fDetector(-1) + ,fPrevDetector(-1) + ,fNPads(-1) + ,fRow(-1) + ,fPrevRow(-1) + ,fColumn(-1) + ,fPrevColumn(-1) + ,fTime(-1) + ,fSignal(-1) + ,fRawVersion(1) + ,fDataWord(0) + ,fStatus(0) + ,fRowMax(0) + ,fColMax(0) + ,fChamberDone() + ,fGeo(NULL) + ,fDigitsManager(man) + ,fDigits(dig) + ,fTrack0(NULL) + ,fTrack1(NULL) + ,fTrack2(NULL) + +{ + // + // Create an object to read TRD raw digits + // + + fGeo = new AliTRDgeometry(); + + fRawReader->Select("TRD"); + + for (Int_t i = 0; i < 540; i++) { + fChamberDone[i] = 0; + } + } //_____________________________________________________________________________ -AliTRDRawStream::AliTRDRawStream(AliRawReader* rawReader) +AliTRDRawStream::AliTRDRawStream(AliRawReader *rawReader) :TObject() + ,fSig() + ,fADC(0) + ,fTB(0) + ,fEv(0) + ,fROB(0) + ,fMCM(0) + ,fSM(0) + ,fLAYER(0) + ,fSTACK(0) + ,fROC(0) + ,fSIDE(0) + ,fDCS(0) + ,fROW(0) + ,fCOL(0) + ,fBCctr(0) + ,fPTctr(0) + ,fPTphase(0) + ,fRVmajor(0) + ,fRVminor(0) + ,fHCHWords(0) + ,fTBins(0) + ,fTCon(0) + ,fPEDon(0) + ,fGAINon(0) + ,fFiltered(0) + ,fHCHctr1(0) + ,fHCHctr2(0) + ,fMCMHctr1(0) + ,fMCMHctr2(0) + ,fGTUctr1(0) + ,fGTUctr2(0) + ,fTracklPID(0) + ,fTracklDefL(0) + ,fTracklPadPos(0) + ,fTracklPadRow(0) + ,fGTUlinkMask() ,fRawReader(rawReader) ,fCount(0) ,fDetector(-1) @@ -69,6 +243,19 @@ AliTRDRawStream::AliTRDRawStream(AliRawReader* rawReader) ,fPrevColumn(-1) ,fTime(-1) ,fSignal(-1) + ,fRawVersion(1) + ,fDataWord(0) + ,fStatus(0) + ,fRowMax(0) + ,fColMax(0) + ,fChamberDone() + ,fGeo(NULL) + ,fDigitsManager(NULL) + ,fDigits(NULL) + ,fTrack0(NULL) + ,fTrack1(NULL) + ,fTrack2(NULL) + { // // Create an object to read TRD raw digits @@ -76,22 +263,75 @@ AliTRDRawStream::AliTRDRawStream(AliRawReader* rawReader) fRawReader->Select("TRD"); + for (Int_t i = 0; i < 540; i++) { + fChamberDone[i] = 0; + } + } //_____________________________________________________________________________ -AliTRDRawStream::AliTRDRawStream(const AliTRDRawStream& stream) : - TObject(stream), - fRawReader(NULL), - fCount(0), - fDetector(-1), - fPrevDetector(-1), - fNPads(-1), - fRow(-1), - fPrevRow(-1), - fColumn(-1), - fPrevColumn(-1), - fTime(-1), - fSignal(-1) +AliTRDRawStream::AliTRDRawStream(const AliTRDRawStream& stream) + :TObject(stream) + ,fSig() + ,fADC(0) + ,fTB(0) + ,fEv(0) + ,fROB(0) + ,fMCM(0) + ,fSM(0) + ,fLAYER(0) + ,fSTACK(0) + ,fROC(0) + ,fSIDE(0) + ,fDCS(0) + ,fROW(0) + ,fCOL(0) + ,fBCctr(0) + ,fPTctr(0) + ,fPTphase(0) + ,fRVmajor(0) + ,fRVminor(0) + ,fHCHWords(0) + ,fTBins(0) + ,fTCon(0) + ,fPEDon(0) + ,fGAINon(0) + ,fFiltered(0) + ,fHCHctr1(0) + ,fHCHctr2(0) + ,fMCMHctr1(0) + ,fMCMHctr2(0) + ,fGTUctr1(0) + ,fGTUctr2(0) + ,fTracklPID(0) + ,fTracklDefL(0) + ,fTracklPadPos(0) + ,fTracklPadRow(0) + ,fGTUlinkMask() + ,fRawReader(NULL) + ,fCount(0) + ,fDetector(-1) + ,fPrevDetector(-1) + ,fNPads(-1) + ,fRow(-1) + ,fPrevRow(-1) + ,fColumn(-1) + ,fPrevColumn(-1) + ,fTime(-1) + ,fSignal(-1) + ,fRawVersion(1) + ,fDataWord(0) + ,fStatus(0) + ,fRowMax(0) + ,fColMax(0) + ,fChamberDone() + ,fGeo(NULL) + ,fDigitsManager(NULL) + ,fDigits(NULL) + ,fTrack0(NULL) + ,fTrack1(NULL) + ,fTrack2(NULL) + { // // Copy constructor @@ -121,13 +361,38 @@ AliTRDRawStream::~AliTRDRawStream() // Destructor // + delete fGeo; + delete fRawReader; + //delete fDigitsManager; + delete fDigits; + delete fTrack0; + delete fTrack1; + delete fTrack2; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDRawStream::SetRawVersion(Int_t rv) +{ + // + // Set the raw data version + // + + if ( rv >= 0 && rv <= 2 ) { + fRawVersion = rv; + return kTRUE; + } + + return kFALSE; + } //_____________________________________________________________________________ Bool_t AliTRDRawStream::Next() { // - // Read the next raw digit + // This is Bogdans code for reading raw data (offline use only). + // It is used for fRawVersion == 0. This funcyion read the next raw digit. // Returns kFALSE if there is no digit left // @@ -136,17 +401,19 @@ Bool_t AliTRDRawStream::Next() fPrevColumn = fColumn; UChar_t data; - AliTRDcalibDB* calibration = AliTRDcalibDB::Instance(); - if (!calibration) - return kFALSE; + AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); + if (!calibration) return kFALSE; Int_t timeBins = calibration->GetNumberOfTimeBins(); while (fCount >= 0) { while (fCount == 0) { // next detector + // read the flag - if (!fRawReader->ReadNextChar(data)) return kFALSE; + if (!fRawReader->ReadNextChar(data)) { + return kFALSE; + } if (data != 0xBB) { AliError(Form("wrong flag: %x", data)); fCount = -1; @@ -259,3 +526,637 @@ Bool_t AliTRDRawStream::Next() return kFALSE; } + +//____________________________________________________________________________ +Bool_t AliTRDRawStream::ReadAll() +{ + + // + // Read all TRD raw data word (32 bits). This is for all FrawVersion > 0. + // Return kFALSE if something is not cool + // + // by C. Lippmann + // + + AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance(); + if (!commonParam) { + AliError("Could not get common parameters"); + return kFALSE; + } + + AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); + if (!calibration) { + AliError("Could not get calibration object"); + return kFALSE; + } + + UInt_t timeTotal = calibration->GetNumberOfTimeBins(); + + // The number of data words needed for this number of time bins (there + // are 3 time bins in one word) + UInt_t timeWords = ( timeTotal%3 == 0 ) ? timeTotal/3 : timeTotal/3 + 1; + + AliDebug(2, Form("Number of Timebins read from CDB: %d", timeTotal)); + + UInt_t TBswitch = 3; + UInt_t TBswitchCtr = 0; + Int_t WordCtr = 0; + Int_t EqID = 0; + Int_t datasize = 0; + Int_t iDET = 0; + + fHCHctr1 = fHCHctr2 = 0; + fGTUctr1 = fGTUctr2 = -1; + + AliInfo("Converting TRD raw data to digits ..."); + + while ( 1 ) { // loop over all supermodules + + WordCtr = 0; + fHCHctr1 = 0; + fMCMHctr1 = 0; + + // + // 0) Find first GTU Link Mask and test if we can read data + // + do { + + if ( !fRawReader->ReadNextInt( fDataWord ) ) { + AliInfo(Form("Finished processing TRD raw data: Found %d Half-Chambers", fHCHctr2)); + return kTRUE; + } + WordCtr++; + + // After reading the first word check for size of this data and get Eq. ID + if ( WordCtr == 1 ) { + datasize = fRawReader->GetDataSize()/4; // Size of this payload is in 32bit words + EqID = fRawReader->GetEquipmentId(); // Get Equipment ID + } + + // GTU Link Mask? + if ( (fDataWord & 0xfffff000) == 0xe0000000 ) { + fStatus = 1; // GTU link mask found + DecodeGTUlinkMask(); + break; + } + else { + AliError(Form("Equipment %d: First data word is not GTU Link Mask!", EqID)); + return kFALSE; + } + + } + while ( WordCtr < datasize ); + + // + // loop over all half chambers in one supermodule + // + while ( WordCtr < datasize ) { + + // + // 1) Find end_of_tracklet_marker + // + while ( WordCtr < datasize ) { + + if ( !fRawReader->ReadNextInt( fDataWord ) ) { + AliError("Could not read data"); + return kFALSE; + } + WordCtr++; + + // GTU Link Mask? + if ( (fDataWord & 0xfffff000) == 0xe0000000 ) { + DecodeGTUlinkMask(); + continue; + } + + // end_of_tracklet_marker? + if ( fDataWord == end_of_tracklet_marker ) { + AliDebug(3, "end_of_tracklet_marker found"); + fStatus = 1; + break; + } + else { + // Tracklets found + AliDebug(3, "Tracklet found"); + DecodeTracklet(); + } + + } + + if ( fStatus == 0 ) break; + + // + // 2) Look for non-end_of_tracklet_marker + // + fStatus = 0; + while ( WordCtr < datasize ) { + + if ( !fRawReader->ReadNextInt( fDataWord ) ) { + AliError("Could not read data"); + return kFALSE; + } + WordCtr++; + //printf("Word %d: 0x%08x\n", WordCtr, fDataWord); + + if ( fDataWord != end_of_tracklet_marker ) { + fStatus = 1; + break; + } + + } + + if ( fStatus == 0 ) break; + + // + // 3) This Word must be Half Chamber Header + // + fStatus = 0; + if ( (fDataWord & 0x00000003) == 1 ) { // HC header + + // If both half chambers of chamber corresponding to previous header + // were already processed, we can compress these digits + iDET = fGeo->GetDetector(fLAYER, fSTACK, fSM); + if ( fChamberDone[iDET] == 2 ) { + fDigits->Compress(1,0); + fTrack0->Compress(1,0); + fTrack1->Compress(1,0); + fTrack2->Compress(1,0); + } + + // Read from new HC header the chamber position (fLAYER, fSTACK, fSM) + DecodeHCheader(timeTotal); + WordCtr += fHCHWords; + iDET = fGeo->GetDetector(fLAYER, fSTACK, fSM); + fRowMax = commonParam->GetRowMax(fLAYER,fSTACK,fSM); + fColMax = commonParam->GetColMax(fROC); + + // Add a container for the digits of this detector + fDigits = fDigitsManager->GetDigits(iDET); + fTrack0 = fDigitsManager->GetDictionary(iDET,0); + fTrack1 = fDigitsManager->GetDictionary(iDET,1); + fTrack2 = fDigitsManager->GetDictionary(iDET,2); + + fChamberDone[iDET]++; + + // Allocate memory if it was not already done + if (fDigits->GetNtime() == 0) { + fDigits->Allocate(fRowMax,fColMax,timeTotal); + fTrack0->Allocate(fRowMax,fColMax,timeTotal); + fTrack1->Allocate(fRowMax,fColMax,timeTotal); + fTrack2->Allocate(fRowMax,fColMax,timeTotal); + } + + fMCMHctr2 = 0; + + } + + // + // 4) Scan MCM data + // + fStatus = 0; + while ( WordCtr < datasize ) { + + if ( !fRawReader->ReadNextInt( fDataWord ) ) { + AliError("Could not read data"); + return kFALSE; + } + WordCtr++; + //printf("Word %d: 0x%08x\n", WordCtr, fDataWord); + + //if ( WordCtr == 4*datasize ) AliInfo(Form("Achtung! WordCtr=%d (%d)", WordCtr, 4*datasize)); + + if( (fDataWord & 0x0000000f) == 0xC ) { // MCM Header + DecodeMCMheader(); + if ( fMCM < 0 || fMCM > 15 || fROB < 0 || fROB > 7 ) { + AliError("Wrong fMCM or fROB. Skip this data"); + break; + } + TBswitch = 3; // For first adc channel we expect: (fDataWord & 3) = 3 + TBswitchCtr = 0; // + fADC = fTB = 0; // Reset Counter + fStatus = 1; // Now 1 means MCM header is found + continue; + } + + // End of half-chamber data, finished: + if ( fDataWord == end_of_event_marker ) { + fGTUctr1 = -1; + break; + } + + if ( fStatus == 1 ) { // MCM header is set, ADC data is valid. + + // + // Found some data. Decode it now: + // + if ( (fDataWord & 0x00000003) != 0x2 && (fDataWord & 0x00000003) != 0x3) { + AliError(Form("Data %08x : Data Word ends neither with 11 nor 10", (Int_t)fDataWord)); + break; + } + + if ( (fDataWord & 0x00000003) != TBswitch ) { // Next ADC channel found + //if ( fTB+1 != timeBins ) AliError(Form("Time bins in data (%d) != DB (%d)", fTB+1, timeBins)); + TBswitch = (TBswitch & 2) | !(TBswitch & 1); // 0x3 <--> 0x2 + TBswitchCtr = 0; + fADC++; + fTB=0; + } + + TBswitchCtr++; // Just read one word + + // We have only timeTotal time bins + if ( TBswitchCtr > timeWords ) { + AliError(Form("Data is strange. Already found %d words for this ADC channel", (Int_t)TBswitchCtr)); + continue; + } + + // We have only 21 ADC channels. + if ( fADC > 20 ) { + AliError(Form("Data %08x : Data is strange. fADC is already %d", (Int_t)fDataWord, + (Int_t)fADC)); + continue; + } + + // There are 18 pads connected to each MCM ADC channels 2...19. The + // other channels cross to other MCMs and are good for online tracking + // in the MCM. + if ( fADC > 1 && fADC < (Int_t)fGeo->ADCmax()-1 ) { + + fCOL = fGeo->GetPadCol(fROB, fMCM, fADC); + + // We have only 144 Pad Columns + if ( fCOL > fColMax-1 || fCOL < 0 ) { + AliError(Form("SM%d L%dS%d: Wrong Pad column (%d) fROB=%d, fSIDE=%d, fMCM=%02d", fSM, + fLAYER, fSTACK, fCOL, fROB, fSIDE, fMCM )); + } + + // Decode 32 bit data words with information from 3 time bins and copy the data + fSig[0] = (fDataWord & 0x00000ffc) >> 2; + fSig[1] = (fDataWord & 0x003ff000) >> 12; + fSig[2] = (fDataWord & 0xffc00000) >> 22; + + // Print data to screen: + AliDebug(5, Form("SM%d L%dS%d: ROB%d MCM=%d ADC=%d (ROW=%d COL=%d): Data %04d %04d %04d\n", + fSM, fLAYER, fSTACK, fROB, fMCM, fADC, fROW, fCOL, fSig[0], fSig[1], fSig[2])); + + // Write Digits + if ( fCOL >= 0 && fCOL < fColMax && fROW >= 0 && fROW < fRowMax ) { // A real pad + for ( Int_t ctr = 0; ctr <3; ctr++ ) { + if ( fTB+ctr < (Int_t)timeTotal ) { + fDigits->SetDataUnchecked(fROW, fCOL, fTB+ctr, fSig[ctr]); + fTrack0->SetDataUnchecked(fROW, fCOL, fTB+ctr, 0); + fTrack1->SetDataUnchecked(fROW, fCOL, fTB+ctr, 0); + fTrack2->SetDataUnchecked(fROW, fCOL, fTB+ctr, 0); + } + } + } + + fTB += 3; + + } + else { + + fCOL = -1; + + } + + } + + } + + AliDebug(2, Form("SM%d L%dS%d side %x: Processed %d MCMs.", fSM, fLAYER, fSTACK, fSIDE+10, fMCMHctr2)); + + } // End Half-Chamber loop + + AliDebug(1, Form("SM%d (Eq %d): Processed %d HC (%d MCMs)", fSM, EqID, fHCHctr1, fMCMHctr1)); + + } // End Super Module loop + + return kTRUE; + +} + +//============================================================================ +// Decoding functions +//============================================================================ + +//____________________________________________________________________________ +void AliTRDRawStream::DecodeHCheader(Int_t timeBins) +{ + // + // Decode a half chamber header + // + + if ( (fDataWord >> 31) != 1 ) { + + if ( fRawVersion == 1 ) { + DecodeHCheaderV1(); + } + else { + AliError(Form("Mismatch between fRawVersion (%d) and HC header signature", fRawVersion)); + } + return; + + } + else { + + fRVmajor = (fDataWord >> 24) & 0x7f; + fRVminor = (fDataWord >> 17) & 0x7f; + if ( fRawVersion != fRVmajor ) { + AliError(Form("Mismatch between fRawVersion (%d) and fRVmajor from HC header(%d)" + ,fRawVersion,fRVmajor)); + } + if (fRawVersion == 2 ) { + DecodeHCheaderV2(timeBins); + } + return; + + } + + AliError(Form(" Unsupported raw version: %d", fRawVersion)); + return; + +} + +//____________________________________________________________________________ +void AliTRDRawStream::DecodeHCheaderV1() +{ + + // + // Decode the HC header (fRawVersion == 1, SM I Commissioning 06) + // + + if ( (fDataWord & 0x3) == 1 ) { + + fDCS = (fDataWord >> 20); + fSM = (fDataWord >> 15) & 0x1f; + fLAYER = (fDataWord >> 12) & 0x7; + fSTACK = (fDataWord >> 9) & 0x7; + fSIDE = (fDataWord >> 8) & 0x1; + + fROC = fGeo->GetDetectorSec(fLAYER, fSTACK); + + //AliDebug(3, Form("0x%08x: HC header: dcs=%d; sm=%d; roc=%d; side=%x", fDataWord, fDCS, fSM, fROC, fSIDE+10)); + if ((fSM < 0) || + (fSM > 17) || + (fLAYER < 0) || + (fLAYER > 5) || + (fSTACK < 0) || + (fSTACK > 4) || + (fSIDE < 0) || + (fSIDE > 1)) { + AliError(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.", + fDataWord, fDCS, fSM, fLAYER, fSTACK)); + } + else { + fStatus = 1; + fHCHctr1++; + fHCHctr2++; + } + fHCHWords = 0; + + } + else { + + AliError(Form("0x%08x: No HC header when it was expected.", fDataWord)); + + } + +} + + +//____________________________________________________________________________ +void AliTRDRawStream::DecodeHCheaderV2(Int_t timeBins) +{ + // + // Decode the HC header (fRawVersion == 2, Full raw production) + // + + // 1st word + if ( (fDataWord & 0x3) == 1 ) { + + fHCHWords = (fDataWord >> 14) & 0x7; + fSM = (fDataWord >> 9) & 0x1f; + fLAYER = (fDataWord >> 6) & 0x7; + fSTACK = (fDataWord >> 3) & 0x7; + fSIDE = (fDataWord >> 2) & 0x1; + + fROC = fGeo->GetDetectorSec(fLAYER, fSTACK); + + AliDebug(3, Form("0x%08x: HC header: sm=%d; roc=%d; side=%x", fDataWord, fSM, fROC, fSIDE+10)); + + if ((fSM < 0) || + (fSM > 17) || + (fLAYER < 0) || + (fLAYER > 5) || + (fSTACK < 0) || + (fSTACK > 4) || + (fSIDE < 0) || + (fSIDE > 1)) { + AliError(Form("0x%08x: Strange HC header: dcs=%d; sm=%d; layer=%d; stack=%d.", + fDataWord, fDCS, fSM, fLAYER, fSTACK)); + } + else { + fStatus = 1; + fHCHctr1++; + fHCHctr2++; + } + } + else { + AliError(Form("0x%08x: No HC header when it was expected.", fDataWord)); + } + + // 2nd word + if ( fHCHWords >= 1 ) { + // read one more word + if ( !fRawReader->ReadNextInt( fDataWord ) ) { + AliError("Could not read data"); + return; + } + if ( (fDataWord & 0x3) == 1 ) { + + fBCctr = (fDataWord >> 16); + fPTctr = (fDataWord >> 12) & 0xf; + fPTphase = (fDataWord >> 8) & 0xf; + fTBins = ((fDataWord >> 2) & 0x3f) + 1; + + AliDebug(3, Form("0x%08x: HC header 2: BCctr=%d PTctr=%d PTph=%d TB=%d" + , fDataWord, fBCctr, fPTctr, fPTphase, fTBins)); + + if( fTBins != timeBins ) { + AliError(Form("Mismatch between Number of Time Bins from CDB (%d) and from HC header (%d)" + , timeBins, fTBins)); + } + + } + + } + + // 3rd word + if ( fHCHWords >= 2 ) { + // read one more word + if ( !fRawReader->ReadNextInt( fDataWord ) ) { + AliError("Could not read data"); + return; + } + if ( (fDataWord & 0x3) == 1 ) { + /* + Not finished. Next to come: + fTCon + fPEDon + fGAINon + fFiltered + ..... + */ + } + + } + +} + +//____________________________________________________________________________ +void AliTRDRawStream::DecodeMCMheader() +{ + // + // + // + + if ( fRawVersion >= 1 && fRawVersion <= 2 ) { + DecodeMCMheaderV1(); + return; + } + + AliError(Form(" Unsupported raw version: %d", fRawVersion)); + return; + +} + +//____________________________________________________________________________ +void AliTRDRawStream::DecodeMCMheaderV1() +{ + + // + // Decode the MCM header + // + + fMCM = (fDataWord & 0xff000000) >> 24; + fEv = (fDataWord & 0x00fffff0) >> 4; + + fROB = fMCM / 16; + fMCM = fMCM % 16; + + fROW = fGeo->GetPadRow(fROB, fMCM); + + AliDebug(4, Form("0x%08x: SM%d L%dS%d. MCM Header: fROB=%d fMCM=%02d fEv=%02d" + , fDataWord, fSM, fLAYER, fSTACK, fROB, fMCM, fEv)); + + if ( fROB % 2 == 0 && fSIDE == 1 ) { + AliError(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d" + , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM )); + } + if ( fROB % 2 != 0 && fSIDE == 0 ) { + AliError(Form("SM%d L%dS%d: Mismatch between fROB (%d) and fSIDE (%d): fMCM=%02d" + , fSM, fLAYER, fSTACK, fROB, fSIDE, fMCM )); + } + if ( (fSTACK == 2 && fROW > 11) || (fSTACK != 2 && fROW > 15) || fROW < 0 ) { + AliError(Form("SM%d L%dS%d: Wrong Padrow (%d) fROB=%d, fSIDE=%d, fMCM=%02d" + , fSM, fLAYER, fSTACK, fROW, fROB, fSIDE, fMCM )); + } + + fMCMHctr1++; + fMCMHctr2++; + +} + +//____________________________________________________________________________ +void AliTRDRawStream::DecodeTracklet() +{ + // + // + // + + if ( fRawVersion >= 1 && fRawVersion <= 2 ) { + DecodeTrackletV1(); + return; + } + + AliError(Form(" Unsupported raw version: %d", fRawVersion)); + return; + +} + +//____________________________________________________________________________ +void AliTRDRawStream::DecodeTrackletV1() +{ + + // + // Decode the Tracklet + // + // this function is not tested yet on real tracklets + // + + fTracklPID = (fDataWord >> 24) & 0xff; + fTracklPadRow = (fDataWord >> 20) & 0xf; // 0:15 + fTracklDefL = (fDataWord >> 13) & 0x7f; + fTracklPadPos = (fDataWord) & 0x1fff; + + fTracklPID /= (Float_t)((1<<8) - 1); // 0:1 (steps of 0.39%) + fTracklDefL = (fTracklDefL - ((1<< 7)-1)/2.) * 140.e-4; // -0.889:0.889cm + fTracklPadPos = (fTracklPadPos - ((1<<13)-1)/2.) * 160.e-4; // -65.528:65.528 cm + + AliDebug(4, Form("0x%08x: Tracklet found: SM%d L%dS%d side %x: PadRow=%d PadPos=%f DefL=%f PID=%f" + , fDataWord, fSM, fLAYER, fSTACK, fSIDE+10 + , fTracklPadRow, fTracklPadPos, fTracklDefL, fTracklPID)); + + if( (fSTACK == 2) && (fTracklPadRow >= (Int_t)fGeo->RowmaxC0) || + (fSTACK != 2) && (fTracklPadRow >= (Int_t)fGeo->RowmaxC1) ) { + AliError(Form("Strange Row read from Tracklet Word: %d", fTracklPadRow)); + } + +} + +//____________________________________________________________________________ +void AliTRDRawStream::DecodeGTUlinkMask() +{ + // + // + // + + if ( fRawVersion >= 1 && fRawVersion <= 2 ) { + DecodeGTUlinkMaskV1(); + return; + } + + AliError(Form(" Unsupported raw version: %d", fRawVersion)); + return; + +} + +//____________________________________________________________________________ +void AliTRDRawStream::DecodeGTUlinkMaskV1() +{ + + // + // Decode the link masks sent by the GTU. These marke the active optical links + // between GTU and Super Module. Up to now only fully active links are found + // (0xfff = 12 active links). + // + + if ( fGTUctr1 == -1 ) fGTUctr2++; + fGTUctr1++; + + //printf("fGTUctr=%d",fGTUctr); + //printf("fGTUctr1=%d, fGTUctr2=%d",fGTUctr1, fGTUctr2); + + if ( (fGTUctr1 >= 0) && (fGTUctr1 < 5) && (fGTUctr2 >= 0) && (fGTUctr2 < 18) ) { + fGTUlinkMask[fGTUctr2][fGTUctr1] = (fDataWord & 0xfff); + } + + for ( Int_t ctr = 0; ctr < 12; ctr++ ) { + if ( IsGTULinkActive(fGTUctr2, ctr/2, fGTUctr1, ctr%2) ) { + AliDebug(3, Form("SM %2d Stack %d: GTU Link %2d is active!", fGTUctr2, fGTUctr1, ctr)); + } + } + +} + diff --git a/TRD/AliTRDRawStream.h b/TRD/AliTRDRawStream.h index 5c64a5e3fbc..62510556c59 100644 --- a/TRD/AliTRDRawStream.h +++ b/TRD/AliTRDRawStream.h @@ -13,55 +13,148 @@ #include +class AliTRDgeometry; class AliRawReader; -class AliTRDparameter; +class AliTRDdigitsManager; +class AliTRDdataArrayI; + +// Some constants: +const UInt_t end_of_tracklet_marker = 0xAAAAAAAA; /*This marks the end of tracklet data words*/ +const UInt_t end_of_event_marker = 0x00000000; /*This marks the end of half-chamber-data*/ class AliTRDRawStream: public TObject { public : AliTRDRawStream(); - AliTRDRawStream(AliRawReader* rawReader); + AliTRDRawStream(AliRawReader *rawReader); + AliTRDRawStream(AliRawReader *rawReader, AliTRDdigitsManager *man, AliTRDdataArrayI *dig); virtual ~AliTRDRawStream(); - virtual Bool_t Next(); - - Int_t GetDetector() const { return fDetector; }; - Int_t GetPrevDetector() const { return fPrevDetector; }; - Bool_t IsNewDetector() const { return fDetector != fPrevDetector; }; - Int_t GetNPads() const { return fNPads; }; - Int_t GetRow() const { return fRow; }; - Int_t GetPrevRow() const { return fPrevRow; }; - Bool_t IsNewRow() const { return (fRow != fPrevRow) || IsNewDetector(); }; - Int_t GetColumn() const { return fColumn; }; - Int_t GetPrevColumn() const { return fPrevColumn; }; - Bool_t IsNewColumn() const { return (fColumn != fPrevColumn) || IsNewRow(); }; - Int_t GetTime() const { return fTime-1; }; - Int_t GetSignal() const { return fSignal; }; - - enum {kDDLOffset = 0x400}; // offset for DDL numbers + virtual Bool_t Next(); // Next function (for fRawVersion = 0 (Bogdans first version)) + virtual Bool_t ReadAll(); // Read function (for fRawVersion > 0) + + Int_t GetDetector() const { return fDetector; }; + Int_t GetPrevDetector() const { return fPrevDetector; }; + Bool_t IsNewDetector() const { return fDetector != fPrevDetector; }; + Int_t GetNPads() const { return fNPads; }; + Int_t GetRow() const { return fRow; }; + Int_t GetPrevRow() const { return fPrevRow; }; + Bool_t IsNewRow() const { return (fRow != fPrevRow) || IsNewDetector(); }; + Int_t GetColumn() const { return fColumn; }; + Int_t GetPrevColumn() const { return fPrevColumn; }; + Bool_t IsNewColumn() const { return (fColumn != fPrevColumn) || IsNewRow(); }; + Int_t GetTime() const { return fTime-1; }; + Int_t GetSignal() const { return fSignal; }; + + enum { kDDLOffset = 0x400 }; // Offset for DDL numbers + + void SetDigitsManager(AliTRDdigitsManager *man) { fDigitsManager = man; }; + void SetDigits(AliTRDdataArrayI *dig) { fDigits = dig; }; + + AliTRDdigitsManager *GetDigitsManager() const { return fDigitsManager; }; + + Bool_t SetRawVersion(Int_t rv); + Int_t GetRawVersion() const { return fRawVersion; }; + + // Check if the link has optical power (HC sends data) + Bool_t IsGTULinkActive(Int_t sm, Int_t la, Int_t sta, Int_t side) + { return ( ((fGTUlinkMask[sm][sta]) >> (2*la+side)) & 0x1 ); }; + + + Int_t fSig[3]; // Signals in the three time bins from Data Word + Int_t fADC; // MCM ADC channel and Time Bin of word 1 + Int_t fTB; // MCM ADC channel and Time Bin of word 1 + Int_t fEv; // MCM Event number and position of current MCM on TRD chamber + Int_t fROB; // MCM Event number and position of current MCM on TRD chamber + Int_t fMCM; // MCM Event number and position of current MCM on TRD chamber + Int_t fSM; // Position of CURRENT half chamber in full TRD + Int_t fLAYER; // Position of CURRENT half chamber in full TRD + Int_t fSTACK; // Position of CURRENT half chamber in full TRD + Int_t fROC; // Position of CURRENT half chamber in full TRD + Int_t fSIDE; // Position of CURRENT half chamber in full TRD + Int_t fDCS; // DCS board number read from data (HC header) + Int_t fROW; + Int_t fCOL; // Detector Pad coordinates + + Int_t fBCctr; // Counters from HC header (>=V2) + Int_t fPTctr; // Counters from HC header (>=V2) + Int_t fPTphase; // Counters from HC header (>=V2) + Int_t fRVmajor; // Raw version numbers and number of additional HC headerwords (>=V2) + Int_t fRVminor; // Raw version numbers and number of additional HC headerwords (>=V2) + Int_t fHCHWords; // Raw version numbers and number of additional HC headerwords (>=V2) + Int_t fTBins; // Number of time bins read from HC header (>=V2) + Int_t fTCon; // Filter settings read from HC header (>=V2) + Int_t fPEDon; // Filter settings read from HC header (>=V2) + Int_t fGAINon; // Filter settings read from HC header (>=V2) + Int_t fFiltered; // Filter settings read from HC header (>=V2) + + Int_t fHCHctr1; // HC and MCM Header counter + Int_t fHCHctr2; // HC and MCM Header counter + Int_t fMCMHctr1; // HC and MCM Header counter + Int_t fMCMHctr2; // HC and MCM Header counter + Int_t fGTUctr1; // GTU LinkMask Counter + Int_t fGTUctr2; // GTU LinkMask Counter + + Float_t fTracklPID; // Tracklet parameters + Float_t fTracklDefL; // Tracklet parameters + Float_t fTracklPadPos; // Tracklet parameters + Int_t fTracklPadRow; // Tracklet parameters + + UShort_t fGTUlinkMask[18][5]; // Mask with active links private : AliTRDRawStream(const AliTRDRawStream &stream); AliTRDRawStream &operator=(const AliTRDRawStream &stream); - AliRawReader* fRawReader; // Object for reading the raw data + AliRawReader *fRawReader; // Object for reading the raw data - Int_t fCount; // Counter of bytes to be read for current detector + // The following is used by V0 (from Bogdan, offline use only): + Int_t fCount; // Counter of bytes to be read for current detector + Int_t fDetector; // Index of current detector + Int_t fPrevDetector; // Index of previous detector + Int_t fNPads; // Number of active pads + Int_t fRow; // Index of current pad row + Int_t fPrevRow; // Index of previous pad row + Int_t fColumn; // Index of current pad column + Int_t fPrevColumn; // Index of previous pad column + Int_t fTime; // Index of current time bin + Int_t fSignal; // Signal in ADC counts - Int_t fDetector; // Index of current detector - Int_t fPrevDetector; // Index of previous detector - Int_t fNPads; // Number of active pads - Int_t fRow; // Index of current pad row - Int_t fPrevRow; // Index of previous pad row - Int_t fColumn; // Index of current pad column - Int_t fPrevColumn; // Index of previous pad column - Int_t fTime; // Index of current time bin - Int_t fSignal; // Signal in ADC counts + // This is again new: + Int_t fRawVersion; // Which version of raw data decoding is used + UInt_t fDataWord; // The current 32 bit data word + Int_t fStatus; // Status of Raw data Reading - ClassDef(AliTRDRawStream, 1) // Class for reading TRD raw digits + Int_t fRowMax; // Maximum number of pad rows and columns + Int_t fColMax; // Maximum number of pad rows and columns + Bool_t fChamberDone[540]; // Chamber was processed already? -}; + protected: + + AliTRDgeometry *fGeo; // TRD geometry + + AliTRDdigitsManager *fDigitsManager; //! Manager for the output digits + AliTRDdataArrayI *fDigits; //! The Output digits + AliTRDdataArrayI *fTrack0; //! The track dictionary + AliTRDdataArrayI *fTrack1; //! The track dictionary + AliTRDdataArrayI *fTrack2; //! The track dictionary + void DecodeHCheader(Int_t timeBins); + void DecodeHCheaderV1(); // Valid for fRawversion = 1 + void DecodeHCheaderV2(Int_t imeBins); // Valid for fRawversion = 2,3,4 + + void DecodeMCMheader(); + void DecodeMCMheaderV1(); // Valid for fRawversion = 1,2,3,4 + + void DecodeTracklet(); + void DecodeTrackletV1(); // Valid for fRawversion = 1,2,3,4 + + void DecodeGTUlinkMask(); + void DecodeGTUlinkMaskV1(); // Valid for fRawversion = 1,2,3,4 + + ClassDef(AliTRDRawStream, 2) // Class for reading TRD raw digits + +}; #endif diff --git a/TRD/AliTRDdigitizer.cxx b/TRD/AliTRDdigitizer.cxx index f29c9567600..e27141c33ba 100644 --- a/TRD/AliTRDdigitizer.cxx +++ b/TRD/AliTRDdigitizer.cxx @@ -395,21 +395,21 @@ void AliTRDdigitizer::Exec(Option_t *option) TString optionString = option; if (optionString.Contains("deb")) { AliLog::SetClassDebugLevel("AliTRDdigitizer",1); - AliInfo("Called with debug option\n"); + AliInfo("Called with debug option"); } // The AliRoot file is already connected by the manager AliRunLoader *inrl; if (gAlice) { - AliDebug(1,"AliRun object found on file.\n"); + AliDebug(1,"AliRun object found on file."); } else { inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(0)); inrl->LoadgAlice(); gAlice = inrl->GetAliRun(); if (!gAlice) { - AliError("Could not find AliRun object.\n") + AliError("Could not find AliRun object.") return; } } @@ -454,7 +454,7 @@ void AliTRDdigitizer::Exec(Option_t *option) for (iInput = 0; iInput < nInput; iInput++) { - AliDebug(1,Form("Add input stream %d\n",iInput)); + AliDebug(1,Form("Add input stream %d",iInput)); // Check if the input tree exists inrl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(iInput)); @@ -470,7 +470,7 @@ void AliTRDdigitizer::Exec(Option_t *option) } if (treees == 0x0) { - AliError(Form("Input stream %d does not exist\n",iInput)); + AliError(Form("Input stream %d does not exist",iInput)); return; } @@ -491,17 +491,17 @@ void AliTRDdigitizer::Exec(Option_t *option) } // Convert the s-digits to normal digits - AliDebug(1,"Do the conversion\n"); + AliDebug(1,"Do the conversion"); SDigits2Digits(); // Store the digits - AliDebug(1,"Write the digits\n"); + AliDebug(1,"Write the digits"); fDigitsManager->WriteDigits(); // Write parameters orl->CdGAFile(); - AliDebug(1,"Done\n"); + AliDebug(1,"Done"); DeleteSDigitsManager(); @@ -533,10 +533,10 @@ Bool_t AliTRDdigitizer::Open(const Char_t *file, Int_t nEvent) gAlice = fRunLoader->GetAliRun(); if (gAlice) { - AliDebug(1,"AliRun object found on file.\n"); + AliDebug(1,"AliRun object found on file."); } else { - AliError("Could not find AliRun object.\n"); + AliError("Could not find AliRun object."); return kFALSE; } @@ -595,10 +595,10 @@ Bool_t AliTRDdigitizer::Open(AliRunLoader *runLoader, Int_t nEvent) gAlice = fRunLoader->GetAliRun(); if (gAlice) { - AliDebug(1,"AliRun object found on file.\n"); + AliDebug(1,"AliRun object found on file."); } else { - AliError("Could not find AliRun object.\n"); + AliError("Could not find AliRun object."); return kFALSE; } @@ -646,17 +646,17 @@ Bool_t AliTRDdigitizer::InitDetector() // Get the pointer to the detector class and check for version 1 fTRD = (AliTRD *) gAlice->GetDetector("TRD"); if (!fTRD) { - AliFatal("No TRD module found\n"); + AliFatal("No TRD module found"); exit(1); } if (fTRD->IsVersion() != 1) { - AliFatal("TRD must be version 1 (slow simulator)\n"); + AliFatal("TRD must be version 1 (slow simulator)"); exit(1); } // Get the geometry fGeo = fTRD->GetGeometry(); - AliDebug(1,Form("Geometry version %d\n",fGeo->IsVersion())); + AliDebug(1,Form("Geometry version %d",fGeo->IsVersion())); // Create a digits manager delete fDigitsManager; @@ -747,13 +747,13 @@ Bool_t AliTRDdigitizer::MakeDigits() AliTRDSimParam *simParam = AliTRDSimParam::Instance(); if (!simParam) { - AliError("Could not get simulation parameters\n"); + AliError("Could not get simulation parameters"); return kFALSE; } AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance(); if (!commonParam) { - AliError("Could not get common parameterss\n"); + AliError("Could not get common parameterss"); return kFALSE; } @@ -763,24 +763,24 @@ Bool_t AliTRDdigitizer::MakeDigits() AliTRDcalibDB* calibration = AliTRDcalibDB::Instance(); if (!calibration) { - AliError("Could not get calibration object\n"); + AliError("Could not get calibration object"); return kFALSE; } if (simParam->TRFOn()) { timeBinTRFend = ((Int_t) (simParam->GetTRFhi() * commonParam->GetSamplingFrequency())) - 1; - AliDebug(1,Form("Sample the TRF up to bin %d\n",timeBinTRFend)); + AliDebug(1,Form("Sample the TRF up to bin %d",timeBinTRFend)); } Float_t elAttachProp = simParam->GetElAttachProp() / 100.0; if (!fGeo) { - AliError("No geometry defined\n"); + AliError("No geometry defined"); return kFALSE; } - AliDebug(1,"Start creating digits.\n"); + AliDebug(1,"Start creating digits."); AliLoader *gimme = fRunLoader->GetLoader("TRDLoader"); if (!gimme->TreeH()) { @@ -796,15 +796,15 @@ Bool_t AliTRDdigitizer::MakeDigits() // Get the number of entries in the hit tree // (Number of primary particles creating a hit somewhere) Int_t nTrack = (Int_t) hitTree->GetEntries(); - AliDebug(1,Form("Found %d primary particles\n",nTrack)); - AliDebug(1,Form("Sampling = %.0fMHz\n" ,commonParam->GetSamplingFrequency())); - AliDebug(1,Form("Gain = %d\n" ,((Int_t) simParam->GetGasGain()))); - AliDebug(1,Form("Noise = %d\n" ,((Int_t) simParam->GetNoise()))); + AliDebug(1,Form("Found %d primary particles",nTrack)); + AliDebug(1,Form("Sampling = %.0fMHz" ,commonParam->GetSamplingFrequency())); + AliDebug(1,Form("Gain = %d" ,((Int_t) simParam->GetGasGain()))); + AliDebug(1,Form("Noise = %d" ,((Int_t) simParam->GetNoise()))); if (simParam->TimeStructOn()) { - AliDebug(1,"Time Structure of drift cells implemented.\n"); + AliDebug(1,"Time Structure of drift cells implemented."); } else { - AliDebug(1,"Constant drift velocity in drift cells.\n"); + AliDebug(1,"Constant drift velocity in drift cells."); } Int_t detectorOld = -1; @@ -925,7 +925,7 @@ Bool_t AliTRDdigitizer::MakeDigits() if ((xyz[2] < padPlane->GetRowEnd()) || (xyz[2] > padPlane->GetRow0())) { if (iEl == 0) { - AliDebug(2,Form("Hit outside of sensitive volume, row (z=%f, row0=%f, rowE=%f)\n" + AliDebug(2,Form("Hit outside of sensitive volume, row (z=%f, row0=%f, rowE=%f)" ,xyz[2],padPlane->GetRow0(),padPlane->GetRowEnd())); } continue; @@ -934,7 +934,7 @@ Bool_t AliTRDdigitizer::MakeDigits() if ((tt < 0.0) || (tt > kDrWidth + 2.0*kAmWidth)) { if (iEl == 0) { - AliDebug(2,Form("Hit outside of sensitive volume, time (Q = %d)\n" + AliDebug(2,Form("Hit outside of sensitive volume, time (Q = %d)" ,((Int_t) q))); } continue; @@ -1108,7 +1108,7 @@ Bool_t AliTRDdigitizer::MakeDigits() } // Loop: primary tracks - AliDebug(1,Form("Finished analyzing %d hits\n",countHits)); + AliDebug(1,Form("Finished analyzing %d hits",countHits)); // The coupling factor Double_t coupling = simParam->GetPadCoupling() @@ -1197,7 +1197,7 @@ Bool_t AliTRDdigitizer::MakeDigits() Float_t padgain = calibration->GetGainFactor(iDet,iCol,iRow); if (padgain <= 0) { - AliError(Form("Not a valid gain %f, %d %d %d\n",padgain,iDet,iCol,iRow)); + AliError(Form("Not a valid gain %f, %d %d %d",padgain,iDet,iCol,iRow)); } signalAmp *= padgain; @@ -1230,7 +1230,7 @@ Bool_t AliTRDdigitizer::MakeDigits() for (iTime = 0; iTime < nTimeTotal; iTime++) { // Store the amplitude of the digit if above threshold - if (outADC[iTime] > simParam->GetADCthreshold()) { + if ( outADC[iTime] > ( simParam->GetADCbaseline() + simParam->GetADCthreshold() ) ) { nDigits++; digits->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime])); } @@ -1256,7 +1256,7 @@ Bool_t AliTRDdigitizer::MakeDigits() if (nDigits > 0) { Float_t nPixel = nRowMax * nColMax * nTimeTotal; - AliDebug(1,Form("Found %d digits in detector %d (%3.0f).\n" + AliDebug(1,Form("Found %d digits in detector %d (%3.0f)." ,nDigits,iDet ,100.0 * ((Float_t) nDigits) / nPixel)); } @@ -1275,8 +1275,8 @@ Bool_t AliTRDdigitizer::MakeDigits() signalsArray = 0; } - AliDebug(1,Form("Total number of analyzed hits = %d\n",countHits)); - AliDebug(1,Form("Total digits data size = %d, %d, %d, %d\n",totalSizeDigits + AliDebug(1,Form("Total number of analyzed hits = %d",countHits)); + AliDebug(1,Form("Total digits data size = %d, %d, %d, %d",totalSizeDigits ,totalSizeDict0 ,totalSizeDict1 ,totalSizeDict2)); @@ -1327,19 +1327,19 @@ Bool_t AliTRDdigitizer::ConvertSDigits() AliTRDSimParam *simParam = AliTRDSimParam::Instance(); if (!simParam) { - AliError("Could not get simulation parameters\n"); + AliError("Could not get simulation parameters"); return kFALSE; } AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance(); if (!commonParam) { - AliError("Could not get common parameters\n"); + AliError("Could not get common parameters"); return kFALSE; } AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); if (!calibration) { - AliError("Could not get calibration object\n"); + AliError("Could not get calibration object"); return kFALSE; } @@ -1404,7 +1404,7 @@ Bool_t AliTRDdigitizer::ConvertSDigits() // Apply the pad-by-pad gain factors Float_t padgain = calibration->GetGainFactor(iDet,iCol,iRow); if (padgain <= 0.0) { - AliError(Form("Not a valid gain %f, %d %d %d\n",padgain,iDet,iCol,iRow)); + AliError(Form("Not a valid gain %f, %d %d %d",padgain,iDet,iCol,iRow)); } signal *= padgain; // Pad and time coupling @@ -1432,7 +1432,7 @@ Bool_t AliTRDdigitizer::ConvertSDigits() for (iTime = 0; iTime < nTimeTotal; iTime++) { // Store the amplitude of the digit if above threshold - if (outADC[iTime] > adcThreshold) { + if (outADC[iTime] > (adcBaseline + adcThreshold)) { digitsOut->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime])); // Copy the dictionary for (iDict = 0; iDict < kNDict; iDict++) { @@ -1480,19 +1480,19 @@ Bool_t AliTRDdigitizer::MergeSDigits() AliTRDSimParam *simParam = AliTRDSimParam::Instance(); if (!simParam) { - AliError("Could not get simulation parameters\n"); + AliError("Could not get simulation parameters"); return kFALSE; } AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance(); if (!commonParam) { - AliError("Could not get common parameters\n"); + AliError("Could not get common parameters"); return kFALSE; } AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); if (!calibration) { - AliError("Could not get calibration object\n"); + AliError("Could not get calibration object"); return kFALSE; } @@ -1507,7 +1507,7 @@ Bool_t AliTRDdigitizer::MergeSDigits() // Get the first s-digits fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First(); if (!fSDigitsManager) { - AliError("No SDigits manager\n"); + AliError("No SDigits manager"); return kFALSE; } @@ -1517,10 +1517,10 @@ Bool_t AliTRDdigitizer::MergeSDigits() fSDigitsManagerList->After(fSDigitsManager); if (mergeSDigitsManager) { - AliDebug(1,Form("Merge %d input files.\n",fSDigitsManagerList->GetSize())); + AliDebug(1,Form("Merge %d input files.",fSDigitsManagerList->GetSize())); } else { - AliDebug(1,"Only one input file.\n"); + AliDebug(1,"Only one input file."); } Int_t nTimeTotal = calibration->GetNumberOfTimeBins(); @@ -1561,7 +1561,7 @@ Bool_t AliTRDdigitizer::MergeSDigits() if (doMerge) { - AliDebug(1,Form("Merge detector %d of input no.%d\n",iDet,iMerge+1)); + AliDebug(1,Form("Merge detector %d of input no.%d",iDet,iMerge+1)); for (Int_t iRow = 0; iRow < nRowMax; iRow++ ) { for (Int_t iCol = 0; iCol < nColMax; iCol++ ) { @@ -1725,7 +1725,7 @@ Double_t AliTRDdigitizer::TimeStruct(Float_t vdrift, Double_t dist, Double_t z) (r1 > 37) || (kz1 < 0) || (kz1 > 10)) { - AliWarning(Form("Indices out of range: dist=%.2f, z=%.2f, r1=%d, kz1=%d\n" + AliWarning(Form("Indices out of range: dist=%.2f, z=%.2f, r1=%d, kz1=%d" ,dist,z,r1,kz1)); } @@ -1809,11 +1809,11 @@ void AliTRDdigitizer::SampleTimeStruct(Float_t vdrift) fVDsmp[7] = 2.134; if (vdrift < fVDsmp[0]) { - AliWarning(Form("Drift Velocity too small (%.3f<%.3f)\n",vdrift,fVDsmp[0])); + AliWarning(Form("Drift Velocity too small (%.3f<%.3f)",vdrift,fVDsmp[0])); vdrift = fVDsmp[0]; } else if (vdrift > fVDsmp[7]) { - AliWarning(Form("Drift Velocity too large (%.3f>%.3f)\n",vdrift,fVDsmp[6])); + AliWarning(Form("Drift Velocity too large (%.3f>%.3f)",vdrift,fVDsmp[6])); vdrift = fVDsmp[7]; } @@ -2527,19 +2527,19 @@ void AliTRDdigitizer::RecalcDiffusion(Float_t vdrift) AliTRDSimParam *simParam = AliTRDSimParam::Instance(); if (!simParam) { - AliError("Could not get simulation parameters\n"); + AliError("Could not get simulation parameters"); return; } AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance(); if (!commonParam) { - AliError("Could not get common parameters\n"); + AliError("Could not get common parameters"); return; } AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); if (!calibration) { - AliError("Could not get calibration object\n"); + AliError("Could not get calibration object"); return; } diff --git a/TRD/AliTRDgeometry.cxx b/TRD/AliTRDgeometry.cxx index 22e64a99baa..7a622ba64fd 100644 --- a/TRD/AliTRDgeometry.cxx +++ b/TRD/AliTRDgeometry.cxx @@ -45,108 +45,118 @@ ClassImp(AliTRDgeometry) // // The geometry constants // - const Int_t AliTRDgeometry::fgkNsect = kNsect; - const Int_t AliTRDgeometry::fgkNplan = kNplan; - const Int_t AliTRDgeometry::fgkNcham = kNcham; - const Int_t AliTRDgeometry::fgkNdet = kNdet; + const Int_t AliTRDgeometry::fgkNsect = kNsect; + const Int_t AliTRDgeometry::fgkNplan = kNplan; + const Int_t AliTRDgeometry::fgkNcham = kNcham; + const Int_t AliTRDgeometry::fgkNdet = kNdet; // // Dimensions of the detector // // Parameter of the BTRD mother volumes - const Float_t AliTRDgeometry::fgkSheight = 77.9; - const Float_t AliTRDgeometry::fgkSwidth1 = 94.881; - const Float_t AliTRDgeometry::fgkSwidth2 = 122.353; - const Float_t AliTRDgeometry::fgkSlength = 751.0; + const Float_t AliTRDgeometry::fgkSheight = 77.9; + const Float_t AliTRDgeometry::fgkSwidth1 = 94.881; + const Float_t AliTRDgeometry::fgkSwidth2 = 122.353; + const Float_t AliTRDgeometry::fgkSlength = 751.0; // The super module side plates - const Float_t AliTRDgeometry::fgkSMpltT = 0.2; + const Float_t AliTRDgeometry::fgkSMpltT = 0.2; // Height of different chamber parts // Radiator - const Float_t AliTRDgeometry::fgkCraH = 4.8; + const Float_t AliTRDgeometry::fgkCraH = 4.8; // Drift region - const Float_t AliTRDgeometry::fgkCdrH = 3.0; + const Float_t AliTRDgeometry::fgkCdrH = 3.0; // Amplification region - const Float_t AliTRDgeometry::fgkCamH = 0.7; + const Float_t AliTRDgeometry::fgkCamH = 0.7; // Readout - const Float_t AliTRDgeometry::fgkCroH = 2.316; + const Float_t AliTRDgeometry::fgkCroH = 2.316; // Total height - const Float_t AliTRDgeometry::fgkCH = AliTRDgeometry::fgkCraH - + AliTRDgeometry::fgkCdrH - + AliTRDgeometry::fgkCamH - + AliTRDgeometry::fgkCroH; + const Float_t AliTRDgeometry::fgkCH = AliTRDgeometry::fgkCraH + + AliTRDgeometry::fgkCdrH + + AliTRDgeometry::fgkCamH + + AliTRDgeometry::fgkCroH; // Vertical spacing of the chambers - const Float_t AliTRDgeometry::fgkVspace = 1.784; + const Float_t AliTRDgeometry::fgkVspace = 1.784; // Horizontal spacing of the chambers - const Float_t AliTRDgeometry::fgkHspace = 2.0; + const Float_t AliTRDgeometry::fgkHspace = 2.0; // Radial distance of the first ROC to the outer plates of the SM - const Float_t AliTRDgeometry::fgkVrocsm = 1.2; + const Float_t AliTRDgeometry::fgkVrocsm = 1.2; // Thicknesses of different parts of the chamber frame // Lower aluminum frame - const Float_t AliTRDgeometry::fgkCalT = 0.4; + const Float_t AliTRDgeometry::fgkCalT = 0.4; // Lower Wacosit frame sides - const Float_t AliTRDgeometry::fgkCclsT = 0.21; + const Float_t AliTRDgeometry::fgkCclsT = 0.21; // Lower Wacosit frame front - const Float_t AliTRDgeometry::fgkCclfT = 1.0; + const Float_t AliTRDgeometry::fgkCclfT = 1.0; // Thickness of glue around radiator - const Float_t AliTRDgeometry::fgkCglT = 0.25; + const Float_t AliTRDgeometry::fgkCglT = 0.25; // Upper Wacosit frame - const Float_t AliTRDgeometry::fgkCcuT = 0.9; + const Float_t AliTRDgeometry::fgkCcuT = 0.9; // Al frame of back panel - const Float_t AliTRDgeometry::fgkCauT = 1.5; + const Float_t AliTRDgeometry::fgkCauT = 1.5; // Additional Al of the lower chamber frame - const Float_t AliTRDgeometry::fgkCalW = 1.11; + const Float_t AliTRDgeometry::fgkCalW = 1.11; // Additional width of the readout chamber frames - const Float_t AliTRDgeometry::fgkCroW = 0.9; + const Float_t AliTRDgeometry::fgkCroW = 0.9; // Difference of outer chamber width and pad plane width - const Float_t AliTRDgeometry::fgkCpadW = 0.0; - const Float_t AliTRDgeometry::fgkRpadW = 1.0; + const Float_t AliTRDgeometry::fgkCpadW = 0.0; + const Float_t AliTRDgeometry::fgkRpadW = 1.0; // // Thickness of the the material layers // - const Float_t AliTRDgeometry::fgkMyThick = 0.005; - const Float_t AliTRDgeometry::fgkRaThick = 0.3233; - const Float_t AliTRDgeometry::fgkDrThick = AliTRDgeometry::fgkCdrH; - const Float_t AliTRDgeometry::fgkAmThick = AliTRDgeometry::fgkCamH; - const Float_t AliTRDgeometry::fgkXeThick = AliTRDgeometry::fgkDrThick - + AliTRDgeometry::fgkAmThick; - const Float_t AliTRDgeometry::fgkWrThick = 0.0002; - const Float_t AliTRDgeometry::fgkCuThick = 0.0072; - const Float_t AliTRDgeometry::fgkGlThick = 0.05; - const Float_t AliTRDgeometry::fgkSuThick = 0.0919; - const Float_t AliTRDgeometry::fgkRcThick = 0.0058; - const Float_t AliTRDgeometry::fgkRpThick = 0.0632; - const Float_t AliTRDgeometry::fgkRoThick = 0.0028; + const Float_t AliTRDgeometry::fgkMyThick = 0.005; + const Float_t AliTRDgeometry::fgkRaThick = 0.3233; + const Float_t AliTRDgeometry::fgkDrThick = AliTRDgeometry::fgkCdrH; + const Float_t AliTRDgeometry::fgkAmThick = AliTRDgeometry::fgkCamH; + const Float_t AliTRDgeometry::fgkXeThick = AliTRDgeometry::fgkDrThick + + AliTRDgeometry::fgkAmThick; + const Float_t AliTRDgeometry::fgkWrThick = 0.0002; + const Float_t AliTRDgeometry::fgkCuThick = 0.0072; + const Float_t AliTRDgeometry::fgkGlThick = 0.05; + const Float_t AliTRDgeometry::fgkSuThick = 0.0919; + const Float_t AliTRDgeometry::fgkRcThick = 0.0058; + const Float_t AliTRDgeometry::fgkRpThick = 0.0632; + const Float_t AliTRDgeometry::fgkRoThick = 0.0028; // // Position of the material layers // - //const Float_t AliTRDgeometry::fgkRaZpos = -1.50; - const Float_t AliTRDgeometry::fgkRaZpos = 0.0; - const Float_t AliTRDgeometry::fgkDrZpos = 2.4; - const Float_t AliTRDgeometry::fgkAmZpos = 0.0; - const Float_t AliTRDgeometry::fgkWrZpos = 0.0; - const Float_t AliTRDgeometry::fgkCuZpos = -0.9995; - const Float_t AliTRDgeometry::fgkGlZpos = -0.5; - const Float_t AliTRDgeometry::fgkSuZpos = 0.0; - const Float_t AliTRDgeometry::fgkRcZpos = 1.04; - const Float_t AliTRDgeometry::fgkRpZpos = 1.0; - const Float_t AliTRDgeometry::fgkRoZpos = 1.05; + const Float_t AliTRDgeometry::fgkRaZpos = 0.0; + const Float_t AliTRDgeometry::fgkDrZpos = 2.4; + const Float_t AliTRDgeometry::fgkAmZpos = 0.0; + const Float_t AliTRDgeometry::fgkWrZpos = 0.0; + const Float_t AliTRDgeometry::fgkCuZpos = -0.9995; + const Float_t AliTRDgeometry::fgkGlZpos = -0.5; + const Float_t AliTRDgeometry::fgkSuZpos = 0.0; + const Float_t AliTRDgeometry::fgkRcZpos = 1.04; + const Float_t AliTRDgeometry::fgkRpZpos = 1.0; + const Float_t AliTRDgeometry::fgkRoZpos = 1.05; + + const Int_t AliTRDgeometry::fgkMCMmax = 16; + const Int_t AliTRDgeometry::fgkMCMrow = 4; + const Int_t AliTRDgeometry::fgkROBmaxC0 = 6; + const Int_t AliTRDgeometry::fgkROBmaxC1 = 8; + const Int_t AliTRDgeometry::fgkADCmax = 21; + const Int_t AliTRDgeometry::fgkTBmax = 60; + const Int_t AliTRDgeometry::fgkPadmax = 18; + const Int_t AliTRDgeometry::fgkColmax = 144; + const Int_t AliTRDgeometry::fgkRowmaxC0 = 12; + const Int_t AliTRDgeometry::fgkRowmaxC1 = 16; const Double_t AliTRDgeometry::fgkTime0Base = 300.65; - const Float_t AliTRDgeometry::fgkTime0[6] = { fgkTime0Base + 0 * (Cheight() + Cspace()), - fgkTime0Base + 1 * (Cheight() + Cspace()), - fgkTime0Base + 2 * (Cheight() + Cspace()), - fgkTime0Base + 3 * (Cheight() + Cspace()), - fgkTime0Base + 4 * (Cheight() + Cspace()), - fgkTime0Base + 5 * (Cheight() + Cspace()) }; + const Float_t AliTRDgeometry::fgkTime0[6] = { fgkTime0Base + 0 * (Cheight() + Cspace()) + , fgkTime0Base + 1 * (Cheight() + Cspace()) + , fgkTime0Base + 2 * (Cheight() + Cspace()) + , fgkTime0Base + 3 * (Cheight() + Cspace()) + , fgkTime0Base + 4 * (Cheight() + Cspace()) + , fgkTime0Base + 5 * (Cheight() + Cspace())}; //_____________________________________________________________________________ AliTRDgeometry::AliTRDgeometry() @@ -1404,6 +1414,78 @@ Int_t AliTRDgeometry::GetSector(Int_t d) const } +//CL +//_____________________________________________________________________________ +Int_t AliTRDgeometry::GetPadRow(Int_t irob, Int_t imcm) const +{ + + // return on which row this mcm sits + + return fgkMCMrow*(irob/2) + imcm/fgkMCMrow; + +; +} + +//_____________________________________________________________________________ +Int_t AliTRDgeometry::GetPadCol(Int_t irob, Int_t imcm, Int_t iadc) const +{ + // + // return which pad is connected to this adc channel. return -1 if it + // is one of the not directly connected adc channels (0, 1 20) + // + + if (iadc < 2 || iadc > 19 ) return -1; + + return (iadc-2) + (imcm%fgkMCMrow)*fgkPadmax + GetRobSide(irob)*fgkColmax/2; + +} + +//_____________________________________________________________________________ +Int_t AliTRDgeometry::GetMCM(Int_t irow, Int_t icol) const +{ + + // return on which mcm this pad is + + if ( irow < 0 || icol < 0 || irow > fgkRowmaxC1 || icol > fgkColmax ) return -1; + + return (icol%(fgkColmax/2))/fgkPadmax + fgkMCMrow*(irow%fgkMCMrow); + +} + +//_____________________________________________________________________________ +Int_t AliTRDgeometry::GetROB(Int_t irow, Int_t icol) const +{ + + // return on which rob this pad is + + return (irow/fgkMCMrow)*2 + GetColSide(icol); + +} + +//_____________________________________________________________________________ +Int_t AliTRDgeometry::GetRobSide(Int_t irob) const +{ + + // return on which side this rob sits (A side = 0, B side = 1) + + if ( irob < 0 || irob >= fgkROBmaxC1 ) return -1; + + return irob%2; + +} + +//_____________________________________________________________________________ +Int_t AliTRDgeometry::GetColSide(Int_t icol) const +{ + + // return on which side this column sits (A side = 0, B side = 1) + + if ( icol < 0 || icol >= fgkColmax ) return -1; + + return icol/(fgkColmax/2); + +} + //_____________________________________________________________________________ AliTRDgeometry *AliTRDgeometry::GetGeometry(AliRunLoader *runLoader) { diff --git a/TRD/AliTRDgeometry.h b/TRD/AliTRDgeometry.h index f8735a7bfeb..33adb69d09b 100644 --- a/TRD/AliTRDgeometry.h +++ b/TRD/AliTRDgeometry.h @@ -22,11 +22,11 @@ class AliTRDgeometry : public AliGeometry { public: - enum { kNplan = 6 - , kNcham = 5 - , kNsect = 18 - , kNdet = 540 - , kNdets = 30 }; + enum { kNplan = 6 + , kNcham = 5 + , kNsect = 18 + , kNdet = 540 + , kNdets = 30 }; AliTRDgeometry(); AliTRDgeometry(const AliTRDgeometry &g); @@ -58,6 +58,13 @@ class AliTRDgeometry : public AliGeometry { virtual Int_t GetChamber(Int_t d) const; virtual Int_t GetSector(Int_t d) const; + virtual Int_t GetPadRow(Int_t irob, Int_t imcm) const; + virtual Int_t GetPadCol(Int_t irob, Int_t imcm, Int_t iadc) const; + virtual Int_t GetMCM(Int_t irow, Int_t icol) const; + virtual Int_t GetROB(Int_t irow, Int_t icol) const; + virtual Int_t GetRobSide(Int_t irob) const; + virtual Int_t GetColSide(Int_t icol) const; + static Float_t GetTime0(Int_t p) { return fgkTime0[p]; } Char_t GetSMstatus(Int_t sm) const { return fSMstatus[sm]; } @@ -94,6 +101,17 @@ class AliTRDgeometry : public AliGeometry { / fgkSheight * (fgkCH + fgkVspace); } + static Int_t MCMmax() { return fgkMCMmax; } + static Int_t MCMrow() { return fgkMCMrow; } + static Int_t ROBmaxC0() { return fgkROBmaxC0; } + static Int_t ROBmaxC1() { return fgkROBmaxC1; } + static Int_t ADCmax() { return fgkADCmax; } + static Int_t TBmax() { return fgkTBmax; } + static Int_t Padmax() { return fgkPadmax; } + static Int_t Colmax() { return fgkColmax; } + static Int_t RowmaxC0() { return fgkRowmaxC0; } + static Int_t RowmaxC1() { return fgkRowmaxC1; } + TGeoHMatrix *GetGeoMatrix(Int_t det) { return (TGeoHMatrix *) fMatrixGeo->At(det); } TGeoHMatrix *GetMatrix(Int_t det) { return (TGeoHMatrix *) @@ -161,6 +179,17 @@ class AliTRDgeometry : public AliGeometry { static const Float_t fgkRcZpos; // Position of the PCB copper layers static const Float_t fgkRoZpos; // Position of all other ROB componentes (caps, etc.) + static const Int_t fgkMCMmax; // Maximum number of MCMs per ROB + static const Int_t fgkMCMrow; // Maximum number of MCMs per ROB Row + static const Int_t fgkROBmaxC0; // Maximum number of ROBs per C0 chamber + static const Int_t fgkROBmaxC1; // Maximum number of ROBs per C1 chamber + static const Int_t fgkADCmax; // Maximum number of ADC channels per MCM + static const Int_t fgkTBmax; // Maximum number of Time bins + static const Int_t fgkPadmax; // Maximum number of pads per MCM + static const Int_t fgkColmax; // Maximum number of pads per padplane row + static const Int_t fgkRowmaxC0; // Maximum number of Rows per C0 chamber + static const Int_t fgkRowmaxC1; // Maximum number of Rows per C1 chamber + Char_t fSMstatus[kNsect]; // Super module status byte Float_t fCwidth[kNplan]; // Outer widths of the chambers @@ -189,11 +218,11 @@ class AliTRDgeometry : public AliGeometry { Float_t fChamberUFboxd[3*kNdets][3]; // [3] = x, y, z Float_t fChamberUUboxd[3*kNdets][3]; // - TObjArray * fMatrixArray; //! Transformation Global to Local - TObjArray * fMatrixCorrectionArray; //! Transformation Cluster to Tracking systerm - TObjArray * fMatrixGeo; //! Geo matrices + TObjArray *fMatrixArray; //! Transformation Global to Local + TObjArray *fMatrixCorrectionArray; //! Transformation Cluster to Tracking systerm + TObjArray *fMatrixGeo; //! Geo matrices - ClassDef(AliTRDgeometry,11) // TRD geometry class + ClassDef(AliTRDgeometry,12) // TRD geometry class }; diff --git a/TRD/AliTRDrawData.cxx b/TRD/AliTRDrawData.cxx index ac865284421..2f53c38c40a 100644 --- a/TRD/AliTRDrawData.cxx +++ b/TRD/AliTRDrawData.cxx @@ -42,7 +42,7 @@ ClassImp(AliTRDrawData) //_____________________________________________________________________________ AliTRDrawData::AliTRDrawData() :TObject() - ,fRawVersion(0) + ,fRawVersion(1) // Default Raw Data version set here ,fCommonParam(0) ,fCalibration(0) ,fGeo(0) @@ -57,7 +57,7 @@ AliTRDrawData::AliTRDrawData() //_____________________________________________________________________________ AliTRDrawData::AliTRDrawData(const AliTRDrawData &r) :TObject(r) - ,fRawVersion(0) + ,fRawVersion(1) // Default Raw Data version set here ,fCommonParam(0) ,fCalibration(0) ,fGeo(0) @@ -82,12 +82,10 @@ AliTRDrawData::~AliTRDrawData() Bool_t AliTRDrawData::SetRawVersion(Int_t v) { // - // Set the raw data version - // Currently only version 0 and 1 are available. + // Set the raw data version (Currently only version 0, 1 and 2 are available) // - if ((v == 0) || - (v == 1)) { + if ( (v >= 0) && (v <= 2) ) { fRawVersion = v; return kTRUE; } @@ -118,7 +116,7 @@ Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree, TTree *tracks ) if (tracks != NULL) { delete digitsManager; - printf(" Tracklet input is not supported yet.\n"); + AliError("Tracklet input is not supported yet."); return kFALSE; } @@ -126,7 +124,7 @@ Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree, TTree *tracks ) fCommonParam = AliTRDCommonParam::Instance(); if (!fCommonParam) { - AliError("Could not get common params\n"); + AliError("Could not get common params"); delete fGeo; delete digitsManager; return kFALSE; @@ -134,7 +132,7 @@ Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree, TTree *tracks ) fCalibration = AliTRDcalibDB::Instance(); if (!fCalibration) { - AliError("Could not get calibration object\n"); + AliError("Could not get calibration object"); delete fGeo; delete digitsManager; return kFALSE; @@ -143,17 +141,11 @@ Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree, TTree *tracks ) Int_t retval = kTRUE; // Call appropriate Raw Simulator - switch( fRawVersion ) { - case 0 : - retval = Digits2RawV0(digitsManager); - break; - case 1 : - retval = Digits2RawV1(digitsManager); - break; - default: - retval = kFALSE; - AliWarning(Form("Unsupported raw version (fRawVersion=%d).\n",fRawVersion)); - break; + if ( fRawVersion == 0 ) retval = Digits2RawV0(digitsManager); + else if ( fRawVersion > 0 && fRawVersion <= 2 ) retval = Digits2RawVx(digitsManager); + else { + retval = kFALSE; + AliWarning(Form("Unsupported raw version (fRawVersion=%d).",fRawVersion)); } // Cleanup @@ -359,16 +351,14 @@ Bool_t AliTRDrawData::Digits2RawV0(AliTRDdigitsManager* digitsManager) } //_____________________________________________________________________________ -Bool_t AliTRDrawData::Digits2RawV1(AliTRDdigitsManager *digitsManager) +Bool_t AliTRDrawData::Digits2RawVx(AliTRDdigitsManager *digitsManager) { // - // Raw data simulator version 1. + // Raw data simulator for all versions > 0. This is prepared for real data. // This version simulate only raw data with ADC data and not with tracklet. - // This is close to the SM-I commissiong data format in Oct.2006. // - // (timebin/3)*nADC*nMCM*nROB + header + tracklet(max 20) - const Int_t kMaxHcWords = (60/3)*21*16*4 + 100 + 20; + const Int_t kMaxHcWords = (fGeo->TBmax()/3)*fGeo->ADCmax()*fGeo->MCMmax()*fGeo->ROBmaxC1()/2 + 100 + 20; // Buffer to temporary store half chamber data UInt_t *hc_buffer = new UInt_t[kMaxHcWords]; @@ -393,10 +383,16 @@ Bool_t AliTRDrawData::Digits2RawV1(AliTRDdigitsManager *digitsManager) // Reset payload byte size (payload does not include header). Int_t npayloadbyte = 0; - // GTU common data header (5x4 bytes shows link mask) + // GTU common data header (5x4 bytes per super module, shows link mask) for( Int_t cham = 0; cham < fGeo->Ncham(); cham++ ) { - UInt_t GtuCdh; - GtuCdh = 0x00000FFF; // Assume all ORI links (12 per stack) are always up + UInt_t GtuCdh = (0xe << 28); + for( Int_t plan = 0; plan < fGeo->Nplan(); plan++) { + Int_t iDet = fGeo->GetDetector(plan, cham, sect); + // If chamber status is ok, we assume that the optical link is also OK. + // This is shown in the GTU link mask. + if ( fCalibration->GetChamberStatus(iDet) ) + GtuCdh = GtuCdh | (3 << (2*plan)); + } of->write((char *) (& GtuCdh), sizeof(GtuCdh)); npayloadbyte += 4; } @@ -411,15 +407,15 @@ Bool_t AliTRDrawData::Digits2RawV1(AliTRDdigitsManager *digitsManager) AliTRDdataArrayI *digits = digitsManager->GetDigits(iDet); digits->Expand(); - Int_t hcwords; + Int_t hcwords = 0; // Process A side of the chamber - hcwords = ProduceHcDataV1(digits,0,iDet,hc_buffer,kMaxHcWords); + if ( fRawVersion >= 1 && fRawVersion <= 2 ) hcwords = ProduceHcDataV1andV2(digits,0,iDet,hc_buffer,kMaxHcWords); of->write((char *) hc_buffer, hcwords*4); npayloadbyte += hcwords*4; // Process B side of the chamber - hcwords = ProduceHcDataV1(digits,1,iDet,hc_buffer,kMaxHcWords); + if ( fRawVersion >= 1 && fRawVersion <= 2 ) hcwords = ProduceHcDataV1andV2(digits,1,iDet,hc_buffer,kMaxHcWords); of->write((char *) hc_buffer, hcwords*4); npayloadbyte += hcwords*4; @@ -442,12 +438,16 @@ Bool_t AliTRDrawData::Digits2RawV1(AliTRDdigitsManager *digitsManager) } //_____________________________________________________________________________ -Int_t AliTRDrawData::ProduceHcDataV1(AliTRDdataArrayI *digits, Int_t side - , Int_t det, UInt_t *buf, Int_t maxSize) +Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDdataArrayI *digits, Int_t side + , Int_t det, UInt_t *buf, Int_t maxSize) { + // + // This function simulates: 1) SM-I commissiong data Oct. 06 (fRawVersion == 1). + // 2) Full Raw Production Version (fRawVersion == 2) // // Produce half chamber data (= an ORI data) for the given chamber (det) and side (side) // where + // // side=0 means A side with ROB positions 0, 2, 4, 6. // side=1 means B side with ROB positions 1, 3, 5, 7. // @@ -467,10 +467,7 @@ Int_t AliTRDrawData::ProduceHcDataV1(AliTRDdataArrayI *digits, Int_t side Int_t sect = fGeo->GetSector( det ); // Sector (=iDDL) Int_t nRow = fCommonParam->GetRowMax( plan, cham, sect ); Int_t nCol = fCommonParam->GetColMax( plan ); - const Int_t nMcm = 16; // Number of MCMs per ROB (fixed) const Int_t nTBin = fCalibration->GetNumberOfTimeBins(); - Int_t dcs = det+100; // DCS Serial (in simulation, it's always - // chamber ID+1000 without any reason Int_t kCtype = 0; // Chamber type (0:C0, 1:C1) Int_t iEv = 0xA; // Event ID. Now fixed to 10, how do I get event id? UInt_t x = 0; // General used number @@ -481,7 +478,7 @@ Int_t AliTRDrawData::ProduceHcDataV1(AliTRDdataArrayI *digits, Int_t side kCtype = (nRow-12) / 4; } else { - AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d).\n" + AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)." ,nRow,nCol)); return 0; } @@ -493,31 +490,56 @@ Int_t AliTRDrawData::ProduceHcDataV1(AliTRDdataArrayI *digits, Int_t side // Write end of tracklet marker if (nw < maxSize) { - buf[nw++] = 0xAAAAAAAA; + buf[nw++] = end_of_tracklet_marker; } else { of++; } // Half Chamber header - // Now it is the same version as used in SM-I commissioning. - // It is: (dcs << 20) | (sect << 15) | (plan << 12) | (cham << 9) | (side << 8) - x = (dcs << 20) | (sect << 15) | (plan << 12) | (cham << 9) | (side << 8); - if (nw < maxSize) { - buf[nw++] = x; - } - else { - of++; + if ( fRawVersion == 1 ) { + // Now it is the same version as used in SM-I commissioning. + Int_t dcs = det+100; // DCS Serial (in simulation, it is meaningless + x = (dcs<<20) | (sect<<15) | (plan<<12) | (cham<<9) | (side<<8) | 1; + if (nw < maxSize) { + buf[nw++] = x; + } + else { + of++; + } + } + else if ( fRawVersion == 2 ) { + // h[0] (there are 2 HC header) + Int_t minorv = 0; // The minor version number + Int_t add = 1; // The number of additional header words to follow + x = (1<<31) | (fRawVersion<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (plan<<6) | (cham<<3) | (side<<2) | 1; + if (nw < maxSize) { + buf[nw++] = x; + } + else { + of++; + } + // h[1] + Int_t bc_ctr = 99; // bunch crossing counter. Here it is set to 99 always for no reason + Int_t pt_ctr = 15; // pretrigger counter. Here it is set to 15 always for no reason + Int_t pt_phase = 11; // pretrigger phase. Here it is set to 11 always for no reason + x = (bc_ctr<<16) | (pt_ctr<<12) | (pt_phase<<8) | ((nTBin-1)<<2) | 1; + if (nw < maxSize) { + buf[nw++] = x; + } + else { + of++; + } } // Scan for ROB and MCM for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) { Int_t iRob = iRobRow * 2 + side; - for (Int_t iMcm = 0; iMcm < nMcm; iMcm++ ) { + for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) { Int_t padrow = iRobRow * 4 + iMcm / 4; // MCM header - x = ((iRob * nMcm + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC; + x = ((iRob * fGeo->MCMmax() + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC; if (nw < maxSize) { buf[nw++] = x; } @@ -527,49 +549,27 @@ Int_t AliTRDrawData::ProduceHcDataV1(AliTRDdataArrayI *digits, Int_t side // ADC data for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) { - Int_t padcol = (17-(iAdc-2)) + (iMcm % 4)*18 + side*72; - UInt_t aa = 2; + Int_t padcol = fGeo->GetPadCol(iRob, iMcm, iAdc); + UInt_t aa = !(iAdc & 1) + 2; UInt_t *a = new UInt_t[nTBin+2]; // 3 timebins are packed into one 32 bits word for (Int_t iT = 0; iT < nTBin; iT+=3) { - if ((padcol >= 0) && - (padcol < nCol)) { - if ((iT ) < nTBin ) { - a[iT ] = digits->GetDataUnchecked(padrow,padcol,iT); - } - else { - a[iT ] = 0; - } - if ((iT + 1) < nTBin ) { - a[iT+1] = digits->GetDataUnchecked(padrow,padcol,iT + 1); - } - else { - a[iT+1] = 0; - } - if ((iT + 2) < nTBin ) { - a[iT+2] = digits->GetDataUnchecked(padrow,padcol,iT + 2); - } - else { - a[iT+2] = 0; - } - } - else { - a[iT] = a[iT+1] = a[iT+2] = 0; // This happenes at the edge of chamber - } - x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa; - if (nw < maxSize) { - buf[nw++] = x; + if ((padcol >= 0) && (padcol < nCol)) { + a[iT ] = ((iT ) < nTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT ) : 0; + a[iT+1] = ((iT + 1) < nTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT + 1) : 0; + a[iT+2] = ((iT + 2) < nTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT + 2) : 0; + } + else { + a[iT] = a[iT+1] = a[iT+2] = 0; // This happenes at the edge of chamber (should be pedestal! How?) } - else { - of++; + x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa; + if (nw < maxSize) { + buf[nw++] = x; } - if (aa == 2) { - aa = 3; - } - else { - aa = 2; // aa alternatively changes between 10b and 11b + else { + of++; } - } + } // Diagnostics Float_t avg = 0; Float_t rms = 0; @@ -582,8 +582,8 @@ Int_t AliTRDrawData::ProduceHcDataV1(AliTRDdataArrayI *digits, Int_t side } rms = TMath::Sqrt(rms / (Float_t) nTBin); if (rms > 1.7) { - AliDebug(1,Form("Large RMS (>1.7) (ROB,MCM,ADC)=(%02d,%02d,%02d), avg=%03.1f, rms=%03.1f\n" - ,iRob,iMcm,iAdc,avg,rms)); + AliDebug(2,Form("Large RMS (>1.7) (ROB,MCM,ADC)=(%02d,%02d,%02d), avg=%03.1f, rms=%03.1f" + ,iRob,iMcm,iAdc,avg,rms)); } delete a; } @@ -592,7 +592,7 @@ Int_t AliTRDrawData::ProduceHcDataV1(AliTRDdataArrayI *digits, Int_t side // Write end of raw data marker if (nw < maxSize) { - buf[nw++] = 0x00000000; + buf[nw++] = end_of_event_marker; } else { of++; @@ -606,10 +606,26 @@ Int_t AliTRDrawData::ProduceHcDataV1(AliTRDdataArrayI *digits, Int_t side } //_____________________________________________________________________________ -AliTRDdigitsManager* AliTRDrawData::Raw2Digits(AliRawReader *rawReader) +AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader) { // - // Read the raw data digits and put them into the returned digits manager + // Read raw data and convert to digits + // + + if ( fRawVersion == 0 ) { + return Raw2DigitsV0(rawReader); // fRawVersion == 0 + } + else { + return Raw2DigitsVx(rawReader); // fRawVersion > 0 + } + +} + +//_____________________________________________________________________________ +AliTRDdigitsManager *AliTRDrawData::Raw2DigitsV0(AliRawReader *rawReader) +{ + // + // Bogdan's raw data reader (for offline only). // AliTRDdataArrayI *digits = 0; @@ -621,13 +637,13 @@ AliTRDdigitsManager* AliTRDrawData::Raw2Digits(AliRawReader *rawReader) AliTRDCommonParam* commonParam = AliTRDCommonParam::Instance(); if (!commonParam) { - AliError("Could not get common parameters\n"); + AliError("Could not get common parameters"); return 0; } - + AliTRDcalibDB* calibration = AliTRDcalibDB::Instance(); if (!calibration) { - AliError("Could not get calibration object\n"); + AliError("Could not get calibration object"); return 0; } @@ -675,7 +691,7 @@ AliTRDdigitsManager* AliTRDrawData::Raw2Digits(AliRawReader *rawReader) track2->Allocate(rowMax,colMax,timeTotal); } - } + } digits->SetDataUnchecked(input.GetRow(),input.GetColumn(), input.GetTime(),input.GetSignal()); @@ -698,3 +714,40 @@ AliTRDdigitsManager* AliTRDrawData::Raw2Digits(AliRawReader *rawReader) return digitsManager; } + +//_____________________________________________________________________________ +AliTRDdigitsManager *AliTRDrawData::Raw2DigitsVx(AliRawReader *rawReader) +{ + + // + // This is executed for all Raw Data Versions > 0. Raw data is read and filled + // into digits array. Next function is not used. + // + + AliTRDdataArrayI *digits = 0; + + AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance(); + if (!commonParam) { + AliError("Could not get common params"); + return 0; + } + + AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); + if (!calibration) { + AliError("Could not get calibration object"); + return 0; + } + + // Create the digits manager + AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager(); + digitsManager->CreateArrays(); + + AliTRDRawStream input(rawReader, digitsManager, digits); + input.SetRawVersion( fRawVersion ); + input.ReadAll(); // Loop through the digits + + delete digits; + + return digitsManager; + +} diff --git a/TRD/AliTRDrawData.h b/TRD/AliTRDrawData.h index 5ec84a67616..a6e29e719af 100644 --- a/TRD/AliTRDrawData.h +++ b/TRD/AliTRDrawData.h @@ -23,6 +23,12 @@ class AliTRDcalibDB; class AliTRDgeometry; class AliTRDdataArrayI; +// +// The following are defined in AliTRDRawStream.h: +//const Int_t end_of_tracklet_marker = 0xAAAAAAAA; /*This marks the end of tracklet data words*/ +//const Int_t end_of_event_marker = 0x00000000; /*This marks the end of half-chamber-data*/ +// + class AliTRDrawData : public TObject { public: @@ -31,19 +37,23 @@ class AliTRDrawData : public TObject { AliTRDrawData(const AliTRDrawData &r); virtual ~AliTRDrawData(); - AliTRDrawData &operator=(const AliTRDrawData &/*r*/) { return *this; } + AliTRDrawData &operator=(const AliTRDrawData &/*r*/) { return *this; } - virtual Bool_t Digits2Raw(TTree *digits, TTree *tracks = NULL); - virtual Bool_t SetRawVersion(Int_t v); + virtual Bool_t Digits2Raw(TTree *digits, TTree *tracks = NULL); + virtual Bool_t SetRawVersion(Int_t v); virtual AliTRDdigitsManager* Raw2Digits(AliRawReader *rawReader); protected: - virtual Bool_t Digits2RawV0(AliTRDdigitsManager* digitsManager); - virtual Bool_t Digits2RawV1(AliTRDdigitsManager* digitsManager); - virtual Int_t ProduceHcDataV1(AliTRDdataArrayI *digits - , Int_t side, Int_t det, UInt_t *buf, Int_t maxSize); + virtual Bool_t Digits2RawV0(AliTRDdigitsManager* digitsManager); // for fRawVersion == 0 + virtual Bool_t Digits2RawVx(AliTRDdigitsManager* digitsManager); // for fRawVersion > 0 + virtual Int_t ProduceHcDataV1andV2(AliTRDdataArrayI *digits, Int_t side, Int_t det, UInt_t *buf, Int_t maxSize); + //virtual Int_t ProduceHcDataV3(AliTRDdataArrayI *digits, Int_t side, Int_t det, UInt_t *buf, Int_t maxSize); + //virtual Int_t ProduceHcDataV4(AliTRDdataArrayI *digits, Int_t side, Int_t det, UInt_t *buf, Int_t maxSize); + + virtual AliTRDdigitsManager* Raw2DigitsV0(AliRawReader* rawReader); + virtual AliTRDdigitsManager* Raw2DigitsVx(AliRawReader* rawReader); Int_t fRawVersion; // Which version of raw simulator is used AliTRDCommonParam *fCommonParam; //! Common parameters -- 2.43.0