ROOT logo
#ifndef ALIITSUCLUSTERIZER_H
#define ALIITSUCLUSTERIZER_H

#include <TBits.h>
#include <TClonesArray.h>
#include "AliITSUClusterPix.h"

class TTree;
class TObjAray;
class AliITSUSegmentationPix;
class AliITSdigit;
class AliCluster;
class AliITSURecoParam;


class AliITSUClusterizer : public TObject 
{
  //
 public:
  enum {kDigitChunkSize=1024, kMaxLabels=20,kMaxLabInCluster=3};
  enum {kMaskNZ=0xff,kMaskNX=0xff,kMaskNPix=0x1ff,kMaskClUse=0x7f};
  //
  AliITSUClusterizer(Int_t nrowInit=0);
  virtual ~AliITSUClusterizer();
  void SetRawData(Bool_t v=kTRUE)                      {fRawData = v;}
  void Clusterize();
  void SetSegmentation(const AliITSUSegmentationPix *segm);
  void SetRecoParam(const AliITSURecoParam* param)     {fRecoParam = param;}
  void SetLayerID(Int_t id)                            {fLayerID = id;}
  void SetVolID(Int_t id)                              {fVolID = id;}
  void SetNRow(Int_t nrow);
  void SetAllowDiagonalClusterization(Bool_t v)        {fAllowDiagonalClusterization = v;}
  void PrepareLorentzAngleCorrection(Double_t bz);
  //
  // interface methods
  void MakeRecPointBranch(TTree */*treeR*/)            {};
  void SetRecPointTreeAddress(TTree */*treeR*/)        {};
  void DigitsToRecPoints(const TObjArray */*digList*/) {};
  
  void SetDigits(const TClonesArray *digits)       {fInputDigits=digits;fInputDigitsReadIndex=0;}
  void SetClusters(TClonesArray *clusters)         {fOutputClusters=clusters;}
  //
  // labeling methods
  void AddLabel(int label);
  void CheckLabels();
  //
 protected: // transient data types
  struct AliITSUClusterizerClusterDigit {
    AliITSUClusterizerClusterDigit *fNext;
    AliITSdigit *fDigit;
  };
  
  struct AliITSUClusterizerClusterCand;
  struct AliITSUClusterizerClusterPart {
    AliITSUClusterizerClusterPart *fNextInRow;
    AliITSUClusterizerClusterPart *fPrevInCluster;
    AliITSUClusterizerClusterPart *fNextInCluster;
    AliITSUClusterizerClusterCand *fParent;
    Int_t fUBegin;
    Int_t fUEnd;
  };
  
  struct AliITSUClusterizerClusterCand {
    AliITSUClusterizerClusterCand  *fNext; // only used for memory management
    AliITSUClusterizerClusterPart  *fFirstPart;
    AliITSUClusterizerClusterDigit *fFirstDigit;
    AliITSUClusterizerClusterDigit *fLastDigit ;
  };

 protected:
  //
  // allocation and deallocation
  AliITSUClusterizerClusterDigit* AllocDigitFreelist();
  AliITSUClusterizerClusterCand*  AllocCand();
  void                            DeallocCand(AliITSUClusterizerClusterCand *cand);
  AliITSUClusterizerClusterPart*  AllocPart();
  void                            DeallocPart(AliITSUClusterizerClusterPart *part) {DeallocParts(part,part); }
  void                            DeallocParts(AliITSUClusterizerClusterPart *first,AliITSUClusterizerClusterPart *last);
  AliITSUClusterizerClusterDigit* AllocDigit();
  void                            DeallocDigit(AliITSUClusterizerClusterDigit *digit) {DeallocDigits(digit,digit);}
  void                            DeallocDigits(AliITSUClusterizerClusterDigit *first,AliITSUClusterizerClusterDigit *last);

  // input "iterator"
  AliITSUClusterizerClusterDigit* NextDigit();
  // output "iterator"
  AliCluster*                     NextCluster() {return (AliCluster*)fOutputClusters->New(fOutputClusters->GetEntriesFast());}
  
  // modifiers
  void SetAllowDiagonalClusterization();

