+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
+{
+ //
+ // Look for 5 pad cluster with minimum in the middle
+ // Gives back the ratio
+ //
+
+ if (ThisMax.col >= fColMax - 3) return kFALSE;
+ Float_t gain;
+ Float_t onlcf;
+ if (ThisMax.col < fColMax - 5){
+ gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col+4,ThisMax.row);
+ onlcf = fCalOnlGainROC ? fCalOnlGainROC->GetGainCorrectionFactor(ThisMax.row,ThisMax.col+4) : 1;
+ if (fDigits->GetData(ThisMax.row, ThisMax.col+4, ThisMax.time) - fBaseline >= fSigThresh * gain * onlcf)
+ return kFALSE;
+ }
+ if (ThisMax.col > 1) {
+ gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col-2,ThisMax.row);
+ onlcf = fCalOnlGainROC ? fCalOnlGainROC->GetGainCorrectionFactor(ThisMax.row,ThisMax.col-2) : 1;
+ if (fDigits->GetData(ThisMax.row, ThisMax.col-2, ThisMax.time) - fBaseline >= fSigThresh * gain * onlcf)
+ return kFALSE;
+ }
+
+ const Float_t kEpsilon = 0.01;
+ Double_t padSignal[5] = {ThisMax.signals[0], ThisMax.signals[1], ThisMax.signals[2],
+ NeighbourMax.signals[1], NeighbourMax.signals[2]};
+
+ // Unfold the two maxima and set the signal on
+ // the overlapping pad to the ratio
+ Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
+ ThisMax.signals[2] = ThisMax.signals[2]*ratio + 0.5f;
+ NeighbourMax.signals[0] = NeighbourMax.signals[0]*(1-ratio) + 0.5f;
+ ThisMax.fivePad=kTRUE;
+ NeighbourMax.fivePad=kTRUE;
+ return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
+{
+ //
+ // Creates a cluster at the given position and saves it in RecPoints
+ //
+
+ Int_t nPadCount = 1;
+ Short_t signals[7] = { 0, 0, (Short_t)Max.signals[0], (Short_t)Max.signals[1], (Short_t)Max.signals[2], 0, 0 };
+ if(!fReconstructor->IsHLT()) CalcAdditionalInfo(Max, signals, nPadCount);
+
+ AliTRDcluster cluster(fDet, ((UChar_t) Max.col), ((UChar_t) Max.row), ((UChar_t) Max.time), signals, fVolid);
+ cluster.SetNPads(nPadCount);
+ cluster.SetQ(Max.signals[0]+Max.signals[1]+Max.signals[2]);
+ if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
+ else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
+ else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
+
+ cluster.SetFivePad(Max.fivePad);
+ // set pads status for the cluster
+ UChar_t maskPosition = GetCorruption(Max.padStatus);
+ if (maskPosition) {
+ cluster.SetPadMaskedPosition(maskPosition);
+ cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
+ }
+ cluster.SetXcorr(fReconstructor->UseClusterRadialCorrection());
+
+ // Transform the local cluster coordinates into calibrated
+ // space point positions defined in the local tracking system.
+ // Here the calibration for T0, Vdrift and ExB is applied as well.
+ if(!TestBit(kSkipTrafo)) if(!fTransform->Transform(&cluster)) return;
+ // Store raw signals in cluster. This MUST be called after position reconstruction !
+ // Xianguo Lu and Alex Bercuci 19.03.2012
+ if(TestBit(kRawSignal) && fDigitsRaw){
+ Float_t tmp(0.), kMaxShortVal(32767.); // protect against data overflow due to wrong gain calibration
+ Short_t rawSignal[7] = {0};
+ for(Int_t ipad(Max.col-3), iRawId(0); ipad<=Max.col+3; ipad++, iRawId++){
+ if(ipad<0 || ipad>=fColMax) continue;
+ if(!fCalOnlGainROC){
+ rawSignal[iRawId] = fDigitsRaw->GetData(Max.row, ipad, Max.time);
+ continue;
+ }
+ // Deconvolute online gain calibration when available
+ // Alex Bercuci 27.04.2012
+ tmp = (fDigitsRaw->GetData(Max.row, ipad, Max.time) - fBaseline)/fCalOnlGainROC->GetGainCorrectionFactor(Max.row, ipad) + 0.5f;
+ rawSignal[iRawId] = (Short_t)TMath::Min(tmp, kMaxShortVal);
+ }
+ cluster.SetSignals(rawSignal, kTRUE);
+ }
+ // Temporarily store the Max.Row, column and time bin of the center pad
+ // Used to later on assign the track indices
+ cluster.SetLabel(Max.row, 0);
+ cluster.SetLabel(Max.col, 1);
+ cluster.SetLabel(Max.time,2);
+
+ //needed for HLT reconstruction
+ AddClusterToArray(&cluster);
+
+ // Store the index of the first cluster in the current ROC
+ if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
+
+ fNoOfClusters++;
+ fClusterROC++;
+}
+
+//_____________________________________________________________________________
+void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
+{
+// Calculate number of pads/cluster and
+// ADC signals at position 0, 1, 5 and 6
+
+ Float_t tmp(0.), kMaxShortVal(32767.); // protect against data overflow due to wrong gain calibration
+ Float_t gain(1.); Float_t onlcf(1.); Short_t signal(0);
+ // Store the amplitudes of the pads in the cluster for later analysis
+ // and check whether one of these pads is masked in the database
+ signals[3]=Max.signals[1];
+ Int_t ipad(1), jpad(0);
+ // Look to the right
+ while((jpad = Max.col-ipad)){
+ if(!(signal = fDigits->GetData(Max.row, jpad, Max.time))) break; // empty digit !
+ gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(jpad, Max.row);
+ onlcf = fCalOnlGainROC ? fCalOnlGainROC->GetGainCorrectionFactor(Max.row,jpad) : 1;
+ tmp = (signal - fBaseline) / (onlcf * gain) + 0.5f;
+ signal = (Short_t)TMath::Min(tmp, kMaxShortVal);
+ if(signal<fSigThresh) break; // signal under threshold
+ nPadCount++;
+ if(ipad<=3) signals[3 - ipad] = signal;
+ ipad++;
+ }
+ ipad=1;
+ // Look to the left
+ while((jpad = Max.col+ipad)<fColMax){
+ if(!(signal = fDigits->GetData(Max.row, jpad, Max.time))) break; // empty digit !
+ gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(jpad, Max.row);
+ onlcf = fCalOnlGainROC ? fCalOnlGainROC->GetGainCorrectionFactor(Max.row,jpad) : 1;
+ tmp = (signal - fBaseline) / (onlcf * gain) + 0.5f;
+ signal = (Short_t)TMath::Min(tmp, kMaxShortVal);
+ if(signal<fSigThresh) break; // signal under threshold
+ nPadCount++;
+ if(ipad<=3) signals[3 + ipad] = signal;
+ ipad++;
+ }
+
+ AliDebug(4, Form("Signals[%3d %3d %3d %3d %3d %3d %3d] Npads[%d]."
+ , signals[0], signals[1], signals[2], signals[3], signals[4], signals[5], signals[6], nPadCount));
+}
+
+//_____________________________________________________________________________
+void AliTRDclusterizer::AddClusterToArray(AliTRDcluster* cluster)
+{
+ //
+ // Add a cluster to the array
+ //
+
+ Int_t n = RecPoints()->GetEntriesFast();
+ if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
+ new((*RecPoints())[n]) AliTRDcluster(*cluster);
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::AddLabels()
+{
+ //
+ // Add the track indices to the found clusters
+ //
+
+ const Int_t kNclus = 3;
+ const Int_t kNdict = AliTRDdigitsManager::kNDict;
+ const Int_t kNtrack = kNdict * kNclus;
+
+ Int_t iClusterROC = 0;
+
+ Int_t row = 0;
+ Int_t col = 0;
+ Int_t time = 0;
+ Int_t iPad = 0;
+
+ // Temporary array to collect the track indices
+ Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
+
+ // Loop through the dictionary arrays one-by-one
+ // to keep memory consumption low
+ AliTRDarrayDictionary *tracksIn(NULL); //mod
+ for (Int_t iDict = 0; iDict < kNdict; iDict++) {
+
+ // tracksIn should be expanded beforehand!
+ tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);