From 625f526014766c3b393db3c04885fe3402a957d7 Mon Sep 17 00:00:00 2001 From: cblume Date: Thu, 17 Jan 2008 17:25:16 +0000 Subject: [PATCH] Re-structured digitizer --- TRD/AliTRDQADataMaker.cxx | 6 +- TRD/AliTRDQADataMakerSim.cxx | 6 +- TRD/AliTRDRawStream.cxx | 11 +- TRD/AliTRDRawStreamV2.cxx | 11 +- TRD/AliTRDarrayS.cxx | 86 ++ TRD/AliTRDarrayS.h | 32 + TRD/AliTRDclusterizer.cxx | 29 +- TRD/AliTRDclusterizer.h | 4 +- TRD/AliTRDdataArray.h | 15 +- TRD/AliTRDdataArrayS.cxx | 682 +++++++++++++++ TRD/AliTRDdataArrayS.h | 80 ++ TRD/AliTRDdigit.cxx | 20 +- TRD/AliTRDdigit.h | 15 +- TRD/AliTRDdigitizer.cxx | 1553 ++++++++++++++++++---------------- TRD/AliTRDdigitizer.h | 139 +-- TRD/AliTRDdigitsManager.cxx | 326 ++++--- TRD/AliTRDdigitsManager.h | 44 +- TRD/AliTRDgeometry.h | 4 +- TRD/AliTRDrawData.cxx | 19 +- TRD/AliTRDrawData.h | 8 +- TRD/AliTRDrawStreamTB.cxx | 11 +- TRD/AliTRDsegmentArray.cxx | 453 +++++++++- TRD/AliTRDsegmentArray.h | 39 +- TRD/AliTRDtrigger.cxx | 11 +- TRD/AliTRDtrigger.h | 5 +- TRD/TRDbaseLinkDef.h | 3 +- TRD/libTRDbase.pkg | 3 +- 27 files changed, 2499 insertions(+), 1116 deletions(-) create mode 100644 TRD/AliTRDarrayS.cxx create mode 100644 TRD/AliTRDarrayS.h create mode 100644 TRD/AliTRDdataArrayS.cxx create mode 100644 TRD/AliTRDdataArrayS.h diff --git a/TRD/AliTRDQADataMaker.cxx b/TRD/AliTRDQADataMaker.cxx index e102bd9a70a..866ccb86c61 100644 --- a/TRD/AliTRDQADataMaker.cxx +++ b/TRD/AliTRDQADataMaker.cxx @@ -45,7 +45,7 @@ #include "AliTRDQADataMaker.h" #include "AliTRDdigitsManager.h" #include "AliTRDgeometry.h" -#include "AliTRDdataArrayI.h" +#include "AliTRDdataArrayS.h" #include "AliTRDrawStreamTB.h" #include "AliTRDRawStreamV2.h" @@ -572,7 +572,7 @@ void AliTRDQADataMaker::MakeDigits(TTree * digits) for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) { - AliTRDdataArrayI *digitsIn = digitsManager->GetDigits(i); + AliTRDdataArrayS *digitsIn = (AliTRDdataArrayS *) digitsManager->GetDigits(i); // This is to take care of switched off super modules if (digitsIn->GetNtime() == 0) continue; @@ -633,7 +633,7 @@ void AliTRDQADataMaker::MakeSDigits(TTree * digits) for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) { - AliTRDdataArrayI *digitsIn = digitsManager->GetDigits(i); + AliTRDdataArrayS *digitsIn = (AliTRDdataArrayS *) digitsManager->GetDigits(i); // This is to take care of switched off super modules if (digitsIn->GetNtime() == 0) continue; diff --git a/TRD/AliTRDQADataMakerSim.cxx b/TRD/AliTRDQADataMakerSim.cxx index 52951ce8ddb..927a37730aa 100644 --- a/TRD/AliTRDQADataMakerSim.cxx +++ b/TRD/AliTRDQADataMakerSim.cxx @@ -45,7 +45,7 @@ #include "AliTRDQADataMakerSim.h" #include "AliTRDdigitsManager.h" #include "AliTRDgeometry.h" -#include "AliTRDdataArrayI.h" +#include "AliTRDdataArrayS.h" //#include "AliTRDrawStreamTB.h" #include "AliQAChecker.h" @@ -251,7 +251,7 @@ void AliTRDQADataMakerSim::MakeDigits(TTree * digits) for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) { - AliTRDdataArrayI *digitsIn = digitsManager->GetDigits(i); + AliTRDdataArrayS *digitsIn = (AliTRDdataArrayS *) digitsManager->GetDigits(i); // This is to take care of switched off super modules if (digitsIn->GetNtime() == 0) continue; @@ -312,7 +312,7 @@ void AliTRDQADataMakerSim::MakeSDigits(TTree * digits) for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) { - AliTRDdataArrayI *digitsIn = digitsManager->GetDigits(i); + AliTRDdataArrayS *digitsIn = (AliTRDdataArrayS *) digitsManager->GetDigits(i); // This is to take care of switched off super modules if (digitsIn->GetNtime() == 0) continue; diff --git a/TRD/AliTRDRawStream.cxx b/TRD/AliTRDRawStream.cxx index d23ed07bd3b..3e1b495feb2 100644 --- a/TRD/AliTRDRawStream.cxx +++ b/TRD/AliTRDRawStream.cxx @@ -37,6 +37,7 @@ #include "AliTRDcalibDB.h" #include "AliTRDdigitsManager.h" #include "AliTRDdataArrayI.h" +#include "AliTRDdataArrayS.h" #include "AliTRDSignalIndex.h" #include "AliTRDfeeParam.h" @@ -627,7 +628,7 @@ Int_t AliTRDRawStream::NextChamber(AliTRDdigitsManager *man) // Updates the next data word pointer // - AliTRDdataArrayI *digits = 0; + AliTRDdataArrayS *digits = 0; AliTRDdataArrayI *track0 = 0; AliTRDdataArrayI *track1 = 0; AliTRDdataArrayI *track2 = 0; @@ -809,10 +810,10 @@ Int_t AliTRDRawStream::NextChamber(AliTRDdigitsManager *man) AliDebug(4, "New DET!"); // allocate stuff for the new det //man->ResetArrays(); - digits = man->GetDigits(fDET); - track0 = man->GetDictionary(fDET,0); - track1 = man->GetDictionary(fDET,1); - track2 = man->GetDictionary(fDET,2); + digits = (AliTRDdataArrayS *) man->GetDigits(fDET); + track0 = (AliTRDdataArrayI *) man->GetDictionary(fDET,0); + track1 = (AliTRDdataArrayI *) man->GetDictionary(fDET,1); + track2 = (AliTRDdataArrayI *) man->GetDictionary(fDET,2); // Allocate memory space for the digits buffer if (digits->GetNtime() == 0) diff --git a/TRD/AliTRDRawStreamV2.cxx b/TRD/AliTRDRawStreamV2.cxx index e13cb7a2474..c4274ab0596 100644 --- a/TRD/AliTRDRawStreamV2.cxx +++ b/TRD/AliTRDRawStreamV2.cxx @@ -37,6 +37,7 @@ #include "AliTRDfeeParam.h" #include "AliTRDdigitsManager.h" #include "AliTRDdataArrayI.h" +#include "AliTRDdataArrayS.h" #include "AliTRDSignalIndex.h" ClassImp(AliTRDRawStreamV2) @@ -1210,7 +1211,7 @@ Int_t AliTRDRawStreamV2::NextChamber(AliTRDdigitsManager *man) // Return value is the detector number // - AliTRDdataArrayI *digits = 0; + AliTRDdataArrayS *digits = 0; AliTRDdataArrayI *track0 = 0; AliTRDdataArrayI *track1 = 0; AliTRDdataArrayI *track2 = 0; @@ -1307,10 +1308,10 @@ Int_t AliTRDRawStreamV2::NextChamber(AliTRDdigitsManager *man) // AliDebug(4, Form("???? New DET ???? %d last %d", fDET, fLastDET)); // allocate stuff for the new det //man->ResetArrays(); - digits = man->GetDigits(fDET); - track0 = man->GetDictionary(fDET,0); - track1 = man->GetDictionary(fDET,1); - track2 = man->GetDictionary(fDET,2); + digits = (AliTRDdataArrayS *) man->GetDigits(fDET); + track0 = (AliTRDdataArrayI *) man->GetDictionary(fDET,0); + track1 = (AliTRDdataArrayI *) man->GetDictionary(fDET,1); + track2 = (AliTRDdataArrayI *) man->GetDictionary(fDET,2); // Allocate memory space for the digits buffer if (digits->GetNtime() == 0) diff --git a/TRD/AliTRDarrayS.cxx b/TRD/AliTRDarrayS.cxx new file mode 100644 index 00000000000..2b104330870 --- /dev/null +++ b/TRD/AliTRDarrayS.cxx @@ -0,0 +1,86 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id: AliTRDarrayS.cxx,v Exp $ */ + +/////////////////////////////////////////////////////////////////////// +// // +// Added additional functionality to the original TArrayS. // +// - Multiple inheritance from TObject // +// - Function Expand() allows to expand the array without // +// deleting the array contents // +// // +// Origin: Marian Ivanov, Uni. of Bratislava, ivanov@fmph.uniba.sk // +// // +/////////////////////////////////////////////////////////////////////// + +#include "AliTRDarrayS.h" + +ClassImp(AliTRDarrayS) + +//_____________________________________________________________________________ +AliTRDarrayS::AliTRDarrayS():TArrayS() +{ + // + // Default constructor + // + +} + +//_____________________________________________________________________________ +AliTRDarrayS::~AliTRDarrayS() +{ + // + // Default destructor + // + +} + +//_____________________________________________________________________________ +void AliTRDarrayS::Copy(TObject &a) const +{ + // + // Copy function + // + + TObject::Copy(a); + TArrayS::Copy(((TArrayS &) a)); + +} + +//_____________________________________________________________________________ +void AliTRDarrayS::Expand(Int_t n) +{ + // + // Sets the array size of the TArrayF object to integers and copies + // the old array. + // If n < 0 leave the array unchanged. + // The user is responsible for the appropriate size of the array. + // + + if (n < 0) { + return; + } + + fArray = (Short_t *) TStorage::ReAlloc(fArray + ,n *sizeof(Short_t) + ,fN*sizeof(Short_t)); + + if (fArray != 0) { + fN = n; + } + +} + diff --git a/TRD/AliTRDarrayS.h b/TRD/AliTRDarrayS.h new file mode 100644 index 00000000000..4b20cab95da --- /dev/null +++ b/TRD/AliTRDarrayS.h @@ -0,0 +1,32 @@ +#ifndef ALITRDARRAYS_H +#define ALITRDARRAYS_H +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id: AliTRDarrayS.h,v Exp $*/ + +#include +#include + +///////////////////////////////////////////////////////////// +// // +// Array of shorts // +// Origin M.Ivanov // +// // +///////////////////////////////////////////////////////////// + +class AliTRDarrayS: public TObject, public TArrayS { + +public: + + AliTRDarrayS(); + virtual ~AliTRDarrayS(); + void Copy(TObject &a) const; + void Expand(Int_t n); + + ClassDef(AliTRDarrayS,1) // An array of shorts + +}; + +#endif + diff --git a/TRD/AliTRDclusterizer.cxx b/TRD/AliTRDclusterizer.cxx index 1ba16e97361..8c517eb1e94 100644 --- a/TRD/AliTRDclusterizer.cxx +++ b/TRD/AliTRDclusterizer.cxx @@ -39,6 +39,7 @@ #include "AliTRDgeometry.h" #include "AliTRDdataArrayF.h" #include "AliTRDdataArrayI.h" +#include "AliTRDdataArrayS.h" #include "AliTRDdigitsManager.h" #include "AliTRDrawData.h" #include "AliTRDcalibDB.h" @@ -455,9 +456,9 @@ Bool_t AliTRDclusterizer::MakeClusters() for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++) { - AliTRDdataArrayI *digitsIn = fDigitsManager->GetDigits(i); + AliTRDdataArrayS *digitsIn = (AliTRDdataArrayS *) fDigitsManager->GetDigits(i); // This is to take care of switched off super modules - if (digitsIn->GetNtime() == 0) + if (!digitsIn->HasData()) { continue; } @@ -476,7 +477,7 @@ Bool_t AliTRDclusterizer::MakeClusters() for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++) { AliTRDdataArrayI *tracksIn = 0; - tracksIn = fDigitsManager->GetDictionary(i,iDict); + tracksIn = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(i,iDict); tracksIn->Expand(); } } @@ -508,7 +509,7 @@ Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader) // Creates clusters from raw data // - AliTRDdataArrayI *digits = 0; + AliTRDdataArrayS *digits = 0; AliTRDdataArrayI *track0 = 0; AliTRDdataArrayI *track1 = 0; AliTRDdataArrayI *track2 = 0; @@ -542,7 +543,7 @@ Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader) if (lastdet != -1) { - digits = fDigitsManager->GetDigits(lastdet); + digits = (AliTRDdataArrayS *) fDigitsManager->GetDigits(lastdet); Bool_t iclusterBranch = kFALSE; if (indexes->HasEntry()) iclusterBranch = MakeClusters(lastdet); @@ -563,13 +564,13 @@ Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader) lastdet = det; // Add a container for the digits of this detector - digits = fDigitsManager->GetDigits(det); - track0 = fDigitsManager->GetDictionary(det,0); - track1 = fDigitsManager->GetDictionary(det,1); - track2 = fDigitsManager->GetDictionary(det,2); + digits = (AliTRDdataArrayS *) fDigitsManager->GetDigits(det); + track0 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,0); + track1 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,1); + track2 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,2); // Allocate memory space for the digits buffer - if (digits->GetNtime() == 0) + if (!digits->HasData()) { //AliDebug(5, Form("Alloc digits for det %d", det)); digits->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins()); @@ -696,10 +697,10 @@ Bool_t AliTRDclusterizer::MakeClusters(Int_t det) // Get the digits // digits should be expanded beforehand! // digitsIn->Expand(); - AliTRDdataArrayI *digitsIn = fDigitsManager->GetDigits(det); + AliTRDdataArrayS *digitsIn = (AliTRDdataArrayS *) fDigitsManager->GetDigits(det); // This is to take care of switched off super modules - if (digitsIn->GetNtime() == 0) + if (!digitsIn->HasData()) { return kFALSE; } @@ -1076,7 +1077,7 @@ Bool_t AliTRDclusterizer::AddLabels(Int_t idet, Int_t firstClusterROC, Int_t nCl for (Int_t iDict = 0; iDict < kNdict; iDict++) { // tracksIn should be expanded beforehand! - tracksIn = fDigitsManager->GetDictionary(idet,iDict); + tracksIn = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(idet,iDict); // Loop though the clusters found in this ROC for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) { @@ -1197,7 +1198,7 @@ Double_t AliTRDclusterizer::Unfold(Double_t eps, Int_t plane, Double_t *padSigna } //_____________________________________________________________________________ -void AliTRDclusterizer::TailCancelation(AliTRDdataArrayI *digitsIn +void AliTRDclusterizer::TailCancelation(AliTRDdataArrayS *digitsIn , AliTRDdataArrayF *digitsOut , AliTRDSignalIndex *indexesIn , AliTRDSignalIndex *indexesOut diff --git a/TRD/AliTRDclusterizer.h b/TRD/AliTRDclusterizer.h index 8ba4fafd132..87d2822acf6 100644 --- a/TRD/AliTRDclusterizer.h +++ b/TRD/AliTRDclusterizer.h @@ -22,7 +22,7 @@ class AliRawReader; class AliTRD; class AliTRDcluster; -class AliTRDdataArrayI; +class AliTRDdataArrayS; class AliTRDdataArrayF; class AliTRDdigitsManager; class AliTRDSignalIndex; @@ -69,7 +69,7 @@ class AliTRDclusterizer : public TNamed { void DeConvExp(Double_t *source, Double_t *target , Int_t nTimeTotal, Int_t nexp); - void TailCancelation(AliTRDdataArrayI *digitsIn + void TailCancelation(AliTRDdataArrayS *digitsIn , AliTRDdataArrayF *digitsOut , AliTRDSignalIndex *indexesIn , AliTRDSignalIndex *indexesOut diff --git a/TRD/AliTRDdataArray.h b/TRD/AliTRDdataArray.h index 2184d6658a7..5d30bbf23a2 100644 --- a/TRD/AliTRDdataArray.h +++ b/TRD/AliTRDdataArray.h @@ -29,14 +29,17 @@ class AliTRDdataArray : public AliTRDsegmentID { virtual void Allocate(Int_t nrow, Int_t ncol,Int_t ntime); virtual void Reset(); - virtual Int_t GetNrow() const { return fNrow; }; - virtual Int_t GetNcol() const { return fNcol; }; - virtual Int_t GetNtime() const { return fNtime; }; + virtual Int_t GetNrow() const { return fNrow; }; + virtual Int_t GetNcol() const { return fNcol; }; + virtual Int_t GetNtime() const { return fNtime; }; Int_t GetIndex(Int_t row, Int_t col, Int_t time) const; Int_t GetIndexUnchecked(Int_t row, Int_t col, Int_t time) const - { return time * fNrow*fNcol + GetIdx1Unchecked(row,col); }; - Int_t GetBufType() const { return fBufType; }; - virtual Int_t GetNelems() const { return fNelems; }; + { return time * fNrow*fNcol + + GetIdx1Unchecked(row,col); }; + Int_t GetBufType() const { return fBufType; }; + virtual Int_t GetNelems() const { return fNelems; }; + + virtual Bool_t HasData() const { return fNtime ? 1 : 0; }; protected: diff --git a/TRD/AliTRDdataArrayS.cxx b/TRD/AliTRDdataArrayS.cxx new file mode 100644 index 00000000000..e84364258bd --- /dev/null +++ b/TRD/AliTRDdataArrayS.cxx @@ -0,0 +1,682 @@ +/************************************************************************** + * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id: AliTRDdataArrayS.cxx,v 1.17 2006/08/28 14:37:05 cblume Exp $ */ + +/////////////////////////////////////////////////////////////////////////////// +// // +// General container for integer data of a TRD detector segment. // +// Adapted from AliDigits (origin: M.Ivanov). // +// // +/////////////////////////////////////////////////////////////////////////////// + +#include "AliLog.h" + +#include "AliTRDdataArrayS.h" +#include "AliTRDarrayI.h" +#include "AliTRDarrayS.h" + +ClassImp(AliTRDdataArrayS) + +//_____________________________________________________________________________ +AliTRDdataArrayS::AliTRDdataArrayS() + :AliTRDdataArray() + ,fElements(0) + ,fThreshold(0) +{ + // + // Default constructor + // + +} + +//_____________________________________________________________________________ +AliTRDdataArrayS::AliTRDdataArrayS(Int_t nrow, Int_t ncol, Int_t ntime) + :AliTRDdataArray(nrow,ncol,ntime) + ,fElements(0) + ,fThreshold(0) +{ + // + // Creates a AliTRDdataArrayS with the dimensions , , and . + // The row- and column dimensions are compressible. + // + + Allocate(nrow,ncol,ntime); + +} + +//_____________________________________________________________________________ +AliTRDdataArrayS::AliTRDdataArrayS(const AliTRDdataArrayS &a) + :AliTRDdataArray(a) + ,fElements(a.fElements) + ,fThreshold(a.fThreshold) +{ + // + // AliTRDdataArrayS copy constructor + // + +} + +//_____________________________________________________________________________ +AliTRDdataArrayS::~AliTRDdataArrayS() +{ + // + // Destructor + // + + if (fElements) { + delete fElements; + fElements = 0; + } + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::Allocate(Int_t nrow, Int_t ncol, Int_t ntime) +{ + // + // Allocates memory for a AliTRDdataArrayS with the dimensions + // , , and . + // The row- and column dimensions are compressible. + // + + if (fNelems < 0) { + AliTRDdataArray::Allocate(nrow,ncol,ntime); + } + + if (fElements) { + delete fElements; + } + + fElements = new AliTRDarrayS(); + fElements->Set(fNelems); + fElements->Reset(); + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::Copy(TObject &a) const +{ + // + // Copy function + // + + fElements->Copy(*((AliTRDdataArrayS &) a).fElements); + + ((AliTRDdataArrayS &) a).fThreshold = fThreshold; + + AliTRDdataArray::Copy(a); + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::Reset() +{ + // + // Reset the array (old content gets deleted) + // + + if (fElements) { + delete fElements; + } + + + fElements = new AliTRDarrayS(); + fElements->Set(0); + + AliTRDdataArray::Reset(); + + +} + +//_____________________________________________________________________________ +Int_t AliTRDdataArrayS::GetSize() const +{ + // + // Returns the size of the complete object + // + + Int_t size = sizeof(this); + + if (fIndex) size += sizeof(fIndex) + + fIndex->GetSize() * sizeof(Int_t); + if (fElements) size += sizeof(fElements) + + fElements->GetSize() * sizeof(Short_t); + + return size; + +} + +//_____________________________________________________________________________ +Int_t AliTRDdataArrayS::GetDataSize() const +{ + // + // Returns the size of only the data part + // + + if (fElements == 0) + return 0; + else + return sizeof(fElements) + fElements->GetSize() * sizeof(Short_t); + +} + +//_____________________________________________________________________________ +Int_t AliTRDdataArrayS::GetOverThreshold(Short_t threshold) +{ + // + // Returns the number of entries over threshold + // + + if ((fElements == 0) || (fElements->GetSize() <= 0)) + return 0; + + Int_t over = 0; + + for (Bool_t cont = First(); cont == kTRUE; cont = Next()) { + if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue; + if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue; + if (fElements->At(fCurrentIndex) > threshold) over++; + } + + return over; + +} + +//_____________________________________________________________________________ +Short_t AliTRDdataArrayS::GetData(Int_t row, Int_t col, Int_t time) const +{ + // + // Returns the data value at a given position of the array + // + + if ((row >= 0) && (col >= 0) && (time >= 0)) { + Int_t idx1 = GetIdx1(row,col); + if ((idx1 >= 0) && (time < fNdim2)) { + if (fBufType == 0) return GetDataFast(idx1,time); + if (fBufType == 1) return GetData1(idx1,time); + } + else { + if (idx1 >= 0) { + AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)" + ,time,fNdim2,this)); + } + } + } + + return -1; + +} + +//_____________________________________________________________________________ +Short_t AliTRDdataArrayS::GetDataFast(Int_t idx1, Int_t idx2) const +{ + // + // Returns the data value at a given position of the array + // No boundary checking + // + + return fElements->At(fIndex->At(idx2)+idx1); + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::Compress(Int_t bufferType, Short_t threshold) +{ + // + // Compresses the buffer + // + + fThreshold = threshold; + Compress(bufferType); + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::Compress(Int_t bufferType) +{ + // + // Compresses the buffer + // + + if (fBufType < 0) { + AliError("Buffer does not exist"); + return; + } + if (fBufType == bufferType) { + return; + } + if (fBufType > 0) { + Expand(); + } + if (fBufType !=0) { + AliError("Buffer does not exist"); + return; + } + + // Compress a buffer of type 1 + if (bufferType == 1) { + Compress1(); + } + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::Expand() +{ + // + // Expands the compressed buffer + // + + if (fBufType < 0) { + AliError("Buffer does not exist"); + return; + } + if (fBufType == 0) { + return; + } + + // Expand a buffer of type 1 + if (fBufType == 1) Expand1(); + + fBufType = 0; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDdataArrayS::First() +{ + // + // Returns the position of the first valid data value + // + + if (fBufType == 0) return First0(); + if (fBufType == 1) return First1(); + return kFALSE; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDdataArrayS::Next() +{ + // + // Returns the position of the next valid data value + // + + if (fBufType == 0) return Next0(); + if (fBufType == 1) return Next1(); + return kFALSE; + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::Expand1() +{ + // + // Expands a buffer of type 1 + // + + Int_t i, k; + + fNelems = fNdim1 * fNdim2; + + Short_t *buf = new Short_t[fNelems]; + memset(buf,0,fNelems*sizeof(Short_t)); + + fIndex->Set(fNdim2); + + for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k; + + Int_t idx1 = 0; + Int_t idx2 = 0; + Int_t n = fElements->fN; + + for (i = 0; i < n; i++){ + + // Negative sign counts the unwritten values (under threshold) + if ((*fElements)[i] < 0) { + idx1 -= (*fElements)[i]; + } + else { + buf[(*fIndex)[idx2] + idx1] = (*fElements)[i]; + idx1++; + } + if (idx1 == fNdim1) { + idx1 = 0; + idx2++; + } + else { + if (idx1 > fNdim1){ + Reset(); + return; + } + } + } + + fElements->Adopt(fNelems,buf); + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::Compress1() +{ + // + // Compress a buffer of type 1 + // + + AliTRDarrayS *buf = new AliTRDarrayS(); + buf->Set(fNelems); + AliTRDarrayI *index = new AliTRDarrayI(); + index->Set(fNdim2); + + Int_t icurrent = -1; + Int_t izero; + for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){ + + // Set the idx2 pointer + (*index)[idx2] = icurrent + 1; + + // Reset the zero counter + izero = 0; + + for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){ + // If below threshold + if (GetDataFast(idx1,idx2) <= fThreshold) { + izero++; + } + else { + if (izero > 0) { + // If we have currently izero counts under threshold + icurrent++; + if (icurrent >= buf->fN) buf->Expand(icurrent*2); + // Store the number of entries below zero + (*buf)[icurrent] = -izero; + izero = 0; + } + icurrent++; + if (icurrent >= buf->fN) buf->Expand(icurrent*2); + (*buf)[icurrent] = GetDataFast(idx1,idx2); + } // If signal larger than threshold + } // End of loop over idx1 + + if (izero > 0) { + icurrent++; + if (icurrent >= buf->fN) buf->Expand(icurrent*2); + // Store the number of entries below zero + (*buf)[icurrent] = -izero; + } + + } + + buf->Expand(icurrent+1); + if (fElements) delete fElements; + fElements = buf; + fNelems = fElements->fN; + fBufType = 1; + if (fIndex) delete fIndex; + fIndex = index; + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::Expand2() +{ + // + // Expands a buffer of type 2 + // + + Int_t i, k; + + Short_t *buf = new Short_t[fNelems]; + memset(buf,0,fNelems*sizeof(Short_t)); + + fNelems = fNdim1 * fNdim2; + fIndex->Set(fNdim2); + + for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k; + + Int_t idx1 = 0; + Int_t idx2 = 0; + Int_t n = fElements->fN; + for (i = 0; i < n; i++){ + // Negative sign counts the unwritten values (under threshold) + if ((*fElements)[i] < 0) { + idx1 -= fElements->At(i); + } + else { + buf[(*fIndex)[idx2]+idx1] = fElements->At(i); + idx1++; + } + if (idx1 == fNdim1) { + idx1 = 0; + idx2++; + } + else { + if (idx1 > fNdim1){ + Reset(); + return; + } + } + } + + fElements->Adopt(fNelems,buf); + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::Compress2() +{ + // + // Compress a buffer of type 2 - not implemented! + // + +} + +//_____________________________________________________________________________ +Bool_t AliTRDdataArrayS::First0() +{ + // + // Returns the first entry for a buffer of type 0 + // + + fCurrentIdx1 = -1; + fCurrentIdx2 = -1; + fCurrentIndex = -1; + + Int_t i; + for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++) + if (i == fNelems) return kFALSE; + + fCurrentIdx1 = i % fNdim1; + fCurrentIdx2 = i / fNdim1; + fCurrentIndex = i; + return kTRUE; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDdataArrayS::Next0() +{ + // + // Returns the next entry for a buffer of type 0 + // + + if (fCurrentIndex < 0) return kFALSE; + + Int_t i; + for (i = fCurrentIndex + 1; + ((i < fNelems) && (fElements->At(i) <= fThreshold)); + i++); + if (i >= fNelems) { + fCurrentIndex = -1; + return kFALSE; + } + + fCurrentIdx1 = i % fNdim1; + fCurrentIdx2 = i / fNdim1; + fCurrentIndex = i; + return kTRUE; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDdataArrayS::First1() +{ + // + // Returns the first entry for a buffer of type 1 + // + + fCurrentIdx1 = -1; + fCurrentIdx2 = 0; + fCurrentIndex = -1; + + Int_t i; + for (i = 0; i < fNelems; i++){ + if (fElements->At(i) < 0) { + fCurrentIdx1 -= fElements->At(i); + } + else { + fCurrentIdx1++; + } + if (fCurrentIdx1 >= fNdim1) { + fCurrentIdx2++; + fCurrentIdx1 -= fNdim1; + } + if (fElements->At(i) > fThreshold) break; + } + + fCurrentIndex = i; + if (fCurrentIndex >= 0) return kTRUE; + fCurrentIdx1 = -1; + fCurrentIdx2 = -1; + return kFALSE; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDdataArrayS::Next1() +{ + // + // Returns the next entry for a buffer of type 1 + // + + if (fCurrentIndex < 0) return kFALSE; + + Int_t i; + for (i = fCurrentIndex + 1; i < fNelems; i++){ + if (fElements->At(i) < 0) { + fCurrentIdx1 -= fElements->At(i); + } + else { + fCurrentIdx1++; + } + if (fCurrentIdx1 >= fNdim1) { + fCurrentIdx2++; + fCurrentIdx1 -= fNdim1; + } + if (fElements->At(i) > fThreshold) break; + } + + fCurrentIndex = i; + if ((i >= 0) && (i < fNelems)) return kTRUE; + fCurrentIdx1 = -1; + fCurrentIdx2 = -1; + return kFALSE; + +} + +//_____________________________________________________________________________ +Short_t AliTRDdataArrayS::GetData1(Int_t idx1, Int_t idx2) const +{ + // + // Returns the value at a given position of the array + // + + Int_t i, n2; + + if ((idx2 + 1) >= fNdim2) { + n2 = fNelems; + } + else { + n2 = fIndex->At(idx2 + 1); + } + + // Current idx1 + Int_t curidx1 = 0; + + for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){ + if (fElements->At(i) < 0) { + curidx1 -= fElements->At(i); + } + else { + curidx1++; + } + } + + if ((curidx1 == idx1) && (fElements->At(i) > 0)) { + return fElements->At(i); + } + else { + return 0; + } + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::SetData(Int_t row, Int_t col, Int_t time, Short_t value) +{ + // + // Sets the data value at a given position of the array + // Includes boundary checking + // + + if ((row >= 0) && (col >= 0) && (time >= 0)) { + Int_t idx1 = GetIdx1(row,col); + if ((idx1 >= 0) && (time < fNdim2)) { + SetDataFast(idx1,time,value); + } + else { + if (idx1 >= 0) { + AliError(Form("time %d out of bounds (size: %d, this: 0x%08x)" + ,time,fNdim2,this)); + } + } + } + +} + +//_____________________________________________________________________________ +void AliTRDdataArrayS::SetDataFast(Int_t idx1, Int_t idx2, Short_t value) +{ + // + // Sets the data value at a given position of the array + // No boundary checking + // + + (*fElements)[fIndex->fArray[idx2]+idx1] = value; + +} + +//_____________________________________________________________________________ +AliTRDdataArrayS &AliTRDdataArrayS::operator=(const AliTRDdataArrayS &a) +{ + // + // Assignment operator + // + + if (this != &a) ((AliTRDdataArrayS &) a).Copy(*this); + return *this; + +} diff --git a/TRD/AliTRDdataArrayS.h b/TRD/AliTRDdataArrayS.h new file mode 100644 index 00000000000..af637eac915 --- /dev/null +++ b/TRD/AliTRDdataArrayS.h @@ -0,0 +1,80 @@ +#ifndef ALITRDDATAARRAYS_H +#define ALITRDDATAARRAYS_H + +/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * + * See cxx source for full Copyright notice */ + +/* $Id: AliTRDdataArrayS.h,v Exp $ */ + +#include "AliTRDdataArray.h" + +///////////////////////////////////////////////////////////// +// // +// General container for integer data from TRD detector // +// segments. // +// Adapted from AliDigits, origin M.Ivanov // +// // +///////////////////////////////////////////////////////////// + +class AliTRDarrayS; + +class AliTRDdataArrayS : public AliTRDdataArray { + + public: + + AliTRDdataArrayS(); + AliTRDdataArrayS(Int_t nrow, Int_t ncol, Int_t ntime); + AliTRDdataArrayS(const AliTRDdataArrayS &a); + virtual ~AliTRDdataArrayS(); + AliTRDdataArrayS &operator=(const AliTRDdataArrayS &a); + + virtual void Allocate(Int_t nrow, Int_t ncol, Int_t ntime); + virtual void Copy(TObject &a) const; + virtual void Compress(Int_t bufferType, Short_t threshold); + virtual void Compress(Int_t bufferType); + virtual void Expand(); + virtual Bool_t First(); + virtual Bool_t Next(); + virtual void Reset(); + + void SetData(Int_t row, Int_t col, Int_t time, Short_t value); + void SetDataUnchecked(Int_t row, Int_t col, Int_t time, Short_t value) + { SetDataFast(GetIdx1Unchecked(row,col),time,value); }; + + virtual void SetThreshold(Short_t threshold) { fThreshold = threshold; }; + + virtual Short_t GetData(Int_t row, Int_t col, Int_t time) const; + Short_t GetDataUnchecked(Int_t row, Int_t col, Int_t time) const + { return GetDataFast(GetIdx1Unchecked(row,col),time); }; + + virtual Short_t GetThreshold() const { return fThreshold; }; + + virtual Int_t GetSize() const; + virtual Int_t GetDataSize() const; + virtual Int_t GetOverThreshold(Short_t threshold); + + protected: + + void SetDataFast(Int_t idx1, Int_t idx2, Short_t value); + Short_t GetDataFast(Int_t idx1, Int_t idx2) const; + + Short_t GetData1(Int_t idx1, Int_t idx2) const; + void Expand1(); + void Compress1(); + void Expand2(); + void Compress2(); + Bool_t First0(); + Bool_t Next0(); + Bool_t First1(); + Bool_t Next1(); + + AliTRDarrayS *fElements; // Buffer of 2 bytes integers for the array content + Short_t fThreshold; // Threshold for zero suppression + + ClassDef(AliTRDdataArrayS,1) // Container for short data of one TRD detector segment + +}; + +#endif + + diff --git a/TRD/AliTRDdigit.cxx b/TRD/AliTRDdigit.cxx index 49d3e42d773..1bb4e0d9b31 100644 --- a/TRD/AliTRDdigit.cxx +++ b/TRD/AliTRDdigit.cxx @@ -27,11 +27,6 @@ ClassImp(AliTRDdigit) -//_____________________________________________________________________________ - - // Marks a raw digit - const UInt_t AliTRDdigit::fgkRawDigit = 0x00000001; - //_____________________________________________________________________________ AliTRDdigit::AliTRDdigit() :AliDigitNew() @@ -46,7 +41,7 @@ AliTRDdigit::AliTRDdigit() } //_____________________________________________________________________________ -AliTRDdigit::AliTRDdigit(Bool_t isRaw, Int_t *digits, Int_t *amp) +AliTRDdigit::AliTRDdigit(Int_t *digits, Int_t *amp) :AliDigitNew() ,fRow(0) ,fCol(0) @@ -67,8 +62,6 @@ AliTRDdigit::AliTRDdigit(Bool_t isRaw, Int_t *digits, Int_t *amp) // Store the signal amplitude fAmp = amp[0]; - if (isRaw) SetBit(fgkRawDigit); - } //_____________________________________________________________________________ @@ -79,14 +72,3 @@ AliTRDdigit::~AliTRDdigit() // } - -//_____________________________________________________________________________ -Int_t AliTRDdigit::DecodeAmp() const -{ - // - // Decodes the digit amplitude - // - - return 0; - -} diff --git a/TRD/AliTRDdigit.h b/TRD/AliTRDdigit.h index 0b6fd9b3981..87ded130c87 100644 --- a/TRD/AliTRDdigit.h +++ b/TRD/AliTRDdigit.h @@ -19,31 +19,22 @@ class AliTRDdigit : public AliDigitNew { public: AliTRDdigit(); - AliTRDdigit(Bool_t isRaw, Int_t *digits, Int_t *amp); + AliTRDdigit(Int_t *digits, Int_t *amp); virtual ~AliTRDdigit(); - static UInt_t RawDigit() { return fgkRawDigit; }; - - Int_t GetAmp() const { if (TestBit(fgkRawDigit)) - return DecodeAmp(); - else - return fAmp; }; Int_t GetDetector() const { return fId; }; + Int_t GetRow() const { return fRow; }; Int_t GetCol() const { return fCol; }; Int_t GetTime() const { return fTime; }; - virtual Int_t DecodeAmp() const; - protected: - static const UInt_t fgkRawDigit; // Marks a raw digit - UShort_t fRow; // Pad row number UShort_t fCol; // Pad col number UShort_t fTime; // Time bucket - ClassDef(AliTRDdigit,2) // Digit for the TRD + ClassDef(AliTRDdigit,3) // Digit for the TRD }; diff --git a/TRD/AliTRDdigitizer.cxx b/TRD/AliTRDdigitizer.cxx index e3dac8b2706..9e697542ef7 100644 --- a/TRD/AliTRDdigitizer.cxx +++ b/TRD/AliTRDdigitizer.cxx @@ -15,29 +15,25 @@ /* $Id$ */ -/////////////////////////////////////////////////////////////////////////////// -// // -// Creates and handles digits from TRD hits // -// Authors: C. Blume (blume@ikf.uni-frankfurt.de) // -// C. Lippmann // -// B. Vulpescu // -// // -// The following effects are included: // -// - Diffusion // -// - ExB effects // -// - Gas gain including fluctuations // -// - Pad-response (simple Gaussian approximation) // -// - Time-response // -// - Electronics noise // -// - Electronics gain // -// - Digitization // -// The corresponding parameter can be adjusted via the various // -// Set-functions. If these parameters are not explicitly set, default // -// values are used (see Init-function). // -// // -/////////////////////////////////////////////////////////////////////////////// - -#include +//////////////////////////////////////////////////////////////////////////// +// // +// Creates and handles digits from TRD hits // +// // +// Authors: C. Blume (blume@ikf.uni-frankfurt.de) // +// C. Lippmann // +// B. Vulpescu // +// // +// The following effects are included: // +// - Diffusion // +// - ExB effects // +// - Gas gain including fluctuations // +// - Pad-response (simple Gaussian approximation) // +// - Time-response // +// - Electronics noise // +// - Electronics gain // +// - Digitization // +// // +//////////////////////////////////////////////////////////////////////////// #include #include @@ -64,6 +60,7 @@ #include "AliTRDhit.h" #include "AliTRDdigitizer.h" #include "AliTRDdataArrayI.h" +#include "AliTRDdataArrayS.h" #include "AliTRDdataArrayF.h" #include "AliTRDsegmentArray.h" #include "AliTRDdigitsManager.h" @@ -93,7 +90,6 @@ AliTRDdigitizer::AliTRDdigitizer() ,fMasks(0) ,fCompress(kTRUE) ,fSDigits(kFALSE) - ,fSDigitsScale(0.0) ,fMergeSignalOnly(kFALSE) ,fDiffLastVdrift(0) ,fDiffusionT(0.0) @@ -128,7 +124,6 @@ AliTRDdigitizer::AliTRDdigitizer(const Text_t *name, const Text_t *title) ,fMasks(0) ,fCompress(kTRUE) ,fSDigits(kFALSE) - ,fSDigitsScale(0.0) ,fMergeSignalOnly(kFALSE) ,fDiffLastVdrift(0) ,fDiffusionT(0.0) @@ -164,7 +159,6 @@ AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager ,fMasks(0) ,fCompress(kTRUE) ,fSDigits(kFALSE) - ,fSDigitsScale(0.0) ,fMergeSignalOnly(kFALSE) ,fDiffLastVdrift(0) ,fDiffusionT(0.0) @@ -199,7 +193,6 @@ AliTRDdigitizer::AliTRDdigitizer(AliRunDigitizer *manager) ,fMasks(0) ,fCompress(kTRUE) ,fSDigits(kFALSE) - ,fSDigitsScale(0.0) ,fMergeSignalOnly(kFALSE) ,fDiffLastVdrift(0) ,fDiffusionT(0.0) @@ -239,7 +232,6 @@ Bool_t AliTRDdigitizer::Init() fMasks = 0; fCompress = kTRUE; fSDigits = kFALSE; - fSDigitsScale = 100.0; fMergeSignalOnly = kFALSE; fTimeLastVdrift = -1; @@ -271,7 +263,6 @@ AliTRDdigitizer::AliTRDdigitizer(const AliTRDdigitizer &d) ,fMasks(0) ,fCompress(d.fCompress) ,fSDigits(d.fSDigits) - ,fSDigitsScale(d.fSDigitsScale) ,fMergeSignalOnly(d.fMergeSignalOnly) ,fDiffLastVdrift(-1) ,fDiffusionT(0.0) @@ -353,7 +344,9 @@ AliTRDdigitizer &AliTRDdigitizer::operator=(const AliTRDdigitizer &d) // Assignment operator // - if (this != &d) ((AliTRDdigitizer &) d).Copy(*this); + if (this != &d) { + ((AliTRDdigitizer &) d).Copy(*this); + } return *this; @@ -377,7 +370,6 @@ void AliTRDdigitizer::Copy(TObject &d) const ((AliTRDdigitizer &) d).fMasks = 0; ((AliTRDdigitizer &) d).fCompress = fCompress; ((AliTRDdigitizer &) d).fSDigits = fSDigits; - ((AliTRDdigitizer &) d).fSDigitsScale = fSDigitsScale; ((AliTRDdigitizer &) d).fMergeSignalOnly = fMergeSignalOnly; AliTRDdigitizer& target = (AliTRDdigitizer &) d; @@ -414,7 +406,7 @@ void AliTRDdigitizer::Exec(Option_t *option) } // The AliRoot file is already connected by the manager - AliRunLoader *inrl; + AliRunLoader *inrl = 0x0; if (gAlice) { AliDebug(1,"AliRun object found on file."); @@ -673,7 +665,9 @@ Bool_t AliTRDdigitizer::InitDetector() fGeo = new AliTRDgeometry(); // Create a digits manager - delete fDigitsManager; + if (fDigitsManager) { + delete fDigitsManager; + } fDigitsManager = new AliTRDdigitsManager(); fDigitsManager->SetSDigits(fSDigits); fDigitsManager->CreateArrays(); @@ -702,6 +696,28 @@ Bool_t AliTRDdigitizer::MakeBranch(TTree *tree) const } +//_____________________________________________________________________________ +void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man) +{ + // + // Add a digits manager for s-digits to the input list. + // + + fSDigitsManagerList->Add(man); + +} + +//_____________________________________________________________________________ +void AliTRDdigitizer::DeleteSDigitsManager() +{ + // + // Removes digits manager from the input list. + // + + fSDigitsManagerList->Delete(); + +} + //_____________________________________________________________________________ Bool_t AliTRDdigitizer::MakeDigits() { @@ -709,20 +725,193 @@ Bool_t AliTRDdigitizer::MakeDigits() // Creates digits. // - /////////////////////////////////////////////////////////////// - // Parameter - /////////////////////////////////////////////////////////////// + AliDebug(1,"Start creating digits"); - // Converts number of electrons to fC - const Double_t kEl2fC = 1.602e-19 * 1.0e15; + if (!fGeo) { + AliError("No geometry defined"); + return kFALSE; + } + + AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); + if (!calibration) { + AliFatal("Could not get calibration object"); + return kFALSE; + } + + const Int_t kNdet = AliTRDgeometry::Ndet(); + + Float_t **hits = new Float_t*[kNdet]; + Int_t *nhit = new Int_t[kNdet]; + + AliTRDdataArrayF *signals = 0x0; + + // Sort all hits according to detector number + if (!SortHits(hits,nhit)) { + AliError("Sorting hits failed"); + return kFALSE; + } + + // Loop through all detectors + for (Int_t det = 0; det < kNdet; det++) { + + // Detectors that are switched off, not installed, etc. + if (( calibration->IsChamberInstalled(det)) && + (!calibration->IsChamberMasked(det)) && + ( fGeo->ChamberInGeometry(det)) && + (nhit[det] > 0)) { + + signals = new AliTRDdataArrayF(); + + // Convert the hits of the current detector to detector signals + if (!ConvertHits(det,hits[det],nhit[det],signals)) { + AliError(Form("Conversion of hits failed for detector=%d",det)); + return kFALSE; + } + // Convert the detector signals to digits or s-digits + if (!ConvertSignals(det,signals)) { + AliError(Form("Conversion of signals failed for detector=%d",det)); + return kFALSE; + } + + // Delete the signals array + delete signals; + signals = 0x0; + + } // if: detector status + + } // for: detector + + delete [] hits; + delete [] nhit; + + return kTRUE; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDdigitizer::SortHits(Float_t **hits, Int_t *nhit) +{ + // + // Read all the hits and sorts them according to detector number + // in the output array . + // + + AliDebug(1,"Start sorting hits"); + + const Int_t kNdet = AliTRDgeometry::Ndet(); + // Size of the hit vector + const Int_t kNhit = 6; + + Float_t *xyz = 0; + Int_t nhitTrk = 0; + + Int_t *lhit = new Int_t[kNdet]; + + for (Int_t det = 0; det < kNdet; det++) { + lhit[det] = 0; + nhit[det] = 0; + hits[det] = 0; + } + + AliLoader *gimme = fRunLoader->GetLoader("TRDLoader"); + if (!gimme->TreeH()) { + gimme->LoadHits(); + } + TTree *hitTree = gimme->TreeH(); + if (hitTree == 0x0) { + AliError("Can not get TreeH"); + return kFALSE; + } + fTRD->SetTreeAddress(); + + // Get the number of entries in the hit tree + // (Number of primary particles creating a hit somewhere) + Int_t nTrk = (Int_t) hitTree->GetEntries(); + AliDebug(1,Form("Found %d tracks",nTrk)); + + // Loop through all the tracks in the tree + for (Int_t iTrk = 0; iTrk < nTrk; iTrk++) { + + gAlice->ResetHits(); + hitTree->GetEvent(iTrk); + + if (!fTRD->Hits()) { + AliError(Form("No hits array for track = %d",iTrk)); + continue; + } + + // Number of hits for this track + nhitTrk = fTRD->Hits()->GetEntriesFast(); + + Int_t hitCnt = 0; + // Loop through the TRD hits + AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1); + while (hit) { + + hitCnt++; + + // Don't analyze test hits + if (((Int_t) hit->GetCharge()) != 0) { + + Int_t trk = hit->Track(); + Int_t det = hit->GetDetector(); + Int_t q = hit->GetCharge(); + Float_t x = hit->X(); + Float_t y = hit->Y(); + Float_t z = hit->Z(); + Float_t time = hit->GetTime(); + + if (nhit[det] == lhit[det]) { + // Inititialization of new detector + xyz = new Float_t[kNhit*(nhitTrk+lhit[det])]; + if (hits[det]) { + memcpy(xyz,hits[det],sizeof(Float_t)*kNhit*lhit[det]); + delete [] hits[det]; + } + lhit[det] += nhitTrk; + hits[det] = xyz; + } + else { + xyz = hits[det]; + } + xyz[nhit[det]*kNhit+0] = x; + xyz[nhit[det]*kNhit+1] = y; + xyz[nhit[det]*kNhit+2] = z; + xyz[nhit[det]*kNhit+3] = q; + xyz[nhit[det]*kNhit+4] = trk; + xyz[nhit[det]*kNhit+5] = time; + nhit[det]++; + + } // if: charge != 0 + + hit = (AliTRDhit *) fTRD->NextHit(); + + } // for: hits of one track + + } // for: tracks + + delete [] lhit; + + return kTRUE; + +} - /////////////////////////////////////////////////////////////// +//_____________________________________________________________________________ +Bool_t AliTRDdigitizer::ConvertHits(Int_t det, Float_t *hits, Int_t nhit + , AliTRDdataArrayF *signals) +{ + // + // Converts the detectorwise sorted hits to detector signals + // + + AliDebug(1,Form("Start converting hits for detector=%d (nhits=%d)",det,nhit)); // Number of pads included in the pad response const Int_t kNpad = 3; - // Number of track dictionary arrays - const Int_t kNDict = AliTRDdigitsManager::kNDict; + const Int_t kNdict = AliTRDdigitsManager::kNDict; + // Size of the hit vector + const Int_t kNhit = 6; // Width of the amplification region const Float_t kAmWidth = AliTRDgeometry::AmThick(); @@ -732,807 +921,558 @@ Bool_t AliTRDdigitizer::MakeDigits() const Float_t kDrMin = - 0.5 * kAmWidth; const Float_t kDrMax = kDrWidth + 0.5 * kAmWidth; - Int_t iRow; - Int_t iCol; - Int_t iTime; - Int_t iPad; - Int_t iDict = 0; - Int_t nBytes = 0; - - Int_t totalSizeDigits = 0; - Int_t totalSizeDict0 = 0; - Int_t totalSizeDict1 = 0; - Int_t totalSizeDict2 = 0; - - Int_t timeBinTRFend = 1; + Int_t iPad = 0; + Int_t dict = 0; + Int_t timeBinTRFend = 1; Double_t pos[3]; Double_t loc[3]; Double_t padSignal[kNpad]; Double_t signalOld[kNpad]; - AliTRDdataArrayF *signals = 0; - AliTRDdataArrayI *digits = 0; - AliTRDdataArrayI *dictionary[kNDict]; - - AliTRDpadPlane *padPlane = 0; - - AliTRDCalROC *calVdriftROC = 0; - Float_t calVdriftDetValue = 0.0; - AliTRDCalROC *calT0ROC = 0; - Float_t calT0DetValue = 0.0; - AliTRDCalROC *calGainFactorROC = 0; - Float_t calGainFactorDetValue = 0.0; - - if (!gGeoManager) { - AliFatal("No geometry manager!"); - } - - if (!fGeo) { - AliError("No geometry defined"); - return kFALSE; - } + AliTRDdataArrayI *dictionary[kNdict]; AliTRDSimParam *simParam = AliTRDSimParam::Instance(); - if (!simParam) { - AliFatal("Could not get simulation parameters"); - return kFALSE; - } - AliTRDCommonParam *commonParam = AliTRDCommonParam::Instance(); + AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); + if (!commonParam) { AliFatal("Could not get common parameterss"); return kFALSE; } - - AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); + if (!simParam) { + AliFatal("Could not get simulation parameters"); + return kFALSE; + } if (!calibration) { AliFatal("Could not get calibration object"); return kFALSE; } - AliDebug(1,"Start creating digits"); - - // Create a container for the amplitudes - AliTRDsegmentArray *signalsArray = new AliTRDsegmentArray("AliTRDdataArrayF" - ,AliTRDgeometry::Ndet()); - - AliLoader *gimme = fRunLoader->GetLoader("TRDLoader"); - if (!gimme->TreeH()) { - gimme->LoadHits(); - } - TTree *hitTree = gimme->TreeH(); - if (hitTree == 0x0) { - AliError("Can not get TreeH"); - return kFALSE; - } - fTRD->SetTreeAddress(); + // Get the detector wise calibration objects + AliTRDCalROC *calVdriftROC = 0; + Float_t calVdriftDetValue = 0.0; + const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet(); + AliTRDCalROC *calT0ROC = 0; + Float_t calT0DetValue = 0.0; + const AliTRDCalDet *calT0Det = calibration->GetT0Det(); - // 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",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."); - } - else { - AliDebug(1,"Constant drift velocity in drift cells."); - } if (simParam->TRFOn()) { timeBinTRFend = ((Int_t) (simParam->GetTRFhi() * commonParam->GetSamplingFrequency())) - 1; - AliDebug(1,Form("Sample the TRF up to bin %d",timeBinTRFend)); } - // Get the detector wise calibration objects - const AliTRDCalDet *calVdriftDet = calibration->GetVdriftDet(); - const AliTRDCalDet *calT0Det = calibration->GetT0Det(); - const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet(); - - Int_t detectorOld = -1; - Int_t countHits = 0; - Int_t nTimeTotal = calibration->GetNumberOfTimeBins(); Float_t samplingRate = commonParam->GetSamplingFrequency(); Float_t elAttachProp = simParam->GetElAttachProp() / 100.0; - // Loop through all entries in the tree - for (Int_t iTrack = 0; iTrack < nTrack; iTrack++) { + AliTRDpadPlane *padPlane = fGeo->GetPadPlane(det); + Int_t plane = fGeo->GetPlane(det); + Float_t row0 = padPlane->GetRow0ROC(); + Int_t nRowMax = padPlane->GetNrows(); + Int_t nColMax = padPlane->GetNcols(); + + // Create a new array for the signals + signals->Allocate(nRowMax,nColMax,nTimeTotal); + + // Create a new array for the dictionary + for (dict = 0; dict < kNdict; dict++) { + dictionary[dict] = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,dict); + dictionary[dict]->Allocate(nRowMax,nColMax,nTimeTotal); + } + + // Loop through the hits in this detector + for (Int_t hit = 0; hit < nhit; hit++) { + + pos[0] = hits[hit*kNhit+0]; + pos[1] = hits[hit*kNhit+1]; + pos[2] = hits[hit*kNhit+2]; + Float_t q = hits[hit*kNhit+3]; + Float_t hittime = hits[hit*kNhit+5]; + Int_t track = ((Int_t) hits[hit*kNhit+4]); + + Int_t inDrift = 1; + + // Find the current volume with the geo manager + gGeoManager->SetCurrentPoint(pos); + gGeoManager->FindNode(); + if (strstr(gGeoManager->GetPath(),"/UK")) { + inDrift = 0; + } - gAlice->ResetHits(); - nBytes += hitTree->GetEvent(iTrack); + // Get the calibration objects + calVdriftROC = calibration->GetVdriftROC(det); + calVdriftDetValue = calVdriftDet->GetValue(det); + calT0ROC = calibration->GetT0ROC(det); + calT0DetValue = calT0Det->GetValue(det); + + // Go to the local coordinate system: + // loc[0] - col direction in amplification or driftvolume + // loc[1] - row direction in amplification or driftvolume + // loc[2] - time direction in amplification or driftvolume + gGeoManager->MasterToLocal(pos,loc); + if (inDrift) { + // Relative to middle of amplification region + loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0; + } - // Loop through the TRD hits - Int_t iHit = 0; - AliTRDhit *hit = (AliTRDhit *) fTRD->FirstHit(-1); - while (hit) { - - countHits++; - iHit++; + // The driftlength [cm] (w/o diffusion yet !). + // It is negative if the hit is between pad plane and anode wires. + Double_t driftlength = -1.0 * loc[2]; - Float_t q = hit->GetCharge(); - // Don't analyze test hits - if (((Int_t) q) == 0) { - hit = (AliTRDhit *) fTRD->NextHit(); + // Stupid patch to take care of TR photons that are absorbed + // outside the chamber volume. A real fix would actually need + // a more clever implementation of the TR hit generation + if (q < 0.0) { + if ((loc[1] < padPlane->GetRowEndROC()) || + (loc[1] > padPlane->GetRow0ROC())) { continue; } - - pos[0] = hit->X(); - pos[1] = hit->Y(); - pos[2] = hit->Z(); - Int_t track = hit->Track(); - Int_t detector = hit->GetDetector(); - Float_t hittime = hit->GetTime(); - Int_t plane = fGeo->GetPlane(detector); - Int_t chamber = fGeo->GetChamber(detector); - padPlane = fGeo->GetPadPlane(plane,chamber); - Float_t row0 = padPlane->GetRow0ROC(); - Int_t nRowMax = padPlane->GetNrows(); - Int_t nColMax = padPlane->GetNcols(); - Int_t inDrift = 1; - - // Find the current volume with the geo manager - gGeoManager->SetCurrentPoint(pos); - gGeoManager->FindNode(); - if (strstr(gGeoManager->GetPath(),"/UK")) { - inDrift = 0; + if ((driftlength < kDrMin) || + (driftlength > kDrMax)) { + continue; } + } - if (detector != detectorOld) { + // Get row and col of unsmeared electron to retrieve drift velocity + // The pad row (z-direction) + Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]); + if (rowE < 0) { + continue; + } + Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]); + // The pad column (rphi-direction) + Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset); + Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt); + if (colE < 0) { + continue; + } + Double_t colOffset = padPlane->GetPadColOffset(colE,loc[0]+offsetTilt); - // Compress the old one if enabled - if ((fCompress) && (detectorOld > -1)) { - signals->Compress(1,0); - for (iDict = 0; iDict < kNDict; iDict++) { - dictionary[iDict]->Compress(1,0); - } + // Normalized drift length + Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE); + Double_t absdriftlength = TMath::Abs(driftlength); + if (commonParam->ExBOn()) { + absdriftlength /= TMath::Sqrt(GetLorentzFactor(driftvelocity)); + } + + // Loop over all electrons of this hit + // TR photons produce hits with negative charge + Int_t nEl = ((Int_t) TMath::Abs(q)); + for (Int_t iEl = 0; iEl < nEl; iEl++) { + + // Now the real local coordinate system of the ROC + // column direction: locC + // row direction: locR + // time direction: locT + // locR and locC are identical to the coordinates of the corresponding + // volumina of the drift or amplification region. + // locT is defined relative to the wire plane (i.e. middle of amplification + // region), meaming locT = 0, and is negative for hits coming from the + // drift region. + Double_t locC = loc[0]; + Double_t locR = loc[1]; + Double_t locT = loc[2]; + + // Electron attachment + if (simParam->ElAttachOn()) { + if (gRandom->Rndm() < (absdriftlength * elAttachProp)) { + continue; } - // Get the new container - signals = (AliTRDdataArrayF *) signalsArray->At(detector); - if (signals->GetNtime() == 0) { - // Allocate a new one if not yet existing - signals->Allocate(nRowMax,nColMax,nTimeTotal); + } + + // Apply the diffusion smearing + if (simParam->DiffusionOn()) { + if (!(Diffusion(driftvelocity,absdriftlength,locR,locC,locT))) { + continue; } - else { - // Expand an existing one - if (fCompress) { - signals->Expand(); - } - } - // The same for the dictionary - for (iDict = 0; iDict < kNDict; iDict++) { - dictionary[iDict] = fDigitsManager->GetDictionary(detector,iDict); - if (dictionary[iDict]->GetNtime() == 0) { - dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal); - } - else { - if (fCompress) dictionary[iDict]->Expand(); - } - } - - // Get the calibration objects - calVdriftROC = calibration->GetVdriftROC(detector); - calVdriftDetValue = calVdriftDet->GetValue(detector); - calT0ROC = calibration->GetT0ROC(detector); - calT0DetValue = calT0Det->GetValue(detector); - - detectorOld = detector; - } - // Go to the local coordinate system: - // loc[0] - col direction in amplification or driftvolume - // loc[1] - row direction in amplification or driftvolume - // loc[2] - time direction in amplification or driftvolume - gGeoManager->MasterToLocal(pos,loc); - if (inDrift) { - // Relative to middle of amplification region - loc[2] = loc[2] - kDrWidth/2.0 - kAmWidth/2.0; - } - - // The driftlength [cm] (w/o diffusion yet !). - // It is negative if the hit is between pad plane and anode wires. - Double_t driftlength = -1.0 * loc[2]; - - // Stupid patch to take care of TR photons that are absorbed - // outside the chamber volume. A real fix would actually need - // a more clever implementation of the TR hit generation - if (q < 0.0) { - if ((loc[1] < padPlane->GetRowEndROC()) || - (loc[1] > padPlane->GetRow0ROC())) { - hit = (AliTRDhit *) fTRD->NextHit(); + // Apply E x B effects (depends on drift direction) + if (commonParam->ExBOn()) { + if (!(ExB(driftvelocity,driftlength,locC))) { continue; } - if ((driftlength < kDrMin) || - (driftlength > kDrMax)) { - hit = (AliTRDhit *) fTRD->NextHit(); - continue; - } } - // Get row and col of unsmeared electron to retrieve drift velocity + // The electron position after diffusion and ExB in pad coordinates. // The pad row (z-direction) - Int_t rowE = padPlane->GetPadRowNumberROC(loc[1]); - if (rowE < 0) { - hit = (AliTRDhit *) fTRD->NextHit(); - continue; - } - Double_t rowOffset = padPlane->GetPadRowOffsetROC(rowE,loc[1]); + rowE = padPlane->GetPadRowNumberROC(locR); + if (rowE < 0) continue; + rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR); // The pad column (rphi-direction) - Double_t offsetTilt = padPlane->GetTiltOffset(rowOffset); - Int_t colE = padPlane->GetPadColNumber(loc[0]+offsetTilt); - if (colE < 0) { - hit = (AliTRDhit *) fTRD->NextHit(); - continue; + offsetTilt = padPlane->GetTiltOffset(rowOffset); + colE = padPlane->GetPadColNumber(locC+offsetTilt); + if (colE < 0) continue; + colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt); + + // Also re-retrieve drift velocity because col and row may have changed + driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE); + Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE); + + // Convert the position to drift time [mus], using either constant drift velocity or + // time structure of drift cells (non-isochronity, GARFIELD calculation). + // Also add absolute time of hits to take pile-up events into account properly + Double_t drifttime; + if (simParam->TimeStructOn()) { + // Get z-position with respect to anode wire + Double_t zz = row0 - locR + simParam->GetAnodeWireOffset(); + zz -= ((Int_t)(2 * zz)) / 2.0; + if (zz > 0.25) { + zz = 0.5 - zz; + } + // Use drift time map (GARFIELD) + drifttime = TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz) + + hittime; + } + else { + // Use constant drift velocity + drifttime = -1.0 * locT / driftvelocity + + hittime; + } + + // Apply the gas gain including fluctuations + Double_t ggRndm = 0.0; + do { + ggRndm = gRandom->Rndm(); + } while (ggRndm <= 0); + Int_t signal = (Int_t) (-(simParam->GetGasGain()) * TMath::Log(ggRndm)); + + // Apply the pad response + if (simParam->PRFOn()) { + // The distance of the electron to the center of the pad + // in units of pad width + Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE)) + / padPlane->GetColSize(colE); + // This is a fixed parametrization, i.e. not dependent on + // calibration values ! + if (!(calibration->PadResponse(signal,dist,plane,padSignal))) continue; } - Double_t colOffset = padPlane->GetPadColOffset(colE,loc[0]+offsetTilt); - - Float_t driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE); - - // Normalized drift length - Double_t absdriftlength = TMath::Abs(driftlength); - if (commonParam->ExBOn()) { - absdriftlength /= TMath::Sqrt(GetLorentzFactor(driftvelocity)); + else { + padSignal[0] = 0.0; + padSignal[1] = signal; + padSignal[2] = 0.0; } - // Loop over all electrons of this hit - // TR photons produce hits with negative charge - Int_t nEl = ((Int_t) TMath::Abs(q)); - for (Int_t iEl = 0; iEl < nEl; iEl++) { - - // Now the real local coordinate system of the ROC - // column direction: locC - // row direction: locR - // time direction: locT - // locR and locC are identical to the coordinates of the corresponding - // volumina of the drift or amplification region. - // locT is defined relative to the wire plane (i.e. middle of amplification - // region), meaming locT = 0, and is negative for hits coming from the - // drift region. - Double_t locC = loc[0]; - Double_t locR = loc[1]; - Double_t locT = loc[2]; - - // Electron attachment - if (simParam->ElAttachOn()) { - if (gRandom->Rndm() < (absdriftlength * elAttachProp)) { - continue; - } - } + // The time bin (always positive), with t0 distortion + Double_t timeBinIdeal = drifttime * samplingRate + t0; + // Protection + if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) { + timeBinIdeal = 2 * nTimeTotal; + } + Int_t timeBinTruncated = ((Int_t) timeBinIdeal); + // The distance of the position to the middle of the timebin + Double_t timeOffset = ((Float_t) timeBinTruncated + + 0.5 - timeBinIdeal) / samplingRate; - // Apply the diffusion smearing - if (simParam->DiffusionOn()) { - if (!(Diffusion(driftvelocity,absdriftlength,locR,locC,locT))) { - continue; - } + // Sample the time response inside the drift region + // + additional time bins before and after. + // The sampling is done always in the middle of the time bin + for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0) + ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal) + ;iTimeBin++) { + + // Apply the time response + Double_t timeResponse = 1.0; + Double_t crossTalk = 0.0; + Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset; + if (simParam->TRFOn()) { + timeResponse = simParam->TimeResponse(time); } - - // Apply E x B effects (depends on drift direction) - if (commonParam->ExBOn()) { - if (!(ExB(driftvelocity,driftlength,locC))) { - continue; - } + if (simParam->CTOn()) { + crossTalk = simParam->CrossTalk(time); } - // The electron position after diffusion and ExB in pad coordinates. - // The pad row (z-direction) - rowE = padPlane->GetPadRowNumberROC(locR); - if (rowE < 0) continue; - rowOffset = padPlane->GetPadRowOffsetROC(rowE,locR); - - // The pad column (rphi-direction) - offsetTilt = padPlane->GetTiltOffset(rowOffset); - colE = padPlane->GetPadColNumber(locC+offsetTilt); - if (colE < 0) continue; - colOffset = padPlane->GetPadColOffset(colE,locC+offsetTilt); - - // Also re-retrieve drift velocity because col and row may have changed - driftvelocity = calVdriftDetValue * calVdriftROC->GetValue(colE,rowE); - Float_t t0 = calT0DetValue + calT0ROC->GetValue(colE,rowE); - - // Convert the position to drift time [mus], using either constant drift velocity or - // time structure of drift cells (non-isochronity, GARFIELD calculation). - // Also add absolute time of hits to take pile-up events into account properly - Double_t drifttime; - if (simParam->TimeStructOn()) { - // Get z-position with respect to anode wire - Double_t zz = row0 - locR + simParam->GetAnodeWireOffset(); - zz -= ((Int_t)(2 * zz)) / 2.0; - if (zz > 0.25) { - zz = 0.5 - zz; - } - // Use drift time map (GARFIELD) - drifttime = TimeStruct(driftvelocity,0.5*kAmWidth-1.0*locT,zz) - + hittime; - } - else { - // Use constant drift velocity - drifttime = -1.0 * locT / driftvelocity - + hittime; - } + signalOld[0] = 0.0; + signalOld[1] = 0.0; + signalOld[2] = 0.0; - // Apply the gas gain including fluctuations - Double_t ggRndm = 0.0; - do { - ggRndm = gRandom->Rndm(); - } while (ggRndm <= 0); - Int_t signal = (Int_t) (-(simParam->GetGasGain()) * TMath::Log(ggRndm)); - - // Apply the pad response - if (simParam->PRFOn()) { - // The distance of the electron to the center of the pad - // in units of pad width - Double_t dist = (colOffset - 0.5*padPlane->GetColSize(colE)) - / padPlane->GetColSize(colE); - // This is still the fixed parametrization, i.e. not dependent on - // calibration values !!!! - if (!(calibration->PadResponse(signal,dist,plane,padSignal))) continue; - } - else { - padSignal[0] = 0.0; - padSignal[1] = signal; - padSignal[2] = 0.0; - } + for (iPad = 0; iPad < kNpad; iPad++) { - // The time bin (always positive), with t0 distortion - Double_t timeBinIdeal = drifttime * samplingRate + t0; - // Protection - if (TMath::Abs(timeBinIdeal) > 2*nTimeTotal) { - timeBinIdeal = 2 * nTimeTotal; - } - Int_t timeBinTruncated = (Int_t) timeBinIdeal; - // The distance of the position to the middle of the timebin - Double_t timeOffset = ((Float_t) timeBinTruncated - + 0.5 - timeBinIdeal) / samplingRate; - - // Sample the time response inside the drift region - // + additional time bins before and after. - // The sampling is done always in the middle of the time bin - for (Int_t iTimeBin = TMath::Max(timeBinTruncated,0) - ;iTimeBin < TMath::Min(timeBinTruncated+timeBinTRFend,nTimeTotal) - ;iTimeBin++) { - - // Apply the time response - Double_t timeResponse = 1.0; - Double_t crossTalk = 0.0; - Double_t time = (iTimeBin - timeBinTruncated) / samplingRate + timeOffset; - if (simParam->TRFOn()) { - timeResponse = simParam->TimeResponse(time); - } - if (simParam->CTOn()) { - crossTalk = simParam->CrossTalk(time); - } + Int_t colPos = colE + iPad - 1; + if (colPos < 0) continue; + if (colPos >= nColMax) break; - signalOld[0] = 0.0; - signalOld[1] = 0.0; - signalOld[2] = 0.0; + // Add the signals + signalOld[iPad] = signals->GetDataUnchecked(rowE,colPos,iTimeBin); - for (iPad = 0; iPad < kNpad; iPad++) { - - Int_t colPos = colE + iPad - 1; - if (colPos < 0) continue; - if (colPos >= nColMax) break; - - // Add the signals - Int_t iCurrentTimeBin = iTimeBin; - signalOld[iPad] = signals->GetDataUnchecked(rowE,colPos,iCurrentTimeBin); - if (colPos != colE) { - signalOld[iPad] += padSignal[iPad] * (timeResponse + crossTalk); - } - else { - signalOld[iPad] += padSignal[iPad] * timeResponse; - } - signals->SetDataUnchecked(rowE,colPos,iCurrentTimeBin,signalOld[iPad]); + if (colPos != colE) { + // Cross talk added to non-central pads + signalOld[iPad] += padSignal[iPad] + * (timeResponse + crossTalk); + } + else { + // W/o cross talk at central pad + signalOld[iPad] += padSignal[iPad] + * timeResponse; + } - // Store the track index in the dictionary - // Note: We store index+1 in order to allow the array to be compressed - if (signalOld[iPad] > 0) { - for (iDict = 0; iDict < kNDict; iDict++) { - Int_t oldTrack = dictionary[iDict]->GetDataUnchecked(rowE - ,colPos - ,iCurrentTimeBin); - if (oldTrack == track+1) break; - if (oldTrack == 0) { - dictionary[iDict]->SetDataUnchecked(rowE,colPos,iCurrentTimeBin,track+1); - break; - } + signals->SetDataUnchecked(rowE,colPos,iTimeBin,signalOld[iPad]); + + // Store the track index in the dictionary + // Note: We store index+1 in order to allow the array to be compressed + if (signalOld[iPad] > 0.0) { + for (dict = 0; dict < kNdict; dict++) { + Int_t oldTrack = dictionary[dict]->GetDataUnchecked(rowE + ,colPos + ,iTimeBin); + if (oldTrack == track+1) break; + if (oldTrack == 0) { + dictionary[dict]->SetDataUnchecked(rowE,colPos,iTimeBin,track+1); + break; } } + } - } // Loop: pads + } // Loop: pads - } // Loop: time bins + } // Loop: time bins - } // Loop: electrons of a single hit + } // Loop: electrons of a single hit - hit = (AliTRDhit *) fTRD->NextHit(); + } // Loop: hits - } // Loop: hits of one primary track + AliDebug(2,Form("Finished analyzing %d hits",nhit)); - } // Loop: primary tracks + return kTRUE; - AliDebug(1,Form("Finished analyzing %d hits",countHits)); +} - //____________________________________________________________________ +//_____________________________________________________________________________ +Bool_t AliTRDdigitizer::ConvertSignals(Int_t det, AliTRDdataArrayF *signals) +{ // - // Create (s)digits - //____________________________________________________________________ + // Convert signals to digits // - // The coupling factor - Double_t coupling = simParam->GetPadCoupling() - * simParam->GetTimeCoupling(); - - // The conversion factor - Double_t convert = kEl2fC - * simParam->GetChipGain(); - - // Loop through all chambers to finalize the digits - Int_t iDetBeg = 0; - Int_t iDetEnd = AliTRDgeometry::Ndet(); - for (Int_t iDet = iDetBeg; iDet < iDetEnd; iDet++) { + AliDebug(1,Form("Start converting the signals for detector %d",det)); - Int_t plane = fGeo->GetPlane(iDet); - Int_t sector = fGeo->GetSector(iDet); - Int_t chamber = fGeo->GetChamber(iDet); - Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector); - Int_t nColMax = fGeo->GetColMax(plane); - - Double_t *inADC = new Double_t[nTimeTotal]; - Double_t *outADC = new Double_t[nTimeTotal]; - - // Add a container for the digits of this detector - digits = fDigitsManager->GetDigits(iDet); - // Allocate memory space for the digits buffer - if (digits->GetNtime() == 0) { - digits->Allocate(nRowMax,nColMax,nTimeTotal); - } - - // Get the signal container - signals = (AliTRDdataArrayF *) signalsArray->At(iDet); - if (signals->GetNtime() == 0) { - // Create missing containers - signals->Allocate(nRowMax,nColMax,nTimeTotal); + if (fSDigits) { + // Convert the signal array to s-digits + if (!Signal2SDigits(det,signals)) { + return kFALSE; } - else { - // Expand the container if neccessary - if (fCompress) signals->Expand(); - } - // Create the missing dictionary containers - for (iDict = 0; iDict < kNDict; iDict++) { - dictionary[iDict] = fDigitsManager->GetDictionary(iDet,iDict); - if (dictionary[iDict]->GetNtime() == 0) { - dictionary[iDict]->Allocate(nRowMax,nColMax,nTimeTotal); - } + } + else { + // Convert the signal array to digits + if (!Signal2ADC(det,signals)) { + return kFALSE; } + } - Int_t nDigits = 0; - - // Don't create noise in detectors that are switched off / not installed, etc. - if (( calibration->IsChamberInstalled(iDet)) && - (!calibration->IsChamberMasked(iDet)) && - ( fGeo->ChamberInGeometry(iDet))) { - - // Get the calibration objects - calGainFactorROC = calibration->GetGainFactorROC(iDet); - calGainFactorDetValue = calGainFactorDet->GetValue(iDet); - - // Create the digits for this chamber - for (iRow = 0; iRow < nRowMax; iRow++ ) { - for (iCol = 0; iCol < nColMax; iCol++ ) { - - // Check whether pad is masked - // Bridged pads are not considered yet!!! - if (calibration->IsPadMasked(iDet,iCol,iRow)) { - continue; - } - - // Create summable digits - if (fSDigits) { - - for (iTime = 0; iTime < nTimeTotal; iTime++) { - Float_t signalAmp = signals->GetDataUnchecked(iRow,iCol,iTime); - signalAmp *= fSDigitsScale; - signalAmp = TMath::Min(signalAmp,(Float_t) 1.0e9); - Int_t adc = (Int_t) signalAmp; - if (adc > 0) nDigits++; - digits->SetDataUnchecked(iRow,iCol,iTime,adc); - } + // Compress the arrays + CompressOutputArrays(det); - } - // Create normal digits - else { + return kTRUE; - Float_t padgain = calGainFactorDetValue - * calGainFactorROC->GetValue(iCol,iRow); - if (padgain <= 0) { - AliError(Form("Not a valid gain %f, %d %d %d",padgain,iDet,iCol,iRow)); - } +} - for (iTime = 0; iTime < nTimeTotal; iTime++) { - - Float_t signalAmp = signals->GetDataUnchecked(iRow,iCol,iTime); - - // Pad and time coupling - signalAmp *= coupling; - // Gain factors - signalAmp *= padgain; - - // Add the noise, starting from minus ADC baseline in electrons - Double_t baselineEl = simParam->GetADCbaseline() - * (simParam->GetADCinRange() / simParam->GetADCoutRange()) - / convert; - signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise()) - ,-baselineEl); - // Convert to mV - signalAmp *= convert; - // Add ADC baseline in mV - signalAmp += simParam->GetADCbaseline() - * (simParam->GetADCinRange() / simParam->GetADCoutRange()); - // Convert to ADC counts. Set the overflow-bit fADCoutRange if the - // signal is larger than fADCinRange - Int_t adc = 0; - if (signalAmp >= simParam->GetADCinRange()) { - adc = ((Int_t) simParam->GetADCoutRange()); - } - else { - adc = TMath::Nint(signalAmp * (simParam->GetADCoutRange() - / simParam->GetADCinRange())); - } - - inADC[iTime] = adc; - outADC[iTime] = adc; - - } - - for (iTime = 0; iTime < nTimeTotal; iTime++) { - //if (outADC[iTime] != 0 ) { // Now this is enough because there is ZS in raw simulator - // Reintroduce threshold as a temporary fix for the digits file size problem - if (outADC[iTime] > (simParam->GetADCbaseline() + 3)) { - nDigits++; - digits->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime])); - } - } +//_____________________________________________________________________________ +Bool_t AliTRDdigitizer::Signal2ADC(Int_t det, AliTRDdataArrayF *signals) +{ + // + // Converts the sampled electron signals to ADC values for a given chamber + // - } + AliDebug(1,Form("Start converting signals to ADC values for detector=%d",det)); - } - } - - } + AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); + if (!calibration) { + AliFatal("Could not get calibration object"); + return kFALSE; + } - // Compress the arrays - digits->Compress(1,0); - for (iDict = 0; iDict < kNDict; iDict++) { - dictionary[iDict]->Compress(1,0); - } + AliTRDSimParam *simParam = AliTRDSimParam::Instance(); + if (!simParam) { + AliFatal("Could not get simulation parameters"); + return kFALSE; + } - totalSizeDigits += digits->GetSize(); - totalSizeDict0 += dictionary[0]->GetSize(); - totalSizeDict1 += dictionary[1]->GetSize(); - totalSizeDict2 += dictionary[2]->GetSize(); + // Converts number of electrons to fC + const Double_t kEl2fC = 1.602e-19 * 1.0e15; - if (nDigits > 0) { - Float_t nPixel = nRowMax * nColMax * nTimeTotal; - AliDebug(1,Form("Found %d digits in detector %d (%3.0f)." - ,nDigits,iDet - ,100.0 * ((Float_t) nDigits) / nPixel)); - } + // Coupling factor + Double_t coupling = simParam->GetPadCoupling() + * simParam->GetTimeCoupling(); + // Electronics conversion factor + Double_t convert = kEl2fC + * simParam->GetChipGain(); + // ADC conversion factor + Double_t adcConvert = simParam->GetADCoutRange() + / simParam->GetADCinRange(); + // The electronics baseline in mV + Double_t baseline = simParam->GetADCbaseline() + / adcConvert; + // The electronics baseline in electrons + Double_t baselineEl = baseline + / convert; + + Int_t row = 0; + Int_t col = 0; + Int_t time = 0; + + Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows(); + Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols(); + Int_t nTimeTotal = calibration->GetNumberOfTimeBins(); - if (fCompress) { - signals->Compress(1,0); - } + // The gainfactor calibration objects + const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet(); + AliTRDCalROC *calGainFactorROC = 0; + Float_t calGainFactorDetValue = 0.0; - delete [] inADC; - delete [] outADC; + AliTRDdataArrayS *digits = 0x0; + if (!signals) { + AliError(Form("Signals array for detector %d does not exist\n",det)); + return kFALSE; + } + if (signals->HasData()) { + // Expand the container if neccessary + signals->Expand(); + } + else { + // Create missing containers + signals->Allocate(nRowMax,nColMax,nTimeTotal); } - if (signalsArray) { - delete signalsArray; - signalsArray = 0; + // Get the container for the digits of this detector + if (fDigitsManager->HasSDigits()) { + AliError("Digits manager has s-digits"); + return kFALSE; + } + digits = (AliTRDdataArrayS *) fDigitsManager->GetDigits(det); + // Allocate memory space for the digits buffer + if (!digits->HasData()) { + digits->Allocate(nRowMax,nColMax,nTimeTotal); } - 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)); + // Get the calibration objects + calGainFactorROC = calibration->GetGainFactorROC(det); + calGainFactorDetValue = calGainFactorDet->GetValue(det); - return kTRUE; + // Create the digits for this chamber + for (row = 0; row < nRowMax; row++ ) { + for (col = 0; col < nColMax; col++ ) { -} + // Check whether pad is masked + // Bridged pads are not considered yet!!! + if (calibration->IsPadMasked(det,col,row)) { + continue; + } -//_____________________________________________________________________________ -void AliTRDdigitizer::AddSDigitsManager(AliTRDdigitsManager *man) -{ - // - // Add a digits manager for s-digits to the input list. - // + // The gain factors + Float_t padgain = calGainFactorDetValue + * calGainFactorROC->GetValue(col,row); + if (padgain <= 0) { + AliError(Form("Not a valid gain %f, %d %d %d",padgain,det,col,row)); + } - fSDigitsManagerList->Add(man); + for (time = 0; time < nTimeTotal; time++) { + + // Get the signal amplitude + Float_t signalAmp = signals->GetDataUnchecked(row,col,time); + // Pad and time coupling + signalAmp *= coupling; + // Gain factors + signalAmp *= padgain; + + // Add the noise, starting from minus ADC baseline in electrons + signalAmp = TMath::Max((Double_t) gRandom->Gaus(signalAmp,simParam->GetNoise()) + ,-baselineEl); + + // Convert to mV + signalAmp *= convert; + // Add ADC baseline in mV + signalAmp += baseline; + + // Convert to ADC counts. Set the overflow-bit fADCoutRange if the + // signal is larger than fADCinRange + Short_t adc = 0; + if (signalAmp >= simParam->GetADCinRange()) { + adc = ((Short_t) simParam->GetADCoutRange()); + } + else { + adc = TMath::Nint(signalAmp * adcConvert); + } -} + // Store the amplitude of the digit if above threshold + //if (adc != 0) { + // Use temporarily a threshold to reduce the digits file size + if (adc > (simParam->GetADCbaseline() + 2)) { + digits->SetDataUnchecked(row,col,time,adc); + } -//_____________________________________________________________________________ -void AliTRDdigitizer::DeleteSDigitsManager() -{ - // - // Removes digits manager from the input list. - // + } // for: time + } // for: col + } // for: row - fSDigitsManagerList->Delete(); + return kTRUE; } //_____________________________________________________________________________ -Bool_t AliTRDdigitizer::ConvertSDigits() +Bool_t AliTRDdigitizer::Signal2SDigits(Int_t det, AliTRDdataArrayF *signals) { // - // Converts s-digits to normal digits + // Converts the sampled electron signals to s-digits // - // Number of track dictionary arrays - const Int_t kNDict = AliTRDdigitsManager::kNDict; + AliDebug(1,Form("Start converting signals to s-digits for detector=%d",det)); - // Converts number of electrons to fC - const Double_t kEl2fC = 1.602e-19 * 1.0e15; - - Int_t iDict = 0; - Int_t iRow; - Int_t iCol; - Int_t iTime; - - AliTRDCalROC *calGainFactorROC = 0; - Float_t calGainFactorDetValue = 0.0; - - AliTRDSimParam *simParam = AliTRDSimParam::Instance(); - if (!simParam) { - AliFatal("Could not get simulation parameters"); - return kFALSE; - } - AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); if (!calibration) { AliFatal("Could not get calibration object"); return kFALSE; } - - Double_t sDigitsScale = 1.0 / GetSDigitsScale(); - Double_t noise = simParam->GetNoise(); - Double_t padCoupling = simParam->GetPadCoupling(); - Double_t timeCoupling = simParam->GetTimeCoupling(); - Double_t chipGain = simParam->GetChipGain(); - Double_t coupling = padCoupling * timeCoupling; - Double_t convert = kEl2fC * chipGain; - Double_t adcInRange = simParam->GetADCinRange(); - Double_t adcOutRange = simParam->GetADCoutRange(); - Int_t adcBaseline = simParam->GetADCbaseline(); - Int_t nTimeTotal = calibration->GetNumberOfTimeBins(); - - AliTRDdataArrayI *digitsIn; - AliTRDdataArrayI *digitsOut; - AliTRDdataArrayI *dictionaryIn[kNDict]; - AliTRDdataArrayI *dictionaryOut[kNDict]; - - // Get the detector wise calibration objects - const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet(); - - // Loop through the detectors - for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) { - - Int_t plane = fGeo->GetPlane(iDet); - Int_t sector = fGeo->GetSector(iDet); - Int_t chamber = fGeo->GetChamber(iDet); - Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector); - Int_t nColMax = fGeo->GetColMax(plane); - - Double_t *inADC = new Double_t[nTimeTotal]; - Double_t *outADC = new Double_t[nTimeTotal]; - - digitsIn = fSDigitsManager->GetDigits(iDet); - digitsIn->Expand(); - digitsOut = fDigitsManager->GetDigits(iDet); - digitsOut->Allocate(nRowMax,nColMax,nTimeTotal); - for (iDict = 0; iDict < kNDict; iDict++) { - dictionaryIn[iDict] = fSDigitsManager->GetDictionary(iDet,iDict); - dictionaryIn[iDict]->Expand(); - dictionaryOut[iDict] = fDigitsManager->GetDictionary(iDet,iDict); - dictionaryOut[iDict]->Allocate(nRowMax,nColMax,nTimeTotal); - } - - // Don't create noise in detectors that are switched off / not installed, etc. - if (( calibration->IsChamberInstalled(iDet)) && - (!calibration->IsChamberMasked(iDet)) && - ( fGeo->ChamberInGeometry(iDet))) { - - // Get the calibration objects - calGainFactorROC = calibration->GetGainFactorROC(iDet); - calGainFactorDetValue = calGainFactorDet->GetValue(iDet); - - for (iRow = 0; iRow < nRowMax; iRow++ ) { - for (iCol = 0; iCol < nColMax; iCol++ ) { - - // Check whether pad is masked - // Bridged pads are not considered yet!!! - if (calibration->IsPadMasked(iDet,iCol,iRow)) { - continue; - } - - Float_t padgain = calGainFactorDetValue - * calGainFactorROC->GetValue(iCol,iRow); - if (padgain <= 0) { - AliError(Form("Not a valid gain %f, %d %d %d",padgain,iDet,iCol,iRow)); - } - for (iTime = 0; iTime < nTimeTotal; iTime++) { - - // Scale s-digits to normal digits - Double_t signal = (Double_t) digitsIn->GetDataUnchecked(iRow,iCol,iTime); - signal *= sDigitsScale; - // Pad and time coupling - signal *= coupling; - // Gain factors - signal *= padgain; - // Add the noise, starting from minus ADC baseline in electrons - Double_t baselineEl = adcBaseline * (adcInRange / adcOutRange) / convert; - signal = TMath::Max((Double_t) gRandom->Gaus(signal,noise),-baselineEl); - // Convert to mV - signal *= convert; - // add ADC baseline in mV - signal += adcBaseline * (adcInRange / adcOutRange); - // Convert to ADC counts. Set the overflow-bit adcOutRange if the - // signal is larger than adcInRange - Int_t adc = 0; - if (signal >= adcInRange) { - adc = ((Int_t) adcOutRange); - } - else { - adc = TMath::Nint(signal * (adcOutRange / adcInRange)); - } - inADC[iTime] = adc; - outADC[iTime] = adc; + Int_t row = 0; + Int_t col = 0; + Int_t time = 0; - } + Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows(); + Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols(); + Int_t nTimeTotal = calibration->GetNumberOfTimeBins(); - for (iTime = 0; iTime < nTimeTotal; iTime++) { - // Store the amplitude of the digit if above threshold - //if (outADC[iTime] != 0) { // now this is ok because there is ZS in raw simulation - // Reintroduce the threshold as a temporary fix for the digits file size - if (outADC[iTime] > (adcBaseline + 3)) { - digitsOut->SetDataUnchecked(iRow,iCol,iTime,((Int_t) outADC[iTime])); - // Copy the dictionary - for (iDict = 0; iDict < kNDict; iDict++) { - Int_t track = dictionaryIn[iDict]->GetDataUnchecked(iRow,iCol,iTime); - dictionaryOut[iDict]->SetDataUnchecked(iRow,iCol,iTime,track); - } - } - } + // Get the container for the digits of this detector + if (!fDigitsManager->HasSDigits()) { + AliError("Digits manager has no s-digits"); + return kFALSE; + } + AliTRDdataArrayF *digits = (AliTRDdataArrayF *) fDigitsManager->GetDigits(det); + // Allocate memory space for the digits buffer + if (!digits->HasData()) { + digits->Allocate(nRowMax,nColMax,nTimeTotal); + } - } - } + // Create the sdigits for this chamber + for (row = 0; row < nRowMax; row++ ) { + for (col = 0; col < nColMax; col++ ) { + for (time = 0; time < nTimeTotal; time++) { + digits->SetDataUnchecked(row + ,col + ,time + ,signals->GetDataUnchecked(row,col,time)); + } // for: time + } // for: col + } // for: row - } + return kTRUE; - if (fCompress) { - digitsIn->Compress(1,0); - digitsOut->Compress(1,0); - for (iDict = 0; iDict < kNDict; iDict++) { - dictionaryIn[iDict]->Compress(1,0); - dictionaryOut[iDict]->Compress(1,0); - } - } +} - delete [] inADC; - delete [] outADC; +//_____________________________________________________________________________ +Bool_t AliTRDdigitizer::SDigits2Digits() +{ + // + // Merges the input s-digits and converts them to normal digits + // - } + if (!MergeSDigits()) { + return kFALSE; + } - return kTRUE; + return ConvertSDigits(); } @@ -1564,10 +1504,11 @@ Bool_t AliTRDdigitizer::MergeSDigits() Int_t iDict = 0; Int_t jDict = 0; - AliTRDdataArrayI *digitsA; - AliTRDdataArrayI *digitsB; - AliTRDdataArrayI *dictionaryA[kNDict]; - AliTRDdataArrayI *dictionaryB[kNDict]; + AliTRDdataArrayF *digitsA; + AliTRDdataArrayF *digitsB; + AliTRDdataArrayI *dictionaryA[kNDict]; + AliTRDdataArrayI *dictionaryB[kNDict]; + AliTRDdigitsManager *mergeSDigitsManager = 0x0; // Get the first s-digits fSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->First(); @@ -1577,7 +1518,6 @@ Bool_t AliTRDdigitizer::MergeSDigits() } // Loop through the other sets of s-digits - AliTRDdigitsManager *mergeSDigitsManager; mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(fSDigitsManager); @@ -1598,20 +1538,17 @@ Bool_t AliTRDdigitizer::MergeSDigits() // Loop through the detectors for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) { - Int_t plane = fGeo->GetPlane(iDet); - Int_t sector = fGeo->GetSector(iDet); - Int_t chamber = fGeo->GetChamber(iDet); - Int_t nRowMax = fGeo->GetRowMax(plane,chamber,sector); - Int_t nColMax = fGeo->GetColMax(plane); + Int_t nRowMax = fGeo->GetPadPlane(iDet)->GetNrows(); + Int_t nColMax = fGeo->GetPadPlane(iDet)->GetNcols(); // Loop through the pixels of one detector and add the signals - digitsA = fSDigitsManager->GetDigits(iDet); - digitsB = mergeSDigitsManager->GetDigits(iDet); + digitsA = (AliTRDdataArrayF *) fSDigitsManager->GetDigits(iDet); + digitsB = (AliTRDdataArrayF *) mergeSDigitsManager->GetDigits(iDet); digitsA->Expand(); digitsB->Expand(); for (iDict = 0; iDict < kNDict; iDict++) { - dictionaryA[iDict] = fSDigitsManager->GetDictionary(iDet,iDict); - dictionaryB[iDict] = mergeSDigitsManager->GetDictionary(iDet,iDict); + dictionaryA[iDict] = (AliTRDdataArrayI *) fSDigitsManager->GetDictionary(iDet,iDict); + dictionaryB[iDict] = (AliTRDdataArrayI *) mergeSDigitsManager->GetDictionary(iDet,iDict); dictionaryA[iDict]->Expand(); dictionaryB[iDict]->Expand(); } @@ -1633,8 +1570,8 @@ Bool_t AliTRDdigitizer::MergeSDigits() for (Int_t iTime = 0; iTime < nTimeTotal; iTime++) { // Add the amplitudes of the summable digits - Int_t ampA = digitsA->GetDataUnchecked(iRow,iCol,iTime); - Int_t ampB = digitsB->GetDataUnchecked(iRow,iCol,iTime); + Float_t ampA = digitsA->GetDataUnchecked(iRow,iCol,iTime); + Float_t ampB = digitsB->GetDataUnchecked(iRow,iCol,iTime); ampA += ampB; digitsA->SetDataUnchecked(iRow,iCol,iTime,ampA); @@ -1647,50 +1584,162 @@ Bool_t AliTRDdigitizer::MergeSDigits() if (trackA == 0) { trackA = trackB + fMasks[iMerge]; dictionaryA[iDict]->SetDataUnchecked(iRow,iCol,iTime,trackA); - } - } - } - } + } // if: track A == 0 + } // for: jDict + } // if: fMasks and trackB > 0 + } // for: iDict - } - } - } + } // for: iTime + } // for: iCol + } // for: iRow - } + } // if: doMerge + + mergeSDigitsManager->RemoveDigits(iDet); + mergeSDigitsManager->RemoveDictionaries(iDet); if (fCompress) { digitsA->Compress(1,0); - digitsB->Compress(1,0); for (iDict = 0; iDict < kNDict; iDict++) { dictionaryA[iDict]->Compress(1,0); - dictionaryB[iDict]->Compress(1,0); } } - } + } // for: detectors // The next set of s-digits mergeSDigitsManager = (AliTRDdigitsManager *) fSDigitsManagerList->After(mergeSDigitsManager); + } // while: mergeDigitsManagers + + return kTRUE; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDdigitizer::ConvertSDigits() +{ + // + // Converts s-digits to normal digits + // + + AliTRDdataArrayF *digitsIn = 0x0; + + if (!fSDigitsManager->HasSDigits()) { + AliError("No s-digits in digits manager"); + return kFALSE; } + // Loop through the detectors + for (Int_t det = 0; det < AliTRDgeometry::Ndet(); det++) { + + // Get the merged s-digits (signals) + digitsIn = (AliTRDdataArrayF *) fSDigitsManager->GetDigits(det); + if (!digitsIn->HasData()) { + AliDebug(2,Form("No digits for det=%d",det)); + continue; + } + + // Convert the merged sdigits to digits + if (!Signal2ADC(det,digitsIn)) { + continue; + } + + // Copy the dictionary information to the output array + if (!CopyDictionary(det)) { + continue; + } + + // Delete + fSDigitsManager->RemoveDigits(det); + fSDigitsManager->RemoveDictionaries(det); + + // Compress the arrays + CompressOutputArrays(det); + + } // for: detector numbers + return kTRUE; } //_____________________________________________________________________________ -Bool_t AliTRDdigitizer::SDigits2Digits() +Bool_t AliTRDdigitizer::CopyDictionary(Int_t det) { // - // Merges the input s-digits and converts them to normal digits + // Copies the dictionary information from the s-digits arrays + // to the output arrays // - if (!MergeSDigits()) { + AliTRDcalibDB *calibration = AliTRDcalibDB::Instance(); + if (!calibration) { + AliFatal("Could not get calibration object"); return kFALSE; } - return ConvertSDigits(); + AliDebug(1,Form("Start copying dictionaries for detector=%d",det)); + + const Int_t kNDict = AliTRDdigitsManager::kNDict; + AliTRDdataArrayI *dictionaryIn[kNDict]; + AliTRDdataArrayI *dictionaryOut[kNDict]; + + Int_t nRowMax = fGeo->GetPadPlane(det)->GetNrows(); + Int_t nColMax = fGeo->GetPadPlane(det)->GetNcols(); + Int_t nTimeTotal = calibration->GetNumberOfTimeBins(); + + Int_t row = 0; + Int_t col = 0; + Int_t time = 0; + Int_t dict = 0; + + for (dict = 0; dict < kNDict; dict++) { + + dictionaryIn[dict] = (AliTRDdataArrayI *) fSDigitsManager->GetDictionary(det,dict); + dictionaryIn[dict]->Expand(); + dictionaryOut[dict] = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,dict); + dictionaryOut[dict]->Allocate(nRowMax,nColMax,nTimeTotal); + + for (row = 0; row < nRowMax; row++) { + for (col = 0; col < nColMax; col++) { + for (time = 0; time < nTimeTotal; time++) { + + Int_t track = dictionaryIn[dict]->GetDataUnchecked(row,col,time); + dictionaryOut[dict]->SetDataUnchecked(row,col,time,track); + + } // for: time + } // for: col + } // for: row + + } // for: dictionaries + + return kTRUE; + +} + +//_____________________________________________________________________________ +void AliTRDdigitizer::CompressOutputArrays(Int_t det) +{ + // + // Compress the output arrays + // + + const Int_t kNDict = AliTRDdigitsManager::kNDict; + + AliTRDdataArrayS *digits = 0x0; + AliTRDdataArrayI *dictionary = 0x0; + + if (fCompress) { + + digits = (AliTRDdataArrayS *) fDigitsManager->GetDigits(det); + digits->Compress(1,0); + for (Int_t dict = 0; dict < kNDict; dict++) { + dictionary = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,dict); + dictionary->Compress(1,0); + + } + + } } diff --git a/TRD/AliTRDdigitizer.h b/TRD/AliTRDdigitizer.h index 51c2d23d978..7d7b534fe44 100644 --- a/TRD/AliTRDdigitizer.h +++ b/TRD/AliTRDdigitizer.h @@ -23,6 +23,8 @@ class AliTRD; class AliTRDdigitsManager; class AliTRDgeometry; class AliTRDfeeParam; +class AliTRDdataArrayF; +class AliTRDsegmentArray; class AliTRDdigitizer : public AliDigitizer { @@ -33,51 +35,62 @@ class AliTRDdigitizer : public AliDigitizer { AliTRDdigitizer(AliRunDigitizer *manager, const Text_t *name, const Text_t *title); AliTRDdigitizer(AliRunDigitizer *manager); AliTRDdigitizer(const AliTRDdigitizer &d); - virtual ~AliTRDdigitizer(); - AliTRDdigitizer &operator=(const AliTRDdigitizer &d); - - virtual void Copy(TObject &d) const; - virtual Bool_t InitDetector(); - void InitOutput(Int_t iEvent); - virtual void Exec(Option_t *option = 0); - virtual Bool_t Open(const Char_t *file, Int_t nEvent = 0); - virtual Bool_t Open(AliRunLoader *runLoader, Int_t nEvent = 0); - virtual Bool_t MakeBranch(TTree *tree) const; - virtual Bool_t MakeDigits(); - - virtual void AddSDigitsManager(AliTRDdigitsManager *manager); - virtual void DeleteSDigitsManager(); - virtual Bool_t ConvertSDigits(); - virtual Bool_t MergeSDigits(); - virtual Bool_t SDigits2Digits(); - virtual Bool_t WriteDigits() const; - - virtual void SetCompress(Int_t c = 1) { fCompress = c; } - virtual void SetSDigits(Int_t v = 1) { fSDigits = v; } - virtual void SetSDigitsScale(Float_t s) { fSDigitsScale = s; } - virtual void SetEvent(Int_t v = 0) { fEvent = v; } - virtual void SetManager(AliTRDdigitsManager *man) { fDigitsManager = man; } - virtual void SetGeometry(AliTRDgeometry *geo) { fGeo = geo; } - virtual void SetMergeSignalOnly(Bool_t m = kTRUE) { fMergeSignalOnly = m; } - - Bool_t GetCompress() const { return fCompress; } - Bool_t GetSDigits() const { return fSDigits; } - Float_t GetSDigitsScale() const { return fSDigitsScale; } - Float_t GetDiffusionT(Float_t vdrift); - Float_t GetDiffusionL(Float_t vdrift); - Float_t GetLorentzFactor(Float_t vdrift); - - virtual Double_t TimeStruct(Float_t vdrift, Double_t time, Double_t z); - virtual Int_t Diffusion(Float_t vdrift, Double_t absdriftlength - , Double_t &lRow, Double_t &lCol, Double_t &lTime); - virtual Int_t ExB(Float_t vdrift, Double_t driftlength, Double_t &lRow); - - AliTRDdigitsManager *Digits() const { return fDigitsManager; } + virtual ~AliTRDdigitizer(); + AliTRDdigitizer &operator=(const AliTRDdigitizer &d); + + virtual void Copy(TObject &d) const; + Bool_t InitDetector(); + void InitOutput(Int_t iEvent); + virtual void Exec(Option_t *option = 0); + + virtual Bool_t Open(const Char_t *file, Int_t nEvent = 0); + virtual Bool_t Open(AliRunLoader *runLoader, Int_t nEvent = 0); + virtual Bool_t MakeBranch(TTree *tree) const; + virtual Bool_t WriteDigits() const; + + virtual void AddSDigitsManager(AliTRDdigitsManager *manager); + virtual void DeleteSDigitsManager(); + + virtual Bool_t MakeDigits(); + + Bool_t SortHits(Float_t **hits, Int_t *nhit); + Bool_t ConvertHits(Int_t det, Float_t *hits, Int_t nhit, AliTRDdataArrayF *signals); + Bool_t ConvertSignals(Int_t det, AliTRDdataArrayF *signals); + + Bool_t SDigits2Digits(); + Bool_t MergeSDigits(); + Bool_t ConvertSDigits(); + + Bool_t Signal2ADC(Int_t det, AliTRDdataArrayF *signals); + Bool_t Signal2SDigits(Int_t det, AliTRDdataArrayF *signals); + Bool_t CopyDictionary(Int_t det); + void CompressOutputArrays(Int_t det); + + void SetCompress(Int_t c = 1) { fCompress = c; } + void SetSDigits(Int_t v = 1) { fSDigits = v; } + void SetEvent(Int_t v = 0) { fEvent = v; } + void SetManager(AliTRDdigitsManager *man) { fDigitsManager = man; } + void SetGeometry(AliTRDgeometry *geo) { fGeo = geo; } + void SetMergeSignalOnly(Bool_t m = kTRUE) { fMergeSignalOnly = m; } + + AliTRDdigitsManager *Digits() const { return fDigitsManager; } + + Bool_t GetCompress() const { return fCompress; } + Bool_t GetSDigits() const { return fSDigits; } + Float_t GetDiffusionT(Float_t vdrift); + Float_t GetDiffusionL(Float_t vdrift); + Float_t GetLorentzFactor(Float_t vdrift); + + Double_t TimeStruct(Float_t vdrift, Double_t time, Double_t z); + Int_t Diffusion(Float_t vdrift, Double_t absdriftlength + , Double_t &lRow, Double_t &lCol, Double_t &lTime); + Int_t ExB(Float_t vdrift, Double_t driftlength, Double_t &lRow); protected: - void SampleTimeStruct(Float_t vdrift); - void RecalcDiffusion(Float_t vdrift); + virtual Bool_t Init(); + void SampleTimeStruct(Float_t vdrift); + void RecalcDiffusion(Float_t vdrift); AliRunLoader *fRunLoader; //! Local pointer AliTRDdigitsManager *fDigitsManager; //! Manager for the output digits @@ -87,31 +100,25 @@ class AliTRDdigitizer : public AliDigitizer { AliTRDgeometry *fGeo; //! TRD geometry AliTRDfeeParam *fFee; // Fee Parameters - Int_t fEvent; //! Event number - Int_t *fMasks; //! Masks for the merging - Bool_t fCompress; // Switch to keep only compressed data in memory - Bool_t fSDigits; // Switch for the summable digits - Float_t fSDigitsScale; // Scale factor for the summable digits - Bool_t fMergeSignalOnly; // Merge only detectors that contain a signal - - Float_t fDiffLastVdrift; // The structures are valid for fLastVdrift (caching) - Float_t fDiffusionT; // Transverse drift coefficient - Float_t fDiffusionL; // Longitudinal drift coefficient - Float_t fOmegaTau; // Tangens of the Lorentz angle - Float_t fLorentzFactor; // Factor due to Lorentz force - - Float_t fTimeLastVdrift; // The structures are valid for fLastVdrift (caching) - Float_t *fTimeStruct1; //! Time Structure of Drift Cells - Float_t *fTimeStruct2; //! Time Structure of Drift Cells - Float_t fVDlo; // Lower drift velocity, for interpolation - Float_t fVDhi; // Higher drift velocity, for interpolation - - private: - - virtual Bool_t Init(); + Int_t fEvent; //! Event number + Int_t *fMasks; //! Masks for the merging + Bool_t fCompress; // Switch to keep only compressed data in memory + Bool_t fSDigits; // Switch for the summable digits + Bool_t fMergeSignalOnly; // Merge only detectors that contain a signal - ClassDef(AliTRDdigitizer,15) // Produces TRD-Digits + Float_t fDiffLastVdrift; // The structures are valid for fLastVdrift (caching) + Float_t fDiffusionT; // Transverse drift coefficient + Float_t fDiffusionL; // Longitudinal drift coefficient + Float_t fOmegaTau; // Tangens of the Lorentz angle + Float_t fLorentzFactor; // Factor due to Lorentz force -}; + Float_t fTimeLastVdrift; // The structures are valid for fLastVdrift (caching) + Float_t *fTimeStruct1; //! Time Structure of Drift Cells + Float_t *fTimeStruct2; //! Time Structure of Drift Cells + Float_t fVDlo; // Lower drift velocity, for interpolation + Float_t fVDhi; // Higher drift velocity, for interpolation + ClassDef(AliTRDdigitizer,16) // Produces TRD-Digits + +}; #endif diff --git a/TRD/AliTRDdigitsManager.cxx b/TRD/AliTRDdigitsManager.cxx index 199855e62ac..3a8ef555466 100644 --- a/TRD/AliTRDdigitsManager.cxx +++ b/TRD/AliTRDdigitsManager.cxx @@ -33,7 +33,9 @@ #include "AliTRDdigitsManager.h" #include "AliTRDsegmentArray.h" +#include "AliTRDdataArray.h" #include "AliTRDdataArrayI.h" +#include "AliTRDdataArrayS.h" #include "AliTRDdigit.h" #include "AliTRDgeometry.h" @@ -52,8 +54,7 @@ AliTRDdigitsManager::AliTRDdigitsManager() ,fEvent(0) ,fTree(0) ,fDigits(0) - ,fIsRaw(0) - ,fSDigits(0) + ,fHasSDigits(0) ,fSignalIndexes(NULL) ,fUseDictionaries(kTRUE) { @@ -65,7 +66,6 @@ AliTRDdigitsManager::AliTRDdigitsManager() fDictionary[iDict] = NULL; } - //fSignalIndexes = new TList(); fSignalIndexes = new TObjArray(AliTRDgeometry::Ndet()); } @@ -76,8 +76,7 @@ AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m) ,fEvent(m.fEvent) ,fTree(0) ,fDigits(0) - ,fIsRaw(m.fIsRaw) - ,fSDigits(m.fSDigits) + ,fHasSDigits(m.fHasSDigits) ,fSignalIndexes(NULL) ,fUseDictionaries(kTRUE) { @@ -97,7 +96,7 @@ AliTRDdigitsManager::~AliTRDdigitsManager() if (fDigits) { fDigits->Delete(); delete fDigits; - fDigits = NULL; + fDigits = NULL; } for (Int_t iDict = 0; iDict < kNDict; iDict++) { @@ -109,8 +108,8 @@ AliTRDdigitsManager::~AliTRDdigitsManager() if (fSignalIndexes) { fSignalIndexes->Delete(); delete fSignalIndexes; + fSignalIndexes = NULL; } - fSignalIndexes = NULL; } @@ -121,7 +120,10 @@ AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m // Assignment operator // - if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this); + if (this != &m) { + ((AliTRDdigitsManager &) m).Copy(*this); + } + return *this; } @@ -133,11 +135,10 @@ void AliTRDdigitsManager::Copy(TObject &m) const // Copy function // - ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw; - ((AliTRDdigitsManager &) m).fEvent = fEvent; - ((AliTRDdigitsManager &) m).fSDigits = fSDigits; + ((AliTRDdigitsManager &) m).fEvent = fEvent; + ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits; - ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes; + ((AliTRDdigitsManager &) m).fSignalIndexes = fSignalIndexes; ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries; TObject::Copy(m); @@ -151,21 +152,26 @@ void AliTRDdigitsManager::CreateArrays() // Create the data arrays // - fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet()); + if (fHasSDigits) { + fDigits = new AliTRDsegmentArray("AliTRDdataArrayF",AliTRDgeometry::Ndet()); + } + else { + fDigits = new AliTRDsegmentArray("AliTRDdataArrayS",AliTRDgeometry::Ndet()); + } - if (fUseDictionaries) - { - for (Int_t iDict = 0; iDict < kNDict; iDict++) { - fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI" - ,AliTRDgeometry::Ndet()); - } + if (fUseDictionaries) { + for (Int_t iDict = 0; iDict < kNDict; iDict++) { + fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI" + ,AliTRDgeometry::Ndet()); } + } + + for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) { + fSignalIndexes->AddLast(new AliTRDSignalIndex()); + } - for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) - { - fSignalIndexes->AddLast(new AliTRDSignalIndex()); - } } + //_____________________________________________________________________________ void AliTRDdigitsManager::ResetArrays() { @@ -177,38 +183,29 @@ void AliTRDdigitsManager::ResetArrays() fDigits->Delete(); delete fDigits; } - fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet()); + if (fHasSDigits) { + fDigits = new AliTRDsegmentArray("AliTRDdataArrayF",AliTRDgeometry::Ndet()); + } + else { + fDigits = new AliTRDsegmentArray("AliTRDdataArrayS",AliTRDgeometry::Ndet()); + } - if (fUseDictionaries) - { - for (Int_t iDict = 0; iDict < kNDict; iDict++) { - if (fDictionary[iDict]) { - fDictionary[iDict]->Delete(); - delete fDictionary[iDict]; - } - fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI" - ,AliTRDgeometry::Ndet()); + if (fUseDictionaries) { + for (Int_t iDict = 0; iDict < kNDict; iDict++) { + if (fDictionary[iDict]) { + fDictionary[iDict]->Delete(); + delete fDictionary[iDict]; } + fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI" + ,AliTRDgeometry::Ndet()); } + } - for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) - { - AliTRDSignalIndex *idx = (AliTRDSignalIndex *)fSignalIndexes->At(i); - if (idx) idx->Reset(); - } -} - -//_____________________________________________________________________________ -void AliTRDdigitsManager::SetRaw() -{ - // - // Switch on the raw digits flag - // + for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) { + AliTRDSignalIndex *idx = (AliTRDSignalIndex *)fSignalIndexes->At(i); + if (idx) idx->Reset(); + } - fIsRaw = kTRUE; - if (fDigits) - fDigits->SetBit(AliTRDdigit::RawDigit()); - } //_____________________________________________________________________________ @@ -219,8 +216,11 @@ Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time // Returns the amplitude of a digit // - if (!GetDigits(det)) return 0; - return ((Short_t) GetDigits(det)->GetData(row,col,time)); + if (!GetDigits(det)) { + return 0; + } + + return ((Short_t) ((AliTRDdataArrayS *) GetDigits(det))->GetData(row,col,time)); } @@ -245,8 +245,8 @@ Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree) if (kDigits) { if (!fTree) return kFALSE; TBranch* branch = fTree->GetBranch("TRDdigits"); - if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName(), - &kDigits,buffersize,99); + if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName() + ,&kDigits,buffersize,99); AliDebug(1,"Making branch TRDdigits\n"); } else { @@ -257,31 +257,30 @@ Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree) status = kFALSE; } - if (fUseDictionaries) - { - // Make the branches for the dictionaries - for (Int_t iDict = 0; iDict < kNDict; iDict++) { - Char_t branchname[15]; - sprintf(branchname,"TRDdictionary%d",iDict); - if (fDictionary[iDict]) { - const AliTRDdataArray *kDictionary = - (AliTRDdataArray *) fDictionary[iDict]->At(0); - if (kDictionary) { - if (!fTree) return kFALSE; - TBranch* branch = fTree->GetBranch(branchname); - if (!branch) fTree->Branch(branchname,kDictionary->IsA()->GetName(), - &kDictionary,buffersize,99); - AliDebug(1,Form("Making branch %s\n",branchname)); - } - else { - status = kFALSE; - } + if (fUseDictionaries) { + // Make the branches for the dictionaries + for (Int_t iDict = 0; iDict < kNDict; iDict++) { + Char_t branchname[15]; + sprintf(branchname,"TRDdictionary%d",iDict); + if (fDictionary[iDict]) { + const AliTRDdataArray *kDictionary = + (AliTRDdataArray *) fDictionary[iDict]->At(0); + if (kDictionary) { + if (!fTree) return kFALSE; + TBranch* branch = fTree->GetBranch(branchname); + if (!branch) fTree->Branch(branchname,kDictionary->IsA()->GetName() + ,&kDictionary,buffersize,99); + AliDebug(1,Form("Making branch %s\n",branchname)); } else { status = kFALSE; } } + else { + status = kFALSE; + } } + } return status; @@ -297,9 +296,7 @@ Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree) Bool_t status = kTRUE; if (tree) { - fTree = tree; - } if (!fDigits) { @@ -309,26 +306,17 @@ Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree) status = fDigits->LoadArray("TRDdigits",fTree); - if (fUseDictionaries) - { - for (Int_t iDict = 0; iDict < kNDict; iDict++) { - Char_t branchname[15]; - sprintf(branchname,"TRDdictionary%d",iDict); - status = fDictionary[iDict]->LoadArray(branchname,fTree); - if (status == kFALSE) - { - fUseDictionaries = kFALSE; - AliWarning("Unable to load dict arrays. Will not use them.\n"); - break; - } - } - } - - if (fDigits->TestBit(AliTRDdigit::RawDigit())) { - fIsRaw = kTRUE; - } - else { - fIsRaw = kFALSE; + if (fUseDictionaries) { + for (Int_t iDict = 0; iDict < kNDict; iDict++) { + Char_t branchname[15]; + sprintf(branchname,"TRDdictionary%d",iDict); + status = fDictionary[iDict]->LoadArray(branchname,fTree); + if (status == kFALSE) { + fUseDictionaries = kFALSE; + AliWarning("Unable to load dict arrays. Will not use them.\n"); + break; + } + } } return kTRUE; @@ -348,17 +336,16 @@ Bool_t AliTRDdigitsManager::WriteDigits() return kFALSE; } - if (fUseDictionaries) - { - for (Int_t iDict = 0; iDict < kNDict; iDict++) { - Char_t branchname[15]; - sprintf(branchname,"TRDdictionary%d",iDict); - if (!fDictionary[iDict]->StoreArray(branchname,fTree)) { - AliError(Form("Error while storing dictionary in branch %s\n",branchname)); - return kFALSE; - } + if (fUseDictionaries) { + for (Int_t iDict = 0; iDict < kNDict; iDict++) { + Char_t branchname[15]; + sprintf(branchname,"TRDdictionary%d",iDict); + if (!fDictionary[iDict]->StoreArray(branchname,fTree)) { + AliError(Form("Error while storing dictionary in branch %s\n",branchname)); + return kFALSE; } } + } // Write the new tree to the output file fTree->AutoSave(); // Modification by Jiri @@ -383,9 +370,9 @@ AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col digits[2] = col; digits[3] = time; - amp[0] = GetDigits(det)->GetData(row,col,time); + amp[0] = ((AliTRDdataArrayS *) GetDigits(det))->GetData(row,col,time); - return (new AliTRDdigit(fIsRaw,digits,amp)); + return (new AliTRDdigit(digits,amp)); } @@ -404,39 +391,42 @@ Int_t AliTRDdigitsManager::GetTrack(Int_t track return -1; } - if (fUseDictionaries == kFALSE) - { - return -1; - } + if (fUseDictionaries == kFALSE) { + return -1; + } + // Array contains index+1 to allow data compression - return (GetDictionary(det,track)->GetData(row,col,time) - 1); + return (((AliTRDdataArrayI *) GetDictionary(det,track))->GetData(row,col,time) - 1); } //_____________________________________________________________________________ -AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const +AliTRDdataArray *AliTRDdigitsManager::GetDigits(Int_t det) const { // // Returns the digits array for one detector // - if (!fDigits) return 0x0; - return (AliTRDdataArrayI *) fDigits->At(det); + if (!fDigits) { + return 0x0; + } + + return (AliTRDdataArray *) fDigits->At(det); } //_____________________________________________________________________________ -AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const +AliTRDdataArray *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const { // // Returns the dictionary for one detector // - if (fUseDictionaries == kFALSE) - { - return NULL; - } - return (AliTRDdataArrayI *) fDictionary[i]->At(det); + if (fUseDictionaries == kFALSE) { + return 0x0; + } + + return (AliTRDdataArray *) fDictionary[i]->At(det); } @@ -463,7 +453,7 @@ AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det) // Returns indexes of active pads // - return (AliTRDSignalIndex*)fSignalIndexes->At(det); + return (AliTRDSignalIndex *) fSignalIndexes->At(det); } @@ -484,10 +474,10 @@ void AliTRDdigitsManager::RemoveDictionaries(Int_t det) // // Clear memory // - if (fUseDictionaries == kFALSE) - { - return; - } + + if (fUseDictionaries == kFALSE) { + return; + } for (Int_t i = 0; i < kNDict; i++) { fDictionary[i]->ClearSegment(det); @@ -501,9 +491,10 @@ void AliTRDdigitsManager::ClearIndexes(Int_t det) // // Clear memory // + fSignalIndexes->At(det)->Clear(); -} +} //_____________________________________________________________________________ Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det) @@ -517,49 +508,50 @@ Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det) Int_t nTbins = 0; AliTRDgeometry geom; - AliTRDdataArrayI *digits = GetDigits(det); + AliTRDdataArrayS *digits = 0x0; + + if (fHasSDigits) { + return kFALSE; + } + else { + digits = (AliTRDdataArrayS *) GetDigits(det); + } + //digits should be expanded by now!!! - if (digits->GetNtime() > 0) - { - digits->Expand(); - nRows = digits->GetNrow(); - nCols = digits->GetNcol(); - nTbins = digits->GetNtime(); - - //AliInfo(Form("rows %d cols %d tbins %d", nRows, nCols, nTbins)); - - AliTRDSignalIndex* indexes = GetIndexes(det); - indexes->SetSM(geom.GetSector(det)); - indexes->SetChamber(geom.GetChamber(det)); - indexes->SetPlane(geom.GetPlane(det)); - indexes->SetDetNumber(det); - if (indexes->IsAllocated() == kFALSE) - { - indexes->Allocate(nRows, nCols, nTbins); - //AliInfo(Form("Allocating 0x%x %d", indexes->GetArray(), indexes->GetArray()->GetSize())); - } - for (Int_t ir = 0; ir < nRows; ir++) - { - for (Int_t ic = 0; ic < nCols; ic++) - { - for (Int_t it = 0; it < nTbins; it++) - { - //AliInfo(Form("row %d col %d tbin %d", ir, ic, it)); - - Int_t isig = digits->GetDataUnchecked(ir, ic, it); - if (isig > 0) - { - //AliInfo(Form("row %d col %d tbin %d", ir, ic, it)); - indexes->AddIndexTBin(ir, ic, it); - } - } //tbins - } //cols - } // rows - } // if GetNtime - else - { - return kFALSE; + if (digits->GetNtime() > 0) { + + digits->Expand(); + nRows = digits->GetNrow(); + nCols = digits->GetNcol(); + nTbins = digits->GetNtime(); + + AliTRDSignalIndex *indexes = GetIndexes(det); + indexes->SetSM(geom.GetSector(det)); + indexes->SetChamber(geom.GetChamber(det)); + indexes->SetPlane(geom.GetPlane(det)); + indexes->SetDetNumber(det); + + if (indexes->IsAllocated() == kFALSE) { + indexes->Allocate(nRows,nCols,nTbins); } + + for (Int_t ir = 0; ir < nRows; ir++) { + for (Int_t ic = 0; ic < nCols; ic++) { + for (Int_t it = 0; it < nTbins; it++) { + + Int_t isig = digits->GetDataUnchecked(ir,ic,it); + if (isig > 0) { + indexes->AddIndexTBin(ir,ic,it); + } + } // tbins + } // cols + } // rows + + } // if GetNtime + else { + return kFALSE; + } + return kTRUE; } diff --git a/TRD/AliTRDdigitsManager.h b/TRD/AliTRDdigitsManager.h index 22bfa123802..1972d53f597 100644 --- a/TRD/AliTRDdigitsManager.h +++ b/TRD/AliTRDdigitsManager.h @@ -16,7 +16,7 @@ class TFile; class TTree; class AliTRDsegmentArray; -class AliTRDdataArrayI; +class AliTRDdataArray; class AliTRDdigit; class AliTRDSignalIndex; @@ -31,62 +31,60 @@ class AliTRDdigitsManager : public TObject { virtual ~AliTRDdigitsManager(); AliTRDdigitsManager &operator=(const AliTRDdigitsManager &m); + virtual void Copy(TObject &m) const; + virtual void CreateArrays(); virtual void ResetArrays(); - virtual void Copy(TObject &m) const; + virtual Bool_t BuildIndexes(Int_t det); virtual Bool_t MakeBranch(TTree *tree); - virtual Bool_t ReadDigits(TTree *tree); virtual Bool_t WriteDigits(); - virtual void SetRaw(); - virtual void SetEvent(Int_t evt) { fEvent = evt; }; - virtual void SetSDigits(Int_t v = 1) { fSDigits = v; }; + virtual void SetEvent(Int_t evt) { fEvent = evt; }; + virtual void SetSDigits(Int_t v = 1) { fHasSDigits = v; }; + virtual void SetUseDictionaries(Bool_t kval) { fUseDictionaries = kval; }; - virtual Bool_t IsRaw() const { return fIsRaw; }; - static Int_t NDict() { return fgkNDict; }; + virtual Bool_t UsesDictionaries() const { return fUseDictionaries; }; + virtual Bool_t HasSDigits() const { return fHasSDigits; }; + static Int_t NDict() { return fgkNDict; }; - virtual AliTRDsegmentArray *GetDigits() const { return fDigits; }; - virtual AliTRDsegmentArray *GetDictionary(Int_t i) const { return fDictionary[i]; }; + virtual AliTRDsegmentArray *GetDigits() const { return fDigits; }; + virtual AliTRDsegmentArray *GetDictionary(Int_t i) const { return fDictionary[i]; }; AliTRDdigit *GetDigit(Int_t row, Int_t col, Int_t time, Int_t det) const; Int_t GetTrack(Int_t track, Int_t row, Int_t col , Int_t time, Int_t det) const; - AliTRDdataArrayI *GetDigits(Int_t det) const; - AliTRDdataArrayI *GetDictionary(Int_t det, Int_t i) const; + AliTRDdataArray *GetDigits(Int_t det) const; + AliTRDdataArray *GetDictionary(Int_t det, Int_t i) const; + + AliTRDSignalIndex *GetIndexes(Int_t det); + TObjArray *GetIndexes() { return fSignalIndexes; }; void RemoveDigits(Int_t det); void RemoveDictionaries(Int_t det); void ClearIndexes(Int_t det); - Int_t GetTrack(Int_t track, AliTRDdigit *Digit) const; + Int_t GetTrack(Int_t track, AliTRDdigit *digit) const; Short_t GetDigitAmp(Int_t row, Int_t col, Int_t time, Int_t det) const; - AliTRDSignalIndex *GetIndexes(Int_t det); - TObjArray *GetIndexes() {return fSignalIndexes;}; - virtual Bool_t BuildIndexes(Int_t det); - virtual void SetUseDictionaries(Bool_t kval) {fUseDictionaries = kval;} - virtual Bool_t UsesDictionaries() const {return fUseDictionaries;} - protected: static const Int_t fgkNDict; // Number of track dictionary arrays Int_t fEvent; // Event number - TTree *fTree; //! Tree for the digits arrays AliTRDsegmentArray *fDigits; //! Digits data array AliTRDsegmentArray *fDictionary[kNDict]; //! Track dictionary data array - Bool_t fIsRaw; // Flag indicating raw digits - Bool_t fSDigits; // Switch for the summable digits + Bool_t fHasSDigits; // Switch for the summable digits TObjArray *fSignalIndexes; // Provides access to the active pads and tbins Bool_t fUseDictionaries; // Use dictionaries or not (case of real data) - ClassDef(AliTRDdigitsManager,6) // Manages the TRD digits + + ClassDef(AliTRDdigitsManager,7) // Manages the TRD digits }; diff --git a/TRD/AliTRDgeometry.h b/TRD/AliTRDgeometry.h index 0f46fc47f89..13df0d0bfe6 100644 --- a/TRD/AliTRDgeometry.h +++ b/TRD/AliTRDgeometry.h @@ -66,7 +66,9 @@ class AliTRDgeometry : public AliGeometry { void CreatePadPlaneArray(); AliTRDpadPlane *CreatePadPlane(Int_t p, Int_t c); AliTRDpadPlane *GetPadPlane(Int_t p, Int_t c); - Int_t GetRowMax(Int_t p, Int_t c, Int_t /*s*/); + AliTRDpadPlane *GetPadPlane(Int_t det) { return GetPadPlane(GetPlane(det) + ,GetChamber(det)); } + Int_t GetRowMax(Int_t p, Int_t c, Int_t /*s*/); Int_t GetColMax(Int_t p); Double_t GetRow0(Int_t p, Int_t c, Int_t /*s*/); Double_t GetCol0(Int_t p); diff --git a/TRD/AliTRDrawData.cxx b/TRD/AliTRDrawData.cxx index df328b5985c..80f0ee0b8ad 100644 --- a/TRD/AliTRDrawData.cxx +++ b/TRD/AliTRDrawData.cxx @@ -21,8 +21,6 @@ // // /////////////////////////////////////////////////////////////////////////////// -//#include - #include #include "TClass.h" @@ -36,6 +34,7 @@ #include "AliTRDdigitsManager.h" #include "AliTRDgeometry.h" #include "AliTRDdataArrayI.h" +#include "AliTRDdataArrayS.h" #include "AliTRDRawStream.h" #include "AliTRDRawStreamV2.h" #include "AliTRDcalibDB.h" @@ -191,7 +190,7 @@ Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager) Int_t iDet = fGeo->GetDetector(plan,cham,sect); // Get the digits array - AliTRDdataArrayI *digits = digitsManager->GetDigits(iDet); + AliTRDdataArrayS *digits = (AliTRDdataArrayS *) digitsManager->GetDigits(iDet); digits->Expand(); Int_t hcwords = 0; @@ -228,7 +227,7 @@ Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager) } //_____________________________________________________________________________ -Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDdataArrayI *digits, Int_t side +Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDdataArrayS *digits, Int_t side , Int_t det, UInt_t *buf, Int_t maxSize) { // @@ -413,7 +412,7 @@ Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDdataArrayI *digits, Int_t side } //_____________________________________________________________________________ -Int_t AliTRDrawData::ProduceHcDataV3(AliTRDdataArrayI *digits, Int_t side +Int_t AliTRDrawData::ProduceHcDataV3(AliTRDdataArrayS *digits, Int_t side , Int_t det, UInt_t *buf, Int_t maxSize) { // @@ -558,7 +557,7 @@ AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader) // Vx of the raw data reading // - AliTRDdataArrayI *digits = 0; + AliTRDdataArrayS *digits = 0; AliTRDdataArrayI *track0 = 0; AliTRDdataArrayI *track1 = 0; AliTRDdataArrayI *track2 = 0; @@ -593,10 +592,10 @@ AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader) if (track2) track2->Compress(1,0); // Add a container for the digits of this detector - digits = digitsManager->GetDigits(det); - track0 = digitsManager->GetDictionary(det,0); - track1 = digitsManager->GetDictionary(det,1); - track2 = digitsManager->GetDictionary(det,2); + digits = (AliTRDdataArrayS *) digitsManager->GetDigits(det); + track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0); + track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1); + track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2); // Allocate memory space for the digits buffer if (digits->GetNtime() == 0) diff --git a/TRD/AliTRDrawData.h b/TRD/AliTRDrawData.h index 6dc74b4bdd2..bb5f843db65 100644 --- a/TRD/AliTRDrawData.h +++ b/TRD/AliTRDrawData.h @@ -20,7 +20,7 @@ class AliRawReader; class AliTRDdigitsManager; class AliTRDgeometry; class AliTRDfeeParam; -class AliTRDdataArrayI; +class AliTRDdataArrayS; class AliTRDrawData : public TObject { @@ -34,13 +34,13 @@ class AliTRDrawData : public TObject { virtual Bool_t Digits2Raw(TTree *digits, TTree *tracks = NULL); - virtual AliTRDdigitsManager* Raw2Digits(AliRawReader *rawReader); + virtual AliTRDdigitsManager *Raw2Digits(AliRawReader *rawReader); protected: virtual Bool_t Digits2Raw(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 ProduceHcDataV1andV2(AliTRDdataArrayS *digits, Int_t side, Int_t det, UInt_t *buf, Int_t maxSize); + virtual Int_t ProduceHcDataV3(AliTRDdataArrayS *digits, Int_t side, Int_t det, UInt_t *buf, Int_t maxSize); AliTRDgeometry *fGeo; //! Geometry AliTRDfeeParam *fFee; //! Fee Parameters diff --git a/TRD/AliTRDrawStreamTB.cxx b/TRD/AliTRDrawStreamTB.cxx index 371f1466ba2..4b2a753abb9 100644 --- a/TRD/AliTRDrawStreamTB.cxx +++ b/TRD/AliTRDrawStreamTB.cxx @@ -37,6 +37,7 @@ #include "AliTRDfeeParam.h" #include "AliTRDdigitsManager.h" #include "AliTRDdataArrayI.h" +#include "AliTRDdataArrayS.h" #include "AliTRDSignalIndex.h" #include "AliLog.h" @@ -639,7 +640,7 @@ AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager) // Return value is the detector number // - AliTRDdataArrayI *digits = 0; + AliTRDdataArrayS *digits = 0; AliTRDdataArrayI *track0 = 0; AliTRDdataArrayI *track1 = 0; AliTRDdataArrayI *track2 = 0; @@ -680,10 +681,10 @@ AliTRDrawStreamTB::NextChamber(AliTRDdigitsManager *digitsManager) } // Add a container for the digits of this detector - digits = digitsManager->GetDigits(det); - track0 = digitsManager->GetDictionary(det,0); - track1 = digitsManager->GetDictionary(det,1); - track2 = digitsManager->GetDictionary(det,2); + digits = (AliTRDdataArrayS *) digitsManager->GetDigits(det); + track0 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,0); + track1 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,1); + track2 = (AliTRDdataArrayI *) digitsManager->GetDictionary(det,2); if (!digits) { diff --git a/TRD/AliTRDsegmentArray.cxx b/TRD/AliTRDsegmentArray.cxx index 9c40402dc04..e31c4f877b5 100644 --- a/TRD/AliTRDsegmentArray.cxx +++ b/TRD/AliTRDsegmentArray.cxx @@ -21,36 +21,64 @@ // // //////////////////////////////////////////////////////////////////////////// +#include #include +#include +#include +#include +#include #include "AliLog.h" #include "AliTRDgeometry.h" #include "AliTRDsegmentArray.h" +#include "AliTRDsegmentID.h" #include "AliTRDdataArray.h" +#include "AliTRDarrayI.h" ClassImp(AliTRDsegmentArray) //_____________________________________________________________________________ AliTRDsegmentArray::AliTRDsegmentArray() - :AliTRDsegmentArrayBase() + :TNamed() + ,fSegment(0) + ,fTreeIndex(0) + ,fNSegment(0) + ,fTree(0) + ,fBranch(0) + ,fClass(0) { // - // Default constructor + // Default constructor // } //_____________________________________________________________________________ AliTRDsegmentArray::AliTRDsegmentArray(const char *classname, Int_t n) - :AliTRDsegmentArrayBase(classname,n) + :TNamed() + ,fSegment(0) + ,fTreeIndex(0) + ,fNSegment(0) + ,fTree(0) + ,fBranch(0) + ,fClass(0) { // - // Constructor creating an array of AliTRDdataArray of size + // Create an array of objects of . The class must inherit from + // AliTRDsegmentID. The second argument sets the number of entries in + // the array. // AliTRDdataArray *dataArray; + SetClass(classname); + + if (MakeArray(n) == kFALSE) { + AliError(Form("Cannot allocate %d segments in memory",n)); + return; + } + for (Int_t i = 0; i < n; i++) { dataArray = (AliTRDdataArray *) AddSegment(i); } @@ -59,7 +87,13 @@ AliTRDsegmentArray::AliTRDsegmentArray(const char *classname, Int_t n) //_____________________________________________________________________________ AliTRDsegmentArray::AliTRDsegmentArray(AliTRDsegmentArray &a) - :AliTRDsegmentArrayBase(a) + :TNamed(a) + ,fSegment(a.fSegment) + ,fTreeIndex(a.fTreeIndex) + ,fNSegment(a.fNSegment) + ,fTree(a.fTree) + ,fBranch(a.fBranch) + ,fClass(a.fClass) { // // AliTRDsegmentArray copy constructor @@ -78,6 +112,27 @@ AliTRDsegmentArray::~AliTRDsegmentArray() Delete(); + if (fNSegment) { + fSegment->Delete(); + delete fSegment; + } + + if (fTreeIndex) { + delete fTreeIndex; + } + +} + +//_____________________________________________________________________________ +AliTRDsegmentArray &AliTRDsegmentArray::operator=(const AliTRDsegmentArray &a) +{ + // + // Assignment operator + // + + if (this != &a) ((AliTRDsegmentArray &) a).Copy(*this); + return *this; + } //_____________________________________________________________________________ @@ -87,7 +142,389 @@ void AliTRDsegmentArray::Copy(TObject &a) const // Copy function // - AliTRDsegmentArrayBase::Copy(a); + TNamed::Copy(a); + + fSegment->Copy(*((AliTRDsegmentArray &) a).fSegment); + fTreeIndex->Copy(*((AliTRDsegmentArray &) a).fTreeIndex); + fClass->Copy(*((AliTRDsegmentArray &) a).fClass); + + ((AliTRDsegmentArray &) a).fNSegment = fNSegment; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDsegmentArray::SetClass(const Char_t *classname) +{ + // + // Sets the classname of the stored object + // + + if (fTree != 0) { + delete fTree; + fTree = 0; + fBranch = 0; + delete fTreeIndex; + fTreeIndex = 0; + } + if (fSegment != 0) { + fSegment->Delete(); + delete fSegment; + fSegment = 0; + } + + if (!gROOT) { + AliFatal("ROOT system not initialized"); + exit(1); + } + + fClass = gROOT->GetClass(classname); + if (!fClass) { + AliError(Form("%s is not a valid class name",classname)); + return kFALSE; + } + if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) { + AliError(Form("%s does not inherit from AliTRDsegmentID",classname)); + return kFALSE; + } + + return kTRUE; + +} + +//_____________________________________________________________________________ +AliTRDsegmentID *AliTRDsegmentArray::NewSegment() +{ + // + // Create a new object according to the class information + // + + if (fClass == 0) { + return 0; + } + + AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New(); + + if (segment == 0) { + return 0; + } + else { + return segment; + } + +} + +//_____________________________________________________________________________ +Bool_t AliTRDsegmentArray::AddSegment(AliTRDsegmentID *segment) +{ + // + // Add a segment to the array + // + + if (segment == 0) { + return kFALSE; + } + if (fSegment == 0) { + return kFALSE; + } + if (fClass == 0) { + return kFALSE; + } + + if (!(segment->IsA()->InheritsFrom(fClass))) { + AliError(Form("added class %s is not of proper type" + ,segment->IsA()->GetName())); + return kFALSE; + } + + fSegment->AddAt(segment,segment->GetID()); + fNSegment = fSegment->GetLast() + 1; + + return kTRUE; + +} + +//_____________________________________________________________________________ +AliTRDsegmentID *AliTRDsegmentArray::AddSegment(Int_t index) +{ + // + // Add a segment to the array + // + + if (fSegment == 0) { + return 0; + } + if (fClass == 0) { + return 0; + } + + AliTRDsegmentID *segment = NewSegment(); + if (segment == 0) { + return 0; + } + + fSegment->AddAt(segment,index); + segment->SetID(index); + fNSegment = fSegment->GetLast() + 1; + + return segment; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDsegmentArray::MakeArray(Int_t n) +{ + // + // Create an array of pointers to the segments + // + + if (fSegment) { + fSegment->Delete(); + delete fSegment; + } + if (fTreeIndex) delete fTreeIndex; + + fSegment = new TObjArray(n); + fTreeIndex = new AliTRDarrayI(); + fTreeIndex->Set(n); + fNSegment = n; + if ((fSegment) && (fTreeIndex)) { + return kTRUE; + } + else { + return kFALSE; + } + +} + +//_____________________________________________________________________________ +void AliTRDsegmentArray::ClearSegment(Int_t index) +{ + // + // Remove a segment from the active memory + // + + if (fSegment->At(index)) { + delete fSegment->RemoveAt(index); + } + +} + +//_____________________________________________________________________________ +void AliTRDsegmentArray::MakeTree(char *file) +{ + // + // Create a tree for the segment + // + + AliTRDsegmentID *psegment = NewSegment(); + + if (fTree) { + delete fTree; + } + + fTree = new TTree("Segment Tree","Tree with segments"); + fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000); + + if (file) { + fBranch->SetFile(file); + } + + delete psegment; + +} + +//_____________________________________________________________________________ +Bool_t AliTRDsegmentArray::ConnectTree(const char *treeName) +{ + // + // Connect a tree from current directory + // + + if (fTree) { + delete fTree; + fTree = 0; + fBranch = 0; + } + + fTree = (TTree *) gDirectory->Get(treeName); + if (fTree == 0) { + return kFALSE; + } + fBranch = fTree->GetBranch("Segment"); + if (fBranch == 0) { + return kFALSE; + } + + MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries()))); + + return kTRUE; + +} + +//_____________________________________________________________________________ +AliTRDsegmentID *AliTRDsegmentArray::LoadSegment(Int_t index) +{ + // + // Load a segment with index into the memory + // + + if (fTreeIndex == 0) { + MakeDictionary(3000); + } + + // First try to load dictionary + if (fTreeIndex == 0) { + return 0; + } + if (fBranch == 0) { + return 0; + } + if (index > fTreeIndex->fN) { + return 0; + } + + AliTRDsegmentID *s = (AliTRDsegmentID *) fSegment->At(index); + if (s == 0) { + s = NewSegment(); + } + s->SetID(index); + + if (s != 0) { + Int_t treeIndex = (*fTreeIndex)[index]; + if (treeIndex < 1) { + return 0; + } + else { + treeIndex--; + } + fBranch->SetAddress(&s); + fTree->GetEvent(treeIndex); + fSegment->AddAt((TObject*) s, index); + } + else { + return 0; + } + + return s; + +} + +//_____________________________________________________________________________ +AliTRDsegmentID *AliTRDsegmentArray::LoadEntry(Int_t index) +{ + // + // Load a segment at position in the tree into the memory + // + + if (fBranch == 0) { + return 0; + } + if (index > fTree->GetEntries()) { + return 0; + } + + AliTRDsegmentID *s = NewSegment(); + if (s) { + fBranch->SetAddress(&s); + fTree->GetEvent(index); + } + else { + return 0; + } + + Int_t nindex = s->GetID(); + ClearSegment(nindex); + fSegment->AddAt((TObject *) s, nindex); + + return s; + +} + +//_____________________________________________________________________________ +void AliTRDsegmentArray::StoreSegment(Int_t index) +{ + // + // Make a segment persistent + // + + const AliTRDsegmentID *kSegment = (*this)[index]; + if (kSegment == 0) { + return; + } + if (fTree == 0) { + MakeTree(); + } + fBranch->SetAddress(&kSegment); + fTree->Fill(); + +} + +//_____________________________________________________________________________ +Bool_t AliTRDsegmentArray::MakeDictionary(Int_t size) +{ + // + // Create an index table for the tree + // + + if (size < 1) { + return kFALSE; + } + if (fTreeIndex) { + delete fTreeIndex; + } + + fTreeIndex = new AliTRDarrayI(); + fTreeIndex->Set(size); + + AliTRDsegmentID segment; + AliTRDsegmentID *psegment = &segment; + + fBranch->SetAddress(&psegment); + TBranch *brindix = fTree->GetBranch("fSegmentID"); + + Int_t nevent = (Int_t) fTree->GetEntries(); + for (Int_t i = 0; i < nevent; i++) { + brindix->GetEvent(i); + Int_t treeIndex = segment.GetID(); + if (fTreeIndex->fN < treeIndex) { + fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1); + } + (*fTreeIndex)[treeIndex] = i + 1; + } + + return kTRUE; + +} + +//_____________________________________________________________________________ +const AliTRDsegmentID * AliTRDsegmentArray::operator[](Int_t i) const +{ + // + // Returns a segment with the given index + // + + if ((i < 0) || + (i >= fNSegment)) { + return 0; + } + + return (AliTRDsegmentID *) fSegment->At(i); + +} + +//_____________________________________________________________________________ +const AliTRDsegmentID *AliTRDsegmentArray::At(Int_t i) const +{ + // + // Returns a segment with the given index + // + + if ((i < 0) || + (i >= fNSegment)) { + return 0; + } + + return (AliTRDsegmentID *) fSegment->At(i); } @@ -168,7 +605,7 @@ Bool_t AliTRDsegmentArray::StoreArray(const Char_t *branchname, TTree *tree) Bool_t status = kTRUE; for (Int_t iSegment = 0; iSegment < fNSegment; iSegment++) { const AliTRDdataArray *kDataArray = - (AliTRDdataArray *) AliTRDsegmentArrayBase::At(iSegment); + (AliTRDdataArray *) AliTRDsegmentArray::At(iSegment); if (!kDataArray) { status = kFALSE; break; @@ -188,7 +625,7 @@ AliTRDdataArray *AliTRDsegmentArray::GetDataArray(Int_t det) const // Returns the data array for a given detector // - return ((AliTRDdataArray *) AliTRDsegmentArrayBase::At(det)); + return ((AliTRDdataArray *) AliTRDsegmentArray::At(det)); } diff --git a/TRD/AliTRDsegmentArray.h b/TRD/AliTRDsegmentArray.h index 51c11cd4629..00b439a108a 100644 --- a/TRD/AliTRDsegmentArray.h +++ b/TRD/AliTRDsegmentArray.h @@ -13,11 +13,17 @@ // // //////////////////////////////////////////////////////////////////////////// +#include + class TTree; +class TBranch; +class TObjArray; +class AliTRDarrayI; class AliTRDdataArray; +class AliTRDsegmentID; -class AliTRDsegmentArray : public AliTRDsegmentArrayBase { +class AliTRDsegmentArray : public TNamed { public: @@ -25,11 +31,33 @@ class AliTRDsegmentArray : public AliTRDsegmentArrayBase { AliTRDsegmentArray(const char *classname, Int_t n); AliTRDsegmentArray(AliTRDsegmentArray &a); virtual ~AliTRDsegmentArray(); + AliTRDsegmentArray &operator=(const AliTRDsegmentArray &a); + + const AliTRDsegmentID *At(Int_t i) const; + const AliTRDsegmentID *operator[](Int_t i) const; + Bool_t AddSegment(AliTRDsegmentID *segment); + AliTRDsegmentID *AddSegment(Int_t index); + virtual AliTRDsegmentID *NewSegment(); + virtual AliTRDsegmentID *LoadSegment(Int_t index); + virtual AliTRDsegmentID *LoadEntry(Int_t index); + virtual void StoreSegment(Int_t index); + void ClearSegment(Int_t index); + virtual void Copy(TObject &a) const; + virtual Bool_t ConnectTree(const char *treeName); virtual void Delete(); virtual void Delete(const char *) { Delete(); }; + Bool_t MakeArray(Int_t n); + virtual void MakeTree(char *file = 0); + Bool_t MakeDictionary(Int_t size); + + Bool_t SetClass(const char *classname); + + TClass *GetClass() const { return fClass; }; + TTree *GetTree() const { return fTree; }; + virtual Bool_t LoadArray(const Char_t *branchname, TTree *tree = 0); virtual Bool_t StoreArray(const Char_t *branchname, TTree *tree = 0); @@ -38,7 +66,14 @@ class AliTRDsegmentArray : public AliTRDsegmentArrayBase { protected: - ClassDef(AliTRDsegmentArray,1) // TRD detector segment array + TObjArray *fSegment; //! Pointer to an array of pointers to a segment + AliTRDarrayI *fTreeIndex; //! Pointers(index) table + Int_t fNSegment; // Number of segments + TTree *fTree; //! Tree with segment objects + TBranch *fBranch; //! Branchaddress + TClass *fClass; //! Class type of included objects + + ClassDef(AliTRDsegmentArray,2) // TRD detector segment array }; diff --git a/TRD/AliTRDtrigger.cxx b/TRD/AliTRDtrigger.cxx index 2435f75d362..730b6ace947 100644 --- a/TRD/AliTRDtrigger.cxx +++ b/TRD/AliTRDtrigger.cxx @@ -33,8 +33,9 @@ #include "AliLoader.h" #include "AliTRDdigitsManager.h" -#include "AliTRDgeometry.h" #include "AliTRDdataArrayI.h" +#include "AliTRDdataArrayS.h" +#include "AliTRDgeometry.h" #include "AliTRDcalibDB.h" #include "AliTRDrawData.h" #include "AliTRDtrigger.h" @@ -430,20 +431,20 @@ Bool_t AliTRDtrigger::MakeTracklets(Bool_t makeTracks) Int_t nTimeTotal = AliTRDcalibDB::Instance()->GetNumberOfTimeBins(); // Get the digits - fDigits = fDigitsManager->GetDigits(idet); + fDigits = (AliTRDdataArrayS *) fDigitsManager->GetDigits(idet); if (!fDigits) return kFALSE; // This is to take care of switched off super modules if (fDigits->GetNtime() == 0) { continue; } fDigits->Expand(); - fTrack0 = fDigitsManager->GetDictionary(idet,0); + fTrack0 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(idet,0); if (!fTrack0) return kFALSE; fTrack0->Expand(); - fTrack1 = fDigitsManager->GetDictionary(idet,1); + fTrack1 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(idet,1); if (!fTrack1) return kFALSE; fTrack1->Expand(); - fTrack2 = fDigitsManager->GetDictionary(idet,2); + fTrack2 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(idet,2); if (!fTrack2) return kFALSE; fTrack2->Expand(); diff --git a/TRD/AliTRDtrigger.h b/TRD/AliTRDtrigger.h index b74f415338a..c7b71a81e15 100644 --- a/TRD/AliTRDtrigger.h +++ b/TRD/AliTRDtrigger.h @@ -26,6 +26,7 @@ class AliTRDmcm; class AliTRDmodule; class AliTRDdigitsManager; class AliTRDdataArrayI; +class AliTRDdataArrayS; class AliTRDgeometry; class AliTRDtrigger : public TNamed { @@ -85,7 +86,7 @@ class AliTRDtrigger : public TNamed { Int_t fNtracklets; //! Tracklets counter - AliTRDdataArrayI *fDigits; //! Array with digits + AliTRDdataArrayS *fDigits; //! Array with digits AliTRDdataArrayI *fTrack0; //! Track dictionary 0 AliTRDdataArrayI *fTrack1; //! Track dictionary 1 AliTRDdataArrayI *fTrack2; //! Track dictionary 2 @@ -94,7 +95,7 @@ class AliTRDtrigger : public TNamed { TClonesArray *fTracks; //! Array of GTU tracks - ClassDef(AliTRDtrigger,4) // TRD trigger class + ClassDef(AliTRDtrigger,6) // TRD trigger class }; diff --git a/TRD/TRDbaseLinkDef.h b/TRD/TRDbaseLinkDef.h index bfb1f35d882..28bf9be2d4b 100644 --- a/TRD/TRDbaseLinkDef.h +++ b/TRD/TRDbaseLinkDef.h @@ -11,12 +11,13 @@ #pragma link C++ ioctortype TRootIoCtor; #pragma link C++ class AliTRDarrayI+; +#pragma link C++ class AliTRDarrayS+; #pragma link C++ class AliTRDarrayF+; #pragma link C++ class AliTRDsegmentID+; #pragma link C++ class AliTRDsegmentArray+; -#pragma link C++ class AliTRDsegmentArrayBase+; #pragma link C++ class AliTRDdataArray+; #pragma link C++ class AliTRDdataArrayI+; +#pragma link C++ class AliTRDdataArrayS+; #pragma link C++ class AliTRDdataArrayF+; #pragma link C++ class AliTRDSignalIndex+; diff --git a/TRD/libTRDbase.pkg b/TRD/libTRDbase.pkg index 03fa9b8510c..19e0566b961 100644 --- a/TRD/libTRDbase.pkg +++ b/TRD/libTRDbase.pkg @@ -1,11 +1,12 @@ SRCS= AliTRDarrayI.cxx \ + AliTRDarrayS.cxx \ AliTRDarrayF.cxx \ AliTRDsegmentID.cxx \ AliTRDdataArray.cxx \ AliTRDdataArrayI.cxx \ + AliTRDdataArrayS.cxx \ AliTRDdataArrayF.cxx \ AliTRDsegmentArray.cxx \ - AliTRDsegmentArrayBase.cxx \ AliTRDSignalIndex.cxx \ AliTRDgeometry.cxx \ AliTRDdigit.cxx \ -- 2.43.0