  void AttachDigitToCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterDigit *digit);
  void AttachPartToCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterPart *part);
  void DetachPartFromCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterPart *part);
  void MergeCands(AliITSUClusterizerClusterCand *a,AliITSUClusterizerClusterCand *b);
  void Transform(AliITSUClusterPix *cluster, AliITSUClusterizerClusterCand *cand);
  void CloseCand(AliITSUClusterizerClusterCand *cand);
  void ClosePart(AliITSUClusterizerClusterPart *part);

  void CloseRemainingParts(AliITSUClusterizerClusterPart *part);
  //
 protected:
  //
  Int_t fVolID;                             // Volume id (chip index)
  Bool_t fAllowDiagonalClusterization;      // allow clusters with pixels having common corners only
  const AliITSUSegmentationPix* fSegm;      // Segmentation or local coord calc.
  const AliITSURecoParam*       fRecoParam; // reco params
  //
  // Digit Input
  const TClonesArray *fInputDigits;         // supplied digits
  Int_t         fInputDigitsReadIndex;      // digits counter
  Int_t         fLayerID;                   // current layer id
  //
  Int_t         fCurrLabels[kMaxLabels];    // labels collected for current cluster
  Int_t         fNLabels;                   // number of collected labels
  Bool_t        fRawData;                   // is raw data processed?
  //
  Double_t      fLorAngCorrection;          // Lorentz Angle correction for current layer
  // Cluster Output
  TClonesArray *fOutputClusters;            // external container to store clusters
  //
  // temporary variables
  AliITSUClusterizerClusterDigit *fDigitFreelist    ; //! pool of local digits
  AliITSUClusterizerClusterPart  *fPartFreelist     ; //! pool of unfinished clusters
  AliITSUClusterizerClusterCand  *fCandFreelist     ; //! pool of clusters
  AliITSUClusterizerClusterDigit *fDigitFreelistBptrFirst; //! pointer in the pool
  AliITSUClusterizerClusterDigit *fDigitFreelistBptrLast ; //! pointer in the pool
  AliITSUClusterizerClusterPart  *fPartFreelistBptr ; //! pointer in the pool
  AliITSUClusterizerClusterCand  *fCandFreelistBptr ; //!pointer in the pool
  //
#ifdef _ClusterTopology_
  TBits  fTopology;       // container for the clusters topology pattern
  UShort_t fMinCol;       // min col number
  UShort_t fMinRow;       // min row number
  void   FillClusterTopology(const AliITSUClusterizerClusterCand *cand, AliITSUClusterPix* cl) const;
#endif //_ClusterTopology_
 private:
  AliITSUClusterizer(const AliITSUClusterizer&); //Not implemented
  AliITSUClusterizer& operator=(const AliITSUClusterizer&); //Not implemented
  //
  ClassDef(AliITSUClusterizer,0)
};


//_______________________________________________________________________________
inline void AliITSUClusterizer::DeallocCand(AliITSUClusterizerClusterCand *cand)
{
  // free candidate
  cand->fNext=fCandFreelist;
  fCandFreelist=cand;
}

//_______________________________________________________________________________
inline void AliITSUClusterizer::DeallocParts(AliITSUClusterizerClusterPart *first,AliITSUClusterizerClusterPart *last)
{
  // free cluster part
  last->fNextInRow=fPartFreelist;
  fPartFreelist=first;
}

//_______________________________________________________________________________
inline AliITSUClusterizer::AliITSUClusterizerClusterDigit* AliITSUClusterizer::AllocDigit()
{
  // allocate digits
  if (!fDigitFreelist) fDigitFreelist = AllocDigitFreelist();
  AliITSUClusterizerClusterDigit *digit = fDigitFreelist;
  fDigitFreelist = fDigitFreelist->fNext;
  return digit;
}

//_______________________________________________________________________________
inline AliITSUClusterizer::AliITSUClusterizerClusterPart* AliITSUClusterizer::AllocPart()
{
  // allocate cluster part
  AliITSUClusterizerClusterPart *part=fPartFreelist;
  fPartFreelist=fPartFreelist->fNextInRow;
  return part;
}

//_______________________________________________________________________________
inline AliITSUClusterizer::AliITSUClusterizerClusterCand* AliITSUClusterizer::AllocCand()
{
  // allocate cluster 
  AliITSUClusterizerClusterCand *cand=fCandFreelist;
  fCandFreelist=fCandFreelist->fNext;
  return cand;
}

//_______________________________________________________________________________
inline void AliITSUClusterizer::DeallocDigits(AliITSUClusterizerClusterDigit *first, AliITSUClusterizerClusterDigit *last) 
{
  // free digit
  last->fNext = fDigitFreelist;
  fDigitFreelist = first;
}

//_______________________________________________________________________________
inline void AliITSUClusterizer::AttachDigitToCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterDigit *digit) 
{
  // attach digit
  digit->fNext = cand->fFirstDigit;
  cand->fFirstDigit = digit;
}

//_______________________________________________________________________________
inline void AliITSUClusterizer::DetachPartFromCand(AliITSUClusterizerClusterCand *cand,AliITSUClusterizerClusterPart *part) 
{
  // remove cluster part 
  if (part->fPrevInCluster)    part->fPrevInCluster->fNextInCluster=part->fNextInCluster;
  else                         cand->fFirstPart=part->fNextInCluster;
  if (part->fNextInCluster)    part->fNextInCluster->fPrevInCluster=part->fPrevInCluster;
}

