///////////////////////////////////////////////////////////////////////////////
#include <TObject.h>
-#include <TROOT.h>
#include <TMath.h>
-#include <TStopwatch.h>
#include <TTreeStream.h>
#include "AliLog.h"
-
+#include "AliTRDcluster.h"
#include "AliTRDgeometry.h"
#include "AliTRDpadPlane.h"
#include "AliTRDchamberTimeBin.h"
//_____________________________________________________________________________
AliTRDchamberTimeBin::AliTRDchamberTimeBin(Int_t plane, Int_t stack, Int_t sector, Double_t z0, Double_t zLength)
:TObject()
- ,fReconstructor(0x0)
+ ,fkReconstructor(NULL)
,fPlane(plane)
,fStack(stack)
,fSector(sector)
//_____________________________________________________________________________
AliTRDchamberTimeBin::AliTRDchamberTimeBin(const AliTRDchamberTimeBin &layer):
TObject()
- ,fReconstructor(layer.fReconstructor)
+ ,fkReconstructor(layer.fkReconstructor)
,fPlane(layer.fPlane)
,fStack(layer.fStack)
,fSector(layer.fSector)
//_____________________________________________________________________________
void AliTRDchamberTimeBin::Clear(const Option_t *)
{
- for(AliTRDcluster **cit = &fClusters[0]; (*cit); cit++){
- if(IsOwner()) delete (*cit);
- (*cit) = NULL;
- }
+ // Reset the Chamber Timebin
+ if(IsOwner())
+ for(Int_t it = 0; it<kMaxClustersLayer; it++)
+ delete fClusters[it];
+ memset(fClusters,0,kMaxClustersLayer*sizeof(fClusters[0]));
fN = 0;
}
// Copy method. Performs a deep copy of all data from this object to object o.
AliTRDchamberTimeBin &layer = (AliTRDchamberTimeBin &)o;
- layer.fReconstructor = fReconstructor;
+ layer.fkReconstructor = fkReconstructor;
layer.fPlane = fPlane;
layer.fStack = fStack;
layer.fSector = fSector;
// Reinitialize all data members from the clusters array
// It has to be used after reading from disk
- fReconstructor = rec;
+ fkReconstructor = rec;
fPlane = AliTRDgeometry::GetLayer(det);
fStack = AliTRDgeometry::GetStack(det);
fSector = AliTRDgeometry::GetSector(det);
// Select clusters that belong to the Stack
Int_t nClStack = 0; // Internal counter
for(Int_t i = 0; i < fN; i++){
- if(fClusters[i]->IsUsed()){
- fClusters[i] = 0x0;
+ if(fClusters[i]->IsUsed() || fClusters[i]->IsShared()){
+ fClusters[i] = NULL;
fIndex[i] = 0xffff;
} else nClStack++;
}
- if(nClStack > kMaxClustersLayer) AliWarning(Form("Number of clusters in stack %d exceed buffer size %d. Truncating.", nClStack, kMaxClustersLayer));
+ if(nClStack > kMaxClustersLayer) AliInfo(Form("Number of clusters in stack %d exceed buffer size %d. Truncating.", nClStack, kMaxClustersLayer));
// Nothing in this time bin. Reset indexes
if(!nClStack){
fN = 0;
- memset(&fPositions[0], 0xff, sizeof(UChar_t) * kMaxRows);
- memset(&fClusters[0], 0x0, sizeof(AliTRDcluster*) * kMaxClustersLayer);
- memset(&fIndex[0], 0xffff, sizeof(UInt_t) * kMaxClustersLayer);
+ memset(&fPositions[0], 0, sizeof(UChar_t) * kMaxRows);
+ memset(&fClusters[0], 0, sizeof(AliTRDcluster*) * kMaxClustersLayer);
+ memset(&fIndex[0], 0, sizeof(UInt_t) * kMaxClustersLayer);
return;
}
nClStack = 0;
// Defining iterators
AliTRDcluster **fcliter = &fClusters[0], **hcliter = &helpCL[0]; UInt_t *finditer = &fIndex[0], *hinditer = &helpInd[0];
- AliTRDcluster *tmpcl = 0x0;
+ AliTRDcluster *tmpcl = NULL;
for(Int_t i = 0; i < TMath::Min(fN, kMaxClustersLayer); i++){
if(!(tmpcl = *(fcliter++))){
finditer++;
}
*(hcliter++) = tmpcl;
*(hinditer++) = *finditer;
- tmpcl = 0x0;
+ tmpcl = NULL;
*(finditer++) = 0xffff;
nClStack++;
}
// Reset Positions array
memset(fPositions, 0, sizeof(UChar_t)*kMaxRows);
AliTRDcluster **cliter = &helpCL[0]; // Declare iterator running over the whole array
+ const AliTRDrecoParam* const recoParam = fkReconstructor->GetRecoParam(); //the dynamic cast in GetRecoParam is slow, so caching the pointer to it
+ Int_t tb(-1);
for(Int_t i = 0; i < fN; i++){
// boundary check
AliTRDcluster *cl = *(cliter++);
UChar_t rowIndex = cl->GetPadRow();
+ if(tb<0) tb=cl->GetLocalTimeBin();
// Insert Leaf
- Int_t pos = FindYPosition(cl->GetY(), rowIndex, i);
- if(pos == -1){ // zbin is empty;
+ Int_t pos = FindYPosition(cl->GetY(), rowIndex, nClStack);
+ if(pos == -2) continue; // zbin error;
+ else if(pos == -1) { // zbin is empty;
Int_t upper = (rowIndex == fNRows - 1) ? nClStack : fPositions[rowIndex + 1];
memmove(fClusters + upper + 1, fClusters + upper, (sizeof(AliTRDcluster *))*(nClStack-upper));
memmove(fIndex + upper + 1, fIndex + upper, (sizeof(UInt_t))*(nClStack-upper));
fX += cl->GetX();
// Debug Streaming
- if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kTracker) >= 3){
- TTreeSRedirector &cstream = *fReconstructor->GetDebugStream(AliTRDReconstructor::kTracker);
+ if(recoParam->GetStreamLevel(AliTRDrecoParam::kTracker) >= 3){
+ AliTRDcluster dcl(*cl);
+ TTreeSRedirector &cstream = *fkReconstructor->GetDebugStream(AliTRDrecoParam::kTracker);
cstream << "BuildIndices"
<< "Plane=" << fPlane
<< "Stack=" << fStack
<< "Sector=" << fSector
<< "Iter=" << iter
- << "C.=" << cl
+ << "C.=" << &dcl
<< "rowIndex=" << rowIndex
<< "\n";
}
// AliInfo("Positions");
// for(int ir=0; ir<fNRows; ir++) printf("pos[%d] %d\n", ir, fPositions[ir]);
-
- fX /= fN;
+ if(nClStack < fN){
+ AliWarning(Form("Found %d out of %d clusters outside in ChamberTimeBin[%02d_%d_%d|%2d]", fN-nClStack, fN, fSector, fStack, fPlane, tb));
+ fN = nClStack;
+ if(!fN){ // Nothing left in this time bin. Reset indexes
+ memset(&fPositions[0], 0, sizeof(UChar_t) * kMaxRows);
+ memset(&fClusters[0], 0, sizeof(AliTRDcluster*) * kMaxClustersLayer);
+ memset(&fIndex[0], 0, sizeof(UInt_t) * kMaxClustersLayer);
+ return;
+ }
+ }
+ if(fN) fX /= fN;
}
//_____________________________________________________________________________
// Index of the nearest left cluster in the StackLayer indexing (-1 if no clusters are found)
//
+ if(z>=fNRows){ // check pad row of cluster
+ AliDebug(1, Form("Row[%2d] outside range [0 %2d] in %02d_%d_%d.", z, fNRows, fSector, fStack, fPlane));
+ return -2;
+ }
Int_t start = fPositions[z]; // starting Position of the bin
Int_t upper = (Int_t)((z != fNRows - 1) ? fPositions[z+1] : nClusters); // ending Position of the bin
Int_t end = upper - 1; // ending Position of the bin
//
Int_t position = FindYPosition(y, z, fN);
- if(position == -1) return position; // bin empty
+ if(position == -2 || position == -1) return position; // bin empty
// FindYPosition always returns the left Neighbor. We don't know if the left or the right Neighbor is nearest
// to the Reference y-position, so test both
Int_t upper = (Int_t)((z < fNRows-1) ? fPositions[z+1] : fN); // ending Position of the bin
}
//_____________________________________________________________________________
-void AliTRDchamberTimeBin::BuildCond(AliTRDcluster *cl, Double_t *cond, UChar_t Layer, Double_t theta, Double_t phi)
+void AliTRDchamberTimeBin::BuildCond(AliTRDcluster * const cl, Double_t *cond, UChar_t Layer, Double_t theta, Double_t phi)
{
// Helper function to calculate the area where to expect a cluster in THIS
// layer.
//End_Html
//
- if(!fReconstructor){
+ if(!fkReconstructor){
AliError("Reconstructor not set.");
return;
}
if(Layer == 0){
cond[0] = cl->GetY(); // center: y-Direction
cond[1] = cl->GetZ(); // center: z-Direction
- cond[2] = fReconstructor->GetRecoParam()->GetMaxPhi() * (cl->GetX() - GetX()) + 1.0; // deviation: y-Direction
- cond[3] = fReconstructor->GetRecoParam()->GetMaxTheta() * (cl->GetX() - GetX()) + 1.0; // deviation: z-Direction
+ cond[2] = fkReconstructor->GetRecoParam()->GetMaxPhi() * (cl->GetX() - GetX()) + 1.0; // deviation: y-Direction
+ cond[3] = fkReconstructor->GetRecoParam()->GetMaxTheta() * (cl->GetX() - GetX()) + 1.0; // deviation: z-Direction
} else {
cond[0] = cl->GetY() + phi * (GetX() - cl->GetX());
cond[1] = cl->GetZ() + theta * (GetX() - cl->GetX());
- cond[2] = fReconstructor->GetRecoParam()->GetRoad0y() + phi;
- cond[3] = fReconstructor->GetRecoParam()->GetRoad0z();
+ cond[2] = fkReconstructor->GetRecoParam()->GetRoad0y() + phi;
+ cond[3] = fkReconstructor->GetRecoParam()->GetRoad0z();
}
}
//_____________________________________________________________________________
-void AliTRDchamberTimeBin::GetClusters(Double_t *cond, Int_t *index, Int_t& ncl, Int_t BufferSize)
+void AliTRDchamberTimeBin::GetClusters(const Double_t * const cond, Int_t *index, Int_t& ncl, Int_t BufferSize)
{
// Finds all clusters situated in this layer inside a rectangle given by the center an ranges.
//
//AliInfo(Form("z[%d] y [%d %d]", z, fPositions[z], upper));
for(Int_t y = fPositions[z]; y < (Int_t)upper; y++){
if(ncl == BufferSize){
- AliWarning("Buffer size riched. Some clusters may be lost.");
+ AliDebug(1, Form("Buffer size [%d] riched. Some clusters may be lost.", BufferSize));
return; //Buffer filled
}
// successfull) by the help of the method FindNearestCluster
- Double_t maxroad = fReconstructor->GetRecoParam()->GetRoad2y();
- Double_t maxroadz = fReconstructor->GetRecoParam()->GetRoad2z();
+ Double_t maxroad = fkReconstructor->GetRecoParam()->GetRoad2y();
+ Double_t maxroadz = fkReconstructor->GetRecoParam()->GetRoad2z();
Int_t index = SearchNearestCluster(cond[0],cond[1],maxroad,maxroadz);
- AliTRDcluster *returnCluster = 0x0;
+ AliTRDcluster *returnCluster = NULL;
if(index != -1) returnCluster = (AliTRDcluster *) fClusters[index];
return returnCluster;
}