From 726d762cdb0c52b5d086f67f38eb804e39fe1976 Mon Sep 17 00:00:00 2001 From: cvetan Date: Thu, 19 Jul 2007 09:46:31 +0000 Subject: [PATCH] Realistic raw-data simulation and reading. Waiting for the documents that describes the exact format, so that to finalize the corresponding aliroot code --- VZERO/AliVZERO.cxx | 34 +++++++-- VZERO/AliVZEROBuffer.cxx | 104 +++++++++++++++++++++------ VZERO/AliVZEROBuffer.h | 7 +- VZERO/AliVZERORawStream.cxx | 120 +++++++++++++++++++++++++++----- VZERO/AliVZERORawStream.h | 44 +++++++++--- VZERO/AliVZEROReconstructor.cxx | 11 +-- 6 files changed, 259 insertions(+), 61 deletions(-) diff --git a/VZERO/AliVZERO.cxx b/VZERO/AliVZERO.cxx index a1cee7fc632..ca33b1e4d9d 100755 --- a/VZERO/AliVZERO.cxx +++ b/VZERO/AliVZERO.cxx @@ -290,10 +290,27 @@ void AliVZERO::Digits2Raw() ofstream ftxt; buffer->SetVerbose(0); - Int_t fVerbose = buffer->GetVerbose(); + Int_t verbose = buffer->GetVerbose(); + // Get Trigger information first + // Read trigger inputs from trigger-detector object + AliDataLoader * dataLoader = fLoader->GetDigitsDataLoader(); + if( !dataLoader->IsFileOpen() ) + dataLoader->OpenFile( "READ" ); + AliTriggerDetector* trgdet = (AliTriggerDetector*)dataLoader->GetDirectory()->Get( "Trigger" ); + UInt_t triggerInfo = 0; + if(trgdet) { + triggerInfo = trgdet->GetMask() & 0xffff; + } + else { + AliError(Form("There is no trigger object for %s",fLoader->GetName())); + } + buffer->WriteTriggerInfo((UInt_t)triggerInfo); + + // Now write the channel information: charge+time + // We assume here an ordered (by PMNumber) array of + // digits!! Int_t nEntries = Int_t(digits->GetEntries()); - for (Int_t i = 0; i < nEntries; i++) { fVZERO->ResetDigits(); @@ -301,23 +318,26 @@ void AliVZERO::Digits2Raw() Int_t ndig = VZEROdigits->GetEntriesFast(); if(ndig == 0) continue; - if(fVerbose == 2) {ftxt.open("VZEROdigits.txt",ios::app);} + if(verbose == 2) {ftxt.open("VZEROdigits.txt",ios::app);} for(Int_t k=0; kAt(k); Int_t ADC = fVZERODigit->ADC(); Int_t PMNumber = fVZERODigit->PMNumber(); Int_t Time = fVZERODigit->Time(); - if(fVerbose == 1) { cout <<"DDL: "<WriteBinary(PMNumber, ADC, Time); + buffer->WriteChannel(PMNumber, ADC, Time); } - if(fVerbose==2) ftxt.close(); + if(verbose==2) ftxt.close(); } + buffer->WriteScalers(); + buffer->WriteMBInfo(); + delete buffer; fLoader->UnloadDigits(); } diff --git a/VZERO/AliVZEROBuffer.cxx b/VZERO/AliVZEROBuffer.cxx index 3a1e7366f2e..c3146339537 100644 --- a/VZERO/AliVZEROBuffer.cxx +++ b/VZERO/AliVZEROBuffer.cxx @@ -22,6 +22,7 @@ #include #include +#include "AliLog.h" #include "AliRawDataHeader.h" #include "AliVZEROBuffer.h" @@ -33,8 +34,7 @@ ClassImp(AliVZEROBuffer) //_____________________________________________________________________________ AliVZEROBuffer::AliVZEROBuffer():TObject(), fVerbose(0), - f(), - fNumberOfDigits(0) + f() { // // default constructor @@ -43,8 +43,7 @@ AliVZEROBuffer::AliVZEROBuffer():TObject(), //_____________________________________________________________________________ AliVZEROBuffer::AliVZEROBuffer(const char* fileName):TObject(), fVerbose(0), - f(), - fNumberOfDigits(0) + f() { // Constructor f = new AliFstream(fileName); @@ -71,8 +70,7 @@ AliVZEROBuffer::~AliVZEROBuffer(){ //_____________________________________________________________________________ AliVZEROBuffer::AliVZEROBuffer(const AliVZEROBuffer &source):TObject(source), fVerbose(0), - f(), - fNumberOfDigits(0) + f() { // Copy Constructor @@ -90,21 +88,87 @@ AliVZEROBuffer& AliVZEROBuffer::operator=(const AliVZEROBuffer &source) } //_____________________________________________________________________________ -void AliVZEROBuffer::WriteBinary(Int_t cell,Int_t ADC, Int_t Time){ +void AliVZEROBuffer::WriteTriggerInfo(UInt_t trigger) { + // The method writes VZERO trigger information + // This info is contained in the first two + // raw-data words following the raw-data header (CDH). + + f->WriteBuffer((char*)(&trigger),sizeof(trigger)); + + // By default all the inputs are unmasked... Hopefully + UInt_t triggerMask = 0xffff; + f->WriteBuffer((char*)(&triggerMask),sizeof(triggerMask)); +} + +//_____________________________________________________________________________ +void AliVZEROBuffer::WriteChannel(Int_t cell,Int_t ADC, Int_t Time){ // It writes VZERO digits as a raw data file. // Being called by AliVZERODDL.C - struct DataFile{ - Int_t cell; - Int_t ADC; - Int_t Time; - }; - - DataFile data; - data.cell = cell; - data.ADC = ADC; - data.Time = Time; - - fNumberOfDigits++; - f->WriteBuffer((char*)(&data),sizeof(data)); + UInt_t data = 0; + // Information about previous 10 interaction + // Not available in the simulation... + for(Int_t i = 0; i < 5; i++) + f->WriteBuffer((char*)&data,sizeof(data)); + + // Now write the ADC charge for this channel + if (ADC < 0 || ADC > 1023) { + AliInfo(Form("ADC saturated: %d. Truncating to 1023",ADC)); + ADC = 1023; + } + data = ADC | 0x400; // 'Interaction' flag + f->WriteBuffer((char*)&data,sizeof(data)); + + data = 0; + // Information about following 10 interaction + // Not available in the simulation... + for(Int_t i = 0; i < 5; i++) + f->WriteBuffer((char*)&data,sizeof(data)); + + // Now write the timing information + data = Time & 0xfff; + // The signal width is not available the digits! + // To be added soon + // data |= (width & 0x7f) << 12; + f->WriteBuffer((char*)&data,sizeof(data)); +} + +//_____________________________________________________________________________ +void AliVZEROBuffer::WriteScalers() { + // The method writes the VZERO trigger scalers + // For the moment there is no way to simulate + // this, so we fill the necessary words with 0 + + // First the general trigger scalers (16 of them) + for(Int_t i = 0; i < 16; i++) { + UInt_t data = 0; + f->WriteBuffer((char*)&data,sizeof(data)); + } + + // Then beam-beam and beam-gas scalers for + // each individual channel (4x64 words) + for(Int_t i = 0; i < 256; i++) { + UInt_t data = 0; + f->WriteBuffer((char*)&data,sizeof(data)); + } +} + +//_____________________________________________________________________________ +void AliVZEROBuffer::WriteMBInfo() { + // The method writes information about + // the 10 previous minimum-bias events + + // First the bunch crossing numbers + // for these 10 events + for(Int_t i = 0; i < 10; i++) { + UInt_t data = 0; + f->WriteBuffer((char*)&data,sizeof(data)); + } + + // Then channels charge for each of these + // 10 events (5 words/channel) + for(Int_t i = 0; i < 320; i++) { + UInt_t data = 0; + f->WriteBuffer((char*)&data,sizeof(data)); + } } diff --git a/VZERO/AliVZEROBuffer.h b/VZERO/AliVZEROBuffer.h index a08972ec6cf..1a04cbf1bdc 100644 --- a/VZERO/AliVZEROBuffer.h +++ b/VZERO/AliVZEROBuffer.h @@ -23,15 +23,16 @@ public: virtual ~AliVZEROBuffer(); //destructor AliVZEROBuffer(const AliVZEROBuffer &source); // copy constructor AliVZEROBuffer& operator=(const AliVZEROBuffer &source); // ass. op. - void WriteBinary(Int_t cell,Int_t ADC, Int_t Time); - UInt_t GetDigNumber()const{return fNumberOfDigits;} + void WriteTriggerInfo(UInt_t trigger); + void WriteChannel(Int_t cell,Int_t ADC, Int_t Time); + void WriteScalers(); + void WriteMBInfo(); void SetVerbose(Int_t val){fVerbose=val;} Int_t GetVerbose() const{return fVerbose;} private: Int_t fVerbose; //Verbosity level: 0-silent, 1:cout msg, 2: txt files for checking AliFstream* f; //The IO file name - UInt_t fNumberOfDigits; //Number of VZERO digits ClassDef(AliVZEROBuffer,1) }; diff --git a/VZERO/AliVZERORawStream.cxx b/VZERO/AliVZERORawStream.cxx index ace84ad79e1..25831171f2f 100644 --- a/VZERO/AliVZERORawStream.cxx +++ b/VZERO/AliVZERORawStream.cxx @@ -30,9 +30,8 @@ ClassImp(AliVZERORawStream) //_____________________________________________________________________________ AliVZERORawStream::AliVZERORawStream(AliRawReader* rawReader) : - fCell(-1), - fADC(-1), - fTime(-1), + fTrigger(0), + fTriggerMask(0), fPosition(-1), fRawReader(rawReader), fData(NULL) @@ -44,6 +43,22 @@ AliVZERORawStream::AliVZERORawStream(AliRawReader* rawReader) : fRawReader->Reset(); AliDebug(1,Form("Selecting raw data for detector %d",AliDAQ::DetectorID("VZERO"))); fRawReader->Select("VZERO"); + + // Initalize the containers + for(Int_t i = 0; i < kNChannels; i++) { + fTime[i] = fWidth[i] = 0; + for(Int_t j = 0; j < kNEvOfInt; j++) { + fADC[i][j] = 0; + fIsInt[i][j] = fIsBB[i][j] = fIsBG[i][j] = kFALSE; + } + fBBScalers[i] = fBGScalers[i] = 0; + for(Int_t j = 0; j < kNBunches; j++) { + fChargeMB[i][j] = 0; + fIsIntMB[i][j] = fIsBBMB[i][j] = fIsBGMB[i][j] = kFALSE; + } + } + for(Int_t i = 0; i < kNScalers; i++) fScalers[i] = 0; + for(Int_t i = 0; i < kNBunches; i++) fBunchNumbers[i] = 0; } //_____________________________________________________________________________ @@ -57,7 +72,25 @@ void AliVZERORawStream::Reset() { // reset raw stream params - fCell = fADC = fTime = fPosition = -1; + // Reinitalize the containers + for(Int_t i = 0; i < kNChannels; i++) { + fTime[i] = fWidth[i] = 0; + for(Int_t j = 0; j < kNEvOfInt; j++) { + fADC[i][j] = 0; + fIsInt[i][j] = fIsBB[i][j] = fIsBG[i][j] = kFALSE; + } + fBBScalers[i] = fBGScalers[i] = 0; + for(Int_t j = 0; j < kNBunches; j++) { + fChargeMB[i][j] = 0; + fIsIntMB[i][j] = fIsBBMB[i][j] = fIsBGMB[i][j] = kFALSE; + } + } + for(Int_t i = 0; i < kNScalers; i++) fScalers[i] = 0; + for(Int_t i = 0; i < kNBunches; i++) fBunchNumbers[i] = 0; + + fTrigger = fTriggerMask = 0; + fPosition = -1; + fData = NULL; if (fRawReader) fRawReader->Reset(); } @@ -68,27 +101,66 @@ Bool_t AliVZERORawStream::Next() // read next digit from the VZERO raw data stream // return kFALSE in case of error or no digits left - if (fPosition < 0) { - if (!fRawReader->ReadNextData(fData)) return kFALSE; - if (fRawReader->GetDataSize()%3 != 0) { - fRawReader->AddFatalErrorLog(kRawDataSizeErr,Form("size %d != n*12",fRawReader->GetDataSize())); - AliWarning(Form("Wrong VZERO raw data size: %d, expected n*12 bytes!",fRawReader->GetDataSize())); + if (fPosition >= 0) return kFALSE; + + if (!fRawReader->ReadNextData(fData)) return kFALSE; + if (fRawReader->GetDataSize() == 0) return kFALSE; + + if (fRawReader->GetDataSize() != 5488) { + fRawReader->AddFatalErrorLog(kRawDataSizeErr,Form("size %d != 5488",fRawReader->GetDataSize())); + AliWarning(Form("Wrong VZERO raw data size: %d, expected 5488 bytes!",fRawReader->GetDataSize())); return kFALSE; + } + + fPosition = 0; + + fTrigger = GetNextWord() & 0xffff; + fTriggerMask = GetNextWord() & 0xffff; + + for(Int_t iChannel = 0; iChannel < kNChannels; iChannel++) { + for(Int_t iEvOfInt = 0; iEvOfInt < kNEvOfInt; iEvOfInt++) { + UShort_t data = GetNextShort(); + fADC[iChannel][iEvOfInt] = data & 0x3ff; + fIsInt[iChannel][iEvOfInt] = (data >> 10) & 0x1; + fIsBB[iChannel][iEvOfInt] = (data >> 11) & 0x1; + fIsBG[iChannel][iEvOfInt] = (data >> 12) & 0x1; } - fPosition = 0; + GetNextShort(); + + UInt_t time = GetNextWord(); + fTime[iChannel] = time & 0xfff; + fWidth[iChannel] = (time >> 12) & 0x7f; } - if (fPosition >= fRawReader->GetDataSize()) return kFALSE; + for(Int_t iScaler = 0; iScaler < kNScalers; iScaler++) + fScalers[iScaler] = GetNextWord(); + + for(Int_t iChannel = 0; iChannel < kNChannels; iChannel++) { + fBBScalers[iChannel] = ((ULong64_t)GetNextWord()) << 32; + fBBScalers[iChannel] |= GetNextWord(); - fCell = GetNextWord(); - fADC = GetNextWord(); - fTime = GetNextWord(); + fBGScalers[iChannel] = ((ULong64_t)GetNextWord()) << 32; + fBGScalers[iChannel] |= GetNextWord(); + } + + for(Int_t iBunch = 0; iBunch < kNBunches; iBunch++) + fBunchNumbers[iBunch] = GetNextWord(); + + for(Int_t iChannel = 0; iChannel < kNChannels; iChannel++) { + for(Int_t iBunch = 0; iBunch < kNBunches; iBunch++) { + UShort_t data = GetNextShort(); + fChargeMB[iChannel][iBunch] = data & 0x3ff; + fIsIntMB[iChannel][iBunch] = (data >> 10) & 0x1; + fIsBBMB[iChannel][iBunch] = (data >> 11) & 0x1; + fIsBGMB[iChannel][iBunch] = (data >> 12) & 0x1; + } + } return kTRUE; } //_____________________________________________________________________________ -Int_t AliVZERORawStream::GetNextWord() +UInt_t AliVZERORawStream::GetNextWord() { // This method returns the next 32 bit word // inside the raw data payload. @@ -96,7 +168,7 @@ Int_t AliVZERORawStream::GetNextWord() // independent. if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !"); - Int_t word = 0; + UInt_t word = 0; word |= fData[fPosition++]; word |= fData[fPosition++] << 8; word |= fData[fPosition++] << 16; @@ -104,3 +176,19 @@ Int_t AliVZERORawStream::GetNextWord() return word; } + +//_____________________________________________________________________________ +UShort_t AliVZERORawStream::GetNextShort() +{ + // This method returns the next 16 bit word + // inside the raw data payload. + // The method is supposed to be endian (platform) + // independent. + if (!fData || fPosition < 0) AliFatal("Raw data payload buffer is not yet initialized !"); + + UShort_t word = 0; + word |= fData[fPosition++]; + word |= fData[fPosition++] << 8; + + return word; +} diff --git a/VZERO/AliVZERORawStream.h b/VZERO/AliVZERORawStream.h index 20b69e87d1e..836d874b6ef 100644 --- a/VZERO/AliVZERORawStream.h +++ b/VZERO/AliVZERORawStream.h @@ -23,9 +23,17 @@ class AliVZERORawStream: public TObject { virtual void Reset(); virtual Bool_t Next(); - Int_t GetCell() { return fCell; } - Int_t GetADC() { return fADC; } - Int_t GetTime() { return fTime; } + UShort_t GetADC(Int_t channel) const + { return fADC[channel][kNEvOfInt/2]; } + UInt_t GetTime(Int_t channel) const + { return fTime[channel]; } + + enum EVZERORawDataParams { + kNChannels = 64, + kNEvOfInt = 21, // Number of events of interest + kNScalers = 16, + kNBunches = 10 + }; enum EVZERORawStreamError { kRawDataSizeErr = 1 @@ -36,17 +44,33 @@ class AliVZERORawStream: public TObject { AliVZERORawStream(const AliVZERORawStream& stream); AliVZERORawStream& operator = (const AliVZERORawStream& stream); - Int_t GetNextWord(); + UInt_t GetNextWord(); + UShort_t GetNextShort(); + + ULong64_t fBBScalers[kNChannels]; // 'Beam-Beam' scalers for all channels + ULong64_t fBGScalers[kNChannels]; // 'Beam-Gas' scalers for all channels + UInt_t fScalers[kNScalers]; // Trigger scalers + UInt_t fBunchNumbers[kNBunches]; // Bunch numbers for the previous 10 MB events + UShort_t fChargeMB[kNChannels][kNBunches]; // ADC counts for all channels for the previous 10 MB events + Bool_t fIsIntMB[kNChannels][kNBunches]; // 'Interaction' flag for all channels for the previous 10 MB events + Bool_t fIsBBMB[kNChannels][kNBunches]; // 'Beam-Beam' flag for all channels for the previous 10 MB events + Bool_t fIsBGMB[kNChannels][kNBunches]; // 'Beam-Gas' for all channels for the previous 10 MB events + + UShort_t fADC[kNChannels][kNEvOfInt]; // ADC counts for all channels and all events of interest + Bool_t fIsInt[kNChannels][kNEvOfInt]; // 'Interaction' flag for all channels + Bool_t fIsBB[kNChannels][kNEvOfInt]; // 'Beam-Beam' flag for all channels + Bool_t fIsBG[kNChannels][kNEvOfInt]; // 'Beam-Gas' flag for all channels + Int_t fTime[kNChannels]; // leading time for all channels + Int_t fWidth[kNChannels]; // signal width for all channels - Int_t fCell; // current VZERO cell - Int_t fADC; // current ADC count - Int_t fTime; // current time + UShort_t fTrigger; // VZERO trigger inputs + UShort_t fTriggerMask; // VZERO trigger inputs mask - Int_t fPosition; // current position in raw-data stream + Int_t fPosition; // current position in the raw-data payload - AliRawReader* fRawReader; // object for reading the raw data + AliRawReader* fRawReader; // object for reading the raw data - UChar_t* fData; // pointer to raw data payload + UChar_t* fData; // pointer to raw data payload ClassDef(AliVZERORawStream, 0) // class for reading VZERO DDL raw data }; diff --git a/VZERO/AliVZEROReconstructor.cxx b/VZERO/AliVZEROReconstructor.cxx index 60b63fd6008..3863009e03f 100644 --- a/VZERO/AliVZEROReconstructor.cxx +++ b/VZERO/AliVZEROReconstructor.cxx @@ -85,12 +85,13 @@ void AliVZEROReconstructor::ConvertDigits(AliRawReader* rawReader, TTree* digits rawReader->Reset(); AliVZERORawStream rawStream(rawReader); - while (rawStream.Next()) { - Int_t pmNumber = rawStream.GetCell(); - Int_t adc = rawStream.GetADC(); - Int_t time = rawStream.GetTime(); + if (rawStream.Next()) { + for(Int_t iChannel = 0; iChannel < 64; iChannel++) { + Int_t adc = rawStream.GetADC(iChannel); + Int_t time = rawStream.GetTime(iChannel); new ((*digitsArray)[digitsArray->GetEntriesFast()]) - AliVZEROdigit(pmNumber,adc,time); + AliVZEROdigit(iChannel,adc,time); + } } digitsTree->Fill(); -- 2.39.3