//______________________________________________________________________________
inline void AliITSUClusterizer::AddLabel(int label)
{
  // add new label
  if (fNLabels==kMaxLabels) return;
  for (int i=fNLabels;i--;) if (fCurrLabels[i]==label) return;
  fCurrLabels[fNLabels++] = label;
}


#endif

 AliITSUClusterizer.h:1
 AliITSUClusterizer.h:2
 AliITSUClusterizer.h:3
 AliITSUClusterizer.h:4
 AliITSUClusterizer.h:5
 AliITSUClusterizer.h:6
 AliITSUClusterizer.h:7
 AliITSUClusterizer.h:8
 AliITSUClusterizer.h:9
 AliITSUClusterizer.h:10
 AliITSUClusterizer.h:11
 AliITSUClusterizer.h:12
 AliITSUClusterizer.h:13
 AliITSUClusterizer.h:14
 AliITSUClusterizer.h:15
 AliITSUClusterizer.h:16
 AliITSUClusterizer.h:17
 AliITSUClusterizer.h:18
 AliITSUClusterizer.h:19
 AliITSUClusterizer.h:20
 AliITSUClusterizer.h:21
 AliITSUClusterizer.h:22
 AliITSUClusterizer.h:23
 AliITSUClusterizer.h:24
 AliITSUClusterizer.h:25
 AliITSUClusterizer.h:26
 AliITSUClusterizer.h:27
 AliITSUClusterizer.h:28
 AliITSUClusterizer.h:29
 AliITSUClusterizer.h:30
 AliITSUClusterizer.h:31
 AliITSUClusterizer.h:32
 AliITSUClusterizer.h:33
 AliITSUClusterizer.h:34
 AliITSUClusterizer.h:35
 AliITSUClusterizer.h:36
 AliITSUClusterizer.h:37
 AliITSUClusterizer.h:38
 AliITSUClusterizer.h:39
 AliITSUClusterizer.h:40
 AliITSUClusterizer.h:41
 AliITSUClusterizer.h:42
 AliITSUClusterizer.h:43
 AliITSUClusterizer.h:44
 AliITSUClusterizer.h:45
 AliITSUClusterizer.h:46
 AliITSUClusterizer.h:47
 AliITSUClusterizer.h:48
 AliITSUClusterizer.h:49
 AliITSUClusterizer.h:50
 AliITSUClusterizer.h:51
 AliITSUClusterizer.h:52
 AliITSUClusterizer.h:53
 AliITSUClusterizer.h:54
 AliITSUClusterizer.h:55
 AliITSUClusterizer.h:56
 AliITSUClusterizer.h:57
 AliITSUClusterizer.h:58
 AliITSUClusterizer.h:59
 AliITSUClusterizer.h:60
 AliITSUClusterizer.h:61
 AliITSUClusterizer.h:62
 AliITSUClusterizer.h:63
 AliITSUClusterizer.h:64
 AliITSUClusterizer.h:65
 AliITSUClusterizer.h:66
 AliITSUClusterizer.h:67
 AliITSUClusterizer.h:68
 AliITSUClusterizer.h:69
 AliITSUClusterizer.h:70
 AliITSUClusterizer.h:71
 AliITSUClusterizer.h:72
 AliITSUClusterizer.h:73
 AliITSUClusterizer.h:74
 AliITSUClusterizer.h:75
 AliITSUClusterizer.h:76
 AliITSUClusterizer.h:77
 AliITSUClusterizer.h:78
 AliITSUClusterizer.h:79
 AliITSUClusterizer.h:80
 AliITSUClusterizer.h:81
 AliITSUClusterizer.h:82
 AliITSUClusterizer.h:83
 AliITSUClusterizer.h:84
 AliITSUClusterizer.h:85
 AliITSUClusterizer.h:86
 AliITSUClusterizer.h:87
 AliITSUClusterizer.h:88
 AliITSUClusterizer.h:89
 AliITSUClusterizer.h:90
 AliITSUClusterizer.h:91
 AliITSUClusterizer.h:92
 AliITSUClusterizer.h:93
 AliITSUClusterizer.h:94
 AliITSUClusterizer.h:95
 AliITSUClusterizer.h:96
 AliITSUClusterizer.h:97
 AliITSUClusterizer.h:98
 AliITSUClusterizer.h:99
 AliITSUClusterizer.h:100
 AliITSUClusterizer.h:101
 AliITSUClusterizer.h:102
 AliITSUClusterizer.h:103
 AliITSUClusterizer.h:104
 AliITSUClusterizer.h:105
 AliITSUClusterizer.h:106
 AliITSUClusterizer.h:107
 AliITSUClusterizer.h:108
 AliITSUClusterizer.h:109
 AliITSUClusterizer.h:110
 AliITSUClusterizer.h:111
 AliITSUClusterizer.h:112
 AliITSUClusterizer.h:113
 AliITSUClusterizer.h:114
 AliITSUClusterizer.h:115
 AliITSUClusterizer.h:116
 AliITSUClusterizer.h:117
 AliITSUClusterizer.h:118
 AliITSUClusterizer.h:119
 AliITSUClusterizer.h:120
 AliITSUClusterizer.h:121
 AliITSUClusterizer.h:122
 AliITSUClusterizer.h:123
 AliITSUClusterizer.h:124
 AliITSUClusterizer.h:125
 AliITSUClusterizer.h:126
 AliITSUClusterizer.h:127
 AliITSUClusterizer.h:128
 AliITSUClusterizer.h:129
 AliITSUClusterizer.h:130
 AliITSUClusterizer.h:131
 AliITSUClusterizer.h:132
 AliITSUClusterizer.h:133
 AliITSUClusterizer.h:134
 AliITSUClusterizer.h:135
 AliITSUClusterizer.h:136
 AliITSUClusterizer.h:137
 AliITSUClusterizer.h:138
 AliITSUClusterizer.h:139
 AliITSUClusterizer.h:140
 AliITSUClusterizer.h:141
 AliITSUClusterizer.h:142
 AliITSUClusterizer.h:143
 AliITSUClusterizer.h:144
 AliITSUClusterizer.h:145
 AliITSUClusterizer.h:146
 AliITSUClusterizer.h:147
 AliITSUClusterizer.h:148
 AliITSUClusterizer.h:149
 AliITSUClusterizer.h:150
 AliITSUClusterizer.h:151
 AliITSUClusterizer.h:152
 AliITSUClusterizer.h:153
 AliITSUClusterizer.h:154
 AliITSUClusterizer.h:155
 AliITSUClusterizer.h:156
 AliITSUClusterizer.h:157
 AliITSUClusterizer.h:158
 AliITSUClusterizer.h:159
 AliITSUClusterizer.h:160
 AliITSUClusterizer.h:161
 AliITSUClusterizer.h:162
 AliITSUClusterizer.h:163
 AliITSUClusterizer.h:164
 AliITSUClusterizer.h:165
 AliITSUClusterizer.h:166
 AliITSUClusterizer.h:167
 AliITSUClusterizer.h:168
 AliITSUClusterizer.h:169
 AliITSUClusterizer.h:170
 AliITSUClusterizer.h:171
 AliITSUClusterizer.h:172
 AliITSUClusterizer.h:173
 AliITSUClusterizer.h:174
 AliITSUClusterizer.h:175
 AliITSUClusterizer.h:176
 AliITSUClusterizer.h:177
 AliITSUClusterizer.h:178
 AliITSUClusterizer.h:179
 AliITSUClusterizer.h:180
 AliITSUClusterizer.h:181
 AliITSUClusterizer.h:182
 AliITSUClusterizer.h:183
 AliITSUClusterizer.h:184
 AliITSUClusterizer.h:185
 AliITSUClusterizer.h:186
 AliITSUClusterizer.h:187
 AliITSUClusterizer.h:188
 AliITSUClusterizer.h:189
 AliITSUClusterizer.h:190
 AliITSUClusterizer.h:191
 AliITSUClusterizer.h:192
 AliITSUClusterizer.h:193
 AliITSUClusterizer.h:194
 AliITSUClusterizer.h:195
 AliITSUClusterizer.h:196
 AliITSUClusterizer.h:197
 AliITSUClusterizer.h:198
 AliITSUClusterizer.h:199
 AliITSUClusterizer.h:200
 AliITSUClusterizer.h:201
 AliITSUClusterizer.h:202
 AliITSUClusterizer.h:203
 AliITSUClusterizer.h:204
 AliITSUClusterizer.h:205
 AliITSUClusterizer.h:206
 AliITSUClusterizer.h:207
 AliITSUClusterizer.h:208
 AliITSUClusterizer.h:209
 AliITSUClusterizer.h:210
 AliITSUClusterizer.h:211
 AliITSUClusterizer.h:212
 AliITSUClusterizer.h:213
 AliITSUClusterizer.h:214
 AliITSUClusterizer.h:215
 AliITSUClusterizer.h:216
 AliITSUClusterizer.h:217
 AliITSUClusterizer.h:218
 AliITSUClusterizer.h:219
 AliITSUClusterizer.h:220
 AliITSUClusterizer.h:221
 AliITSUClusterizer.h:222
 AliITSUClusterizer.h:223
 AliITSUClusterizer.h:224