2 /**************************************************************************
3 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
21 // TRD cluster finder //
23 ///////////////////////////////////////////////////////////////////////////////
29 #include <TObjArray.h>
31 #include "AliRunLoader.h"
32 #include "AliLoader.h"
33 #include "AliRawReader.h"
35 #include "AliAlignObj.h"
37 #include "AliTRDclusterizer.h"
38 #include "AliTRDcluster.h"
39 #include "AliTRDgeometry.h"
40 #include "AliTRDdataArrayF.h"
41 #include "AliTRDdataArrayI.h"
42 #include "AliTRDdataArrayS.h"
43 #include "AliTRDdigitsManager.h"
44 #include "AliTRDrawData.h"
45 #include "AliTRDcalibDB.h"
46 #include "AliTRDSimParam.h"
47 #include "AliTRDRecParam.h"
48 #include "AliTRDCommonParam.h"
49 #include "AliTRDtransform.h"
50 #include "AliTRDSignalIndex.h"
51 #include "AliTRDRawStream.h"
52 #include "AliTRDRawStreamV2.h"
53 #include "AliTRDfeeParam.h"
55 #include "Cal/AliTRDCalROC.h"
56 #include "Cal/AliTRDCalDet.h"
58 ClassImp(AliTRDclusterizer)
60 //_____________________________________________________________________________
61 AliTRDclusterizer::AliTRDclusterizer()
74 // AliTRDclusterizer default constructor
77 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
81 //_____________________________________________________________________________
82 AliTRDclusterizer::AliTRDclusterizer(const Text_t *name, const Text_t *title)
87 ,fDigitsManager(new AliTRDdigitsManager())
92 ,fTransform(new AliTRDtransform(0))
95 // AliTRDclusterizer constructor
98 fDigitsManager->CreateArrays();
100 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
104 //_____________________________________________________________________________
105 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
110 ,fDigitsManager(NULL)
114 ,fIndexesMaxima(NULL)
118 // AliTRDclusterizer copy constructor
123 //_____________________________________________________________________________
124 AliTRDclusterizer::~AliTRDclusterizer()
127 // AliTRDclusterizer destructor
132 fRecPoints->Delete();
138 delete fDigitsManager;
139 fDigitsManager = NULL;
150 delete fIndexesMaxima;
151 fIndexesMaxima = NULL;
162 //_____________________________________________________________________________
163 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
166 // Assignment operator
171 ((AliTRDclusterizer &) c).Copy(*this);
177 //_____________________________________________________________________________
178 void AliTRDclusterizer::Copy(TObject &c) const
184 ((AliTRDclusterizer &) c).fClusterTree = NULL;
185 ((AliTRDclusterizer &) c).fRecPoints = NULL;
186 ((AliTRDclusterizer &) c).fDigitsManager = NULL;
187 ((AliTRDclusterizer &) c).fAddLabels = fAddLabels;
188 ((AliTRDclusterizer &) c).fRawVersion = fRawVersion;
189 ((AliTRDclusterizer &) c).fIndexesOut = NULL;
190 ((AliTRDclusterizer &) c).fIndexesMaxima = NULL;
191 ((AliTRDclusterizer &) c).fTransform = NULL;
195 //_____________________________________________________________________________
196 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
199 // Opens the AliROOT file. Output and input are in the same file
202 TString evfoldname = AliConfig::GetDefaultEventFolderName();
203 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
206 fRunLoader = AliRunLoader::Open(name);
210 AliError(Form("Can not open session for file %s.",name));
221 //_____________________________________________________________________________
222 Bool_t AliTRDclusterizer::OpenOutput()
225 // Open the output file
228 TObjArray *ioArray = 0;
230 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
231 loader->MakeTree("R");
233 fClusterTree = loader->TreeR();
234 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
240 //_____________________________________________________________________________
241 Bool_t AliTRDclusterizer::OpenOutput(TTree *clusterTree)
244 // Connect the output tree
247 TObjArray *ioArray = 0;
249 fClusterTree = clusterTree;
250 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
256 //_____________________________________________________________________________
257 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
260 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
263 // Import the Trees for the event nEvent in the file
264 fRunLoader->GetEvent(nEvent);
270 //_____________________________________________________________________________
271 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
274 // Fills TRDcluster branch in the tree with the clusters
275 // found in detector = det. For det=-1 writes the tree.
279 (det >= AliTRDgeometry::Ndet())) {
280 AliError(Form("Unexpected detector index %d.\n",det));
284 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
286 TObjArray *ioArray = 0;
287 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
291 (det < AliTRDgeometry::Ndet())) {
293 Int_t nRecPoints = RecPoints()->GetEntriesFast();
294 TObjArray *detRecPoints = new TObjArray(400);
296 for (Int_t i = 0; i < nRecPoints; i++) {
297 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
298 if (det == c->GetDetector()) {
299 detRecPoints->AddLast(c);
302 AliError(Form("Attempt to write a cluster with unexpected detector index: got=%d expected=%d\n"
308 branch->SetAddress(&detRecPoints);
309 fClusterTree->Fill();
319 AliInfo(Form("Writing the cluster tree %s for event %d."
320 ,fClusterTree->GetName(),fRunLoader->GetEventNumber()));
324 branch->SetAddress(&fRecPoints);
326 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
327 loader->WriteRecPoints("OVERWRITE");
332 AliError("Cluster tree does not exist. Cannot write clusters.\n");
341 AliError(Form("Unexpected detector index %d.\n",det));
347 //_____________________________________________________________________________
348 void AliTRDclusterizer::ResetHelperIndexes(AliTRDSignalIndex *indexesIn)
351 // Reset the helper indexes
356 // carefull here - we assume that only row number may change - most probable
357 if (indexesIn->GetNrow() <= fIndexesOut->GetNrow())
358 fIndexesOut->ResetContent();
360 fIndexesOut->ResetContentConditional(indexesIn->GetNrow()
361 , indexesIn->GetNcol()
362 , indexesIn->GetNtime());
366 fIndexesOut = new AliTRDSignalIndex(indexesIn->GetNrow()
367 , indexesIn->GetNcol()
368 , indexesIn->GetNtime());
373 // carefull here - we assume that only row number may change - most probable
374 if (indexesIn->GetNrow() <= fIndexesMaxima->GetNrow())
376 fIndexesMaxima->ResetContent();
380 fIndexesMaxima->ResetContentConditional(indexesIn->GetNrow()
381 , indexesIn->GetNcol()
382 , indexesIn->GetNtime());
387 fIndexesMaxima = new AliTRDSignalIndex(indexesIn->GetNrow()
388 , indexesIn->GetNcol()
389 , indexesIn->GetNtime());
394 //_____________________________________________________________________________
395 Bool_t AliTRDclusterizer::ReadDigits()
398 // Reads the digits arrays from the input aliroot file
402 AliError("No run loader available");
406 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
407 if (!loader->TreeD()) {
408 loader->LoadDigits();
411 // Read in the digit arrays
412 return (fDigitsManager->ReadDigits(loader->TreeD()));
416 //_____________________________________________________________________________
417 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
420 // Reads the digits arrays from the input tree
423 // Read in the digit arrays
424 return (fDigitsManager->ReadDigits(digitsTree));
428 //_____________________________________________________________________________
429 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
432 // Reads the digits arrays from the ddl file
436 fDigitsManager = raw.Raw2Digits(rawReader);
442 //_____________________________________________________________________________
443 Bool_t AliTRDclusterizer::MakeClusters()
446 // Creates clusters from digits
449 // Propagate info from the digits manager
450 if (fAddLabels == kTRUE)
452 fAddLabels = fDigitsManager->UsesDictionaries();
455 Bool_t fReturn = kTRUE;
456 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++)
459 AliTRDdataArrayS *digitsIn = (AliTRDdataArrayS *) fDigitsManager->GetDigits(i);
460 // This is to take care of switched off super modules
461 if (!digitsIn->HasData())
466 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
467 if (indexes->IsAllocated() == kFALSE)
469 fDigitsManager->BuildIndexes(i);
473 if (indexes->HasEntry())
477 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++)
479 AliTRDdataArrayI *tracksIn = 0;
480 tracksIn = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(i,iDict);
484 fR = MakeClusters(i);
485 fReturn = fR && fReturn;
494 // No compress just remove
495 fDigitsManager->RemoveDigits(i);
496 fDigitsManager->RemoveDictionaries(i);
497 fDigitsManager->ClearIndexes(i);
505 //_____________________________________________________________________________
506 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
509 // Creates clusters from raw data
512 AliTRDdataArrayS *digits = 0;
513 AliTRDdataArrayI *track0 = 0;
514 AliTRDdataArrayI *track1 = 0;
515 AliTRDdataArrayI *track2 = 0;
517 AliTRDSignalIndex *indexes = 0;
519 // Create the digits manager
522 fDigitsManager = new AliTRDdigitsManager();
523 fDigitsManager->CreateArrays();
526 AliTRDRawStreamV2 input(rawReader);
527 input.SetRawVersion( fRawVersion );
530 AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
532 // Loop through the digits
539 det = input.GetDet();
546 digits = (AliTRDdataArrayS *) fDigitsManager->GetDigits(lastdet);
547 Bool_t iclusterBranch = kFALSE;
548 if (indexes->HasEntry())
549 iclusterBranch = MakeClusters(lastdet);
550 if (iclusterBranch == kFALSE)
552 WriteClusters(lastdet);
559 fDigitsManager->RemoveDigits(lastdet);
560 fDigitsManager->RemoveDictionaries(lastdet);
561 fDigitsManager->ClearIndexes(lastdet);
566 // Add a container for the digits of this detector
567 digits = (AliTRDdataArrayS *) fDigitsManager->GetDigits(det);
568 track0 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,0);
569 track1 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,1);
570 track2 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,2);
572 // Allocate memory space for the digits buffer
573 if (!digits->HasData())
575 //AliDebug(5, Form("Alloc digits for det %d", det));
576 digits->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
577 track0->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
578 track1->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
579 track2->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
582 indexes = fDigitsManager->GetIndexes(det);
583 indexes->SetSM(input.GetSM());
584 indexes->SetStack(input.GetStack());
585 indexes->SetLayer(input.GetLayer());
586 indexes->SetDetNumber(det);
587 if (indexes->IsAllocated() == kFALSE)
589 indexes->Allocate(input.GetMaxRow(), input.GetMaxCol(), input.GetNumberOfTimeBins());
594 for (it = 0; it < 3; it++)
596 if ( input.GetTimeBin() + it < input.GetNumberOfTimeBins() )
598 if (input.GetSignals()[it] > 0)
600 digits->SetDataUnchecked(input.GetRow(), input.GetCol(),
601 input.GetTimeBin() + it, input.GetSignals()[it]);
603 indexes->AddIndexTBin(input.GetRow(), input.GetCol(),
604 input.GetTimeBin() + it);
605 track0->SetDataUnchecked(input.GetRow(), input.GetCol(),
606 input.GetTimeBin() + it, 0);
607 track1->SetDataUnchecked(input.GetRow(), input.GetCol(),
608 input.GetTimeBin() + it, 0);
609 track2->SetDataUnchecked(input.GetRow(), input.GetCol(),
610 input.GetTimeBin() + it, 0);
619 Bool_t iclusterBranch = kFALSE;
620 if (indexes->HasEntry())
622 iclusterBranch = MakeClusters(lastdet);
624 if (iclusterBranch == kFALSE)
626 WriteClusters(lastdet);
629 //MakeClusters(lastdet);
632 fDigitsManager->RemoveDigits(lastdet);
633 fDigitsManager->RemoveDictionaries(lastdet);
634 fDigitsManager->ClearIndexes(lastdet);
638 delete fDigitsManager;
639 fDigitsManager = NULL;
644 //_____________________________________________________________________________
645 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
648 // Creates clusters from raw data
651 // Create the digits manager
654 fDigitsManager = new AliTRDdigitsManager();
655 fDigitsManager->CreateArrays();
658 fDigitsManager->SetUseDictionaries(fAddLabels);
660 AliTRDRawStreamV2 input(rawReader);
661 input.SetRawVersion( fRawVersion );
664 AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
667 while ((det = input.NextChamber(fDigitsManager)) >= 0)
669 Bool_t iclusterBranch = kFALSE;
670 if (fDigitsManager->GetIndexes(det)->HasEntry())
672 iclusterBranch = MakeClusters(det);
674 if (iclusterBranch == kFALSE)
679 fDigitsManager->RemoveDigits(det);
680 fDigitsManager->RemoveDictionaries(det);
681 fDigitsManager->ClearIndexes(det);
684 delete fDigitsManager;
685 fDigitsManager = NULL;
690 //_____________________________________________________________________________
691 Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
694 // Generates the cluster.
698 // digits should be expanded beforehand!
699 // digitsIn->Expand();
700 AliTRDdataArrayS *digitsIn = (AliTRDdataArrayS *) fDigitsManager->GetDigits(det);
702 // This is to take care of switched off super modules
703 if (!digitsIn->HasData())
708 AliTRDSignalIndex *indexesIn = fDigitsManager->GetIndexes(det);
709 if (indexesIn->IsAllocated() == kFALSE)
711 AliError("Indexes do not exist!");
715 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
718 AliFatal("No AliTRDcalibDB instance available\n");
722 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
725 AliError("No AliTRDRecParam instance available\n");
730 // There is no ADC threshold anymore, and simParam should not be used in clusterizer. KO
731 Float_t adcThreshold = 0;
733 // Threshold value for the maximum
734 Float_t maxThresh = recParam->GetClusMaxThresh();
735 // Threshold value for the digit signal
736 Float_t sigThresh = recParam->GetClusSigThresh();
738 // Iteration limit for unfolding procedure
739 const Float_t kEpsilon = 0.01;
740 const Int_t kNclus = 3;
741 const Int_t kNsig = 5;
744 Double_t ratioLeft = 1.0;
745 Double_t ratioRight = 1.0;
747 Double_t padSignal[kNsig];
748 Double_t clusterSignal[kNclus];
750 Int_t icham = indexesIn->GetChamber();
751 Int_t iplan = indexesIn->GetPlane();
752 Int_t isect = indexesIn->GetSM();
754 // Start clustering in the chamber
756 Int_t idet = AliTRDgeometry::GetDetector(iplan,icham,isect);
759 AliError("Strange Detector number Missmatch!");
763 // TRD space point transformation
764 fTransform->SetDetector(det);
766 Int_t ilayer = AliGeomManager::kTRD1 + iplan;
767 Int_t imodule = icham + AliTRDgeometry::Ncham() * isect;
768 UShort_t volid = AliGeomManager::LayerToVolUID(ilayer,imodule);
770 Int_t nColMax = digitsIn->GetNcol();
771 Int_t nTimeTotal = digitsIn->GetNtime();
773 // Detector wise calibration object for the gain factors
774 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
775 // Calibration object with pad wise values for the gain factors
776 AliTRDCalROC *calGainFactorROC = calibration->GetGainFactorROC(idet);
777 // Calibration value for chamber wise gain factor
778 Float_t calGainFactorDetValue = calGainFactorDet->GetValue(idet);
782 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow()
784 ,digitsIn->GetNtime());
786 ResetHelperIndexes(indexesIn);
788 // Apply the gain and the tail cancelation via digital filter
789 TailCancelation(digitsIn
796 ,calGainFactorDetValue);
803 fIndexesOut->ResetCounters();
804 while (fIndexesOut->NextRCTbinIndex(row, col, time))
807 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col,time));
809 // Look for the maximum
810 if (signalM >= maxThresh)
813 if (col + 1 >= nColMax || col-1 < 0)
816 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time));
817 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
819 if ((TMath::Abs(signalL) <= signalM) &&
820 (TMath::Abs(signalR) < signalM))
822 if ((TMath::Abs(signalL) >= sigThresh) ||
823 (TMath::Abs(signalR) >= sigThresh))
825 // Maximum found, mark the position by a negative signal
826 digitsOut->SetDataUnchecked(row,col,time,-signalM);
827 fIndexesMaxima->AddIndexTBin(row,col,time);
835 // The index to the first cluster of a given ROC
836 Int_t firstClusterROC = -1;
837 // The number of cluster in a given ROC
838 Int_t nClusterROC = 0;
840 // Now check the maxima and calculate the cluster position
841 fIndexesMaxima->ResetCounters();
842 while (fIndexesMaxima->NextRCTbinIndex(row, col, time))
846 if (digitsOut->GetDataUnchecked(row,col,time) < 0.0)
849 for (iPad = 0; iPad < kNclus; iPad++)
851 Int_t iPadCol = col - 1 + iPad;
852 clusterSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row,iPadCol,time));
855 // Count the number of pads in the cluster
860 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time)) >= sigThresh)
864 if (col-ii < 0) break;
868 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time)) >= sigThresh)
872 if (col+ii+1 >= nColMax) break;
876 // Look for 5 pad cluster with minimum in the middle
877 Bool_t fivePadCluster = kFALSE;
878 if (col < (nColMax - 3))
880 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0)
882 fivePadCluster = kTRUE;
884 if ((fivePadCluster) && (col < (nColMax - 5)))
886 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh)
888 fivePadCluster = kFALSE;
891 if ((fivePadCluster) && (col > 1))
893 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh)
895 fivePadCluster = kFALSE;
901 // Modify the signal of the overlapping pad for the left part
902 // of the cluster which remains from a previous unfolding
905 clusterSignal[0] *= ratioLeft;
909 // Unfold the 5 pad cluster
912 for (iPad = 0; iPad < kNsig; iPad++)
914 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
918 // Unfold the two maxima and set the signal on
919 // the overlapping pad to the ratio
920 ratioRight = Unfold(kEpsilon,iplan,padSignal);
921 ratioLeft = 1.0 - ratioRight;
922 clusterSignal[2] *= ratioRight;
926 // The position of the cluster in COL direction relative to the center pad (pad units)
927 Double_t clusterPosCol = 0.0;
928 if (recParam->LUTOn())
930 // Calculate the position of the cluster by using the
931 // lookup table method
932 clusterPosCol = recParam->LUTposition(iplan
939 // Calculate the position of the cluster by using the
940 // center of gravity method
941 for (Int_t i = 0; i < kNsig; i++)
945 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time)); // Central pad
946 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // Left pad
947 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // Right pad
949 (TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)) < padSignal[1]))
951 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
953 if ((col < nColMax - 3) &&
954 (TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)) < padSignal[3]))
956 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
958 clusterPosCol = GetCOG(padSignal);
961 // Store the amplitudes of the pads in the cluster for later analysis
962 Short_t signals[7] = { 0, 0, 0, 0, 0, 0, 0 };
963 for (Int_t jPad = col-3; jPad <= col+3; jPad++)
970 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
973 // Transform the local cluster coordinates into calibrated
974 // space point positions defined in the local tracking system.
975 // Here the calibration for T0, Vdrift and ExB is applied as well.
976 Double_t clusterXYZ[6];
977 clusterXYZ[0] = clusterPosCol;
978 clusterXYZ[1] = clusterSignal[0];
979 clusterXYZ[2] = clusterSignal[1];
980 clusterXYZ[3] = clusterSignal[2];
988 if (fTransform->Transform(clusterXYZ,clusterRCT,((UInt_t) time),0)) {
990 // Add the cluster to the output array
991 // The track indices will be stored later
992 Float_t clusterPos[3];
993 clusterPos[0] = clusterXYZ[0];
994 clusterPos[1] = clusterXYZ[1];
995 clusterPos[2] = clusterXYZ[2];
996 Float_t clusterSig[2];
997 clusterSig[0] = clusterXYZ[4];
998 clusterSig[1] = clusterXYZ[5];
999 Double_t clusterCharge = clusterXYZ[3];
1000 Char_t clusterTimeBin = ((Char_t) clusterRCT[2]);
1001 AliTRDcluster *cluster = new AliTRDcluster(idet
1006 ,((Char_t) nPadCount)
1015 // Temporarily store the row, column and time bin of the center pad
1016 // Used to later on assign the track indices
1017 cluster->SetLabel( row,0);
1018 cluster->SetLabel( col,1);
1019 cluster->SetLabel(time,2);
1021 RecPoints()->Add(cluster);
1023 // Store the index of the first cluster in the current ROC
1024 if (firstClusterROC < 0)
1026 firstClusterROC = RecPoints()->GetEntriesFast() - 1;
1029 // Count the number of cluster in the current ROC
1032 } // if: Transform ok ?
1034 } // if: Maximum found ?
1042 AddLabels(idet, firstClusterROC, nClusterROC);
1045 // Write the cluster and reset the array
1046 WriteClusters(idet);
1053 //_____________________________________________________________________________
1054 Bool_t AliTRDclusterizer::AddLabels(Int_t idet, Int_t firstClusterROC, Int_t nClusterROC)
1057 // Add the track indices to the found clusters
1060 const Int_t kNclus = 3;
1061 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1062 const Int_t kNtrack = kNdict * kNclus;
1064 Int_t iClusterROC = 0;
1071 // Temporary array to collect the track indices
1072 Int_t *idxTracks = new Int_t[kNtrack*nClusterROC];
1074 // Loop through the dictionary arrays one-by-one
1075 // to keep memory consumption low
1076 AliTRDdataArrayI *tracksIn = 0;
1077 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1079 // tracksIn should be expanded beforehand!
1080 tracksIn = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(idet,iDict);
1082 // Loop though the clusters found in this ROC
1083 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
1085 AliTRDcluster *cluster = (AliTRDcluster *)
1086 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1087 row = cluster->GetLabel(0);
1088 col = cluster->GetLabel(1);
1089 time = cluster->GetLabel(2);
1091 for (iPad = 0; iPad < kNclus; iPad++) {
1092 Int_t iPadCol = col - 1 + iPad;
1093 Int_t index = tracksIn->GetDataUnchecked(row,iPadCol,time) - 1;
1094 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1101 // Copy the track indices into the cluster
1102 // Loop though the clusters found in this ROC
1103 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
1105 AliTRDcluster *cluster = (AliTRDcluster *)
1106 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1107 cluster->SetLabel(-9999,0);
1108 cluster->SetLabel(-9999,1);
1109 cluster->SetLabel(-9999,2);
1111 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1115 delete [] idxTracks;
1121 //_____________________________________________________________________________
1122 Double_t AliTRDclusterizer::GetCOG(Double_t signal[5]) const
1126 // Used for clusters with more than 3 pads - where LUT not applicable
1129 Double_t sum = signal[0]
1135 Double_t res = (0.0 * (-signal[0] + signal[4])
1136 + (-signal[1] + signal[3])) / sum;
1142 //_____________________________________________________________________________
1143 Double_t AliTRDclusterizer::Unfold(Double_t eps, Int_t plane, Double_t *padSignal)
1146 // Method to unfold neighbouring maxima.
1147 // The charge ratio on the overlapping pad is calculated
1148 // until there is no more change within the range given by eps.
1149 // The resulting ratio is then returned to the calling method.
1152 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1154 AliError("No AliTRDcalibDB instance available\n");
1159 Int_t itStep = 0; // Count iteration steps
1161 Double_t ratio = 0.5; // Start value for ratio
1162 Double_t prevRatio = 0.0; // Store previous ratio
1164 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1165 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1166 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1168 // Start the iteration
1169 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1174 // Cluster position according to charge ratio
1175 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1176 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
1177 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1178 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1180 // Set cluster charge ratio
1181 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
1182 Double_t ampLeft = padSignal[1] / newSignal[1];
1183 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
1184 Double_t ampRight = padSignal[3] / newSignal[1];
1186 // Apply pad response to parameters
1187 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
1188 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
1190 // Calculate new overlapping ratio
1191 ratio = TMath::Min((Double_t) 1.0
1192 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1200 //_____________________________________________________________________________
1201 void AliTRDclusterizer::TailCancelation(AliTRDdataArrayS *digitsIn
1202 , AliTRDdataArrayF *digitsOut
1203 , AliTRDSignalIndex *indexesIn
1204 , AliTRDSignalIndex *indexesOut
1206 , Float_t adcThreshold
1207 , AliTRDCalROC *calGainFactorROC
1208 , Float_t calGainFactorDetValue)
1211 // Applies the tail cancelation and gain factors:
1212 // Transform digitsIn to digitsOut
1219 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
1222 AliError("No AliTRDRecParam instance available\n");
1226 Double_t *inADC = new Double_t[nTimeTotal]; // ADC data before tail cancellation
1227 Double_t *outADC = new Double_t[nTimeTotal]; // ADC data after tail cancellation
1228 indexesIn->ResetCounters();
1229 while (indexesIn->NextRCIndex(iRow, iCol))
1231 Float_t calGainFactorROCValue = calGainFactorROC->GetValue(iCol,iRow);
1232 Double_t gain = calGainFactorDetValue
1233 * calGainFactorROCValue;
1235 for (iTime = 0; iTime < nTimeTotal; iTime++)
1237 // Apply gain gain factor
1238 inADC[iTime] = digitsIn->GetDataUnchecked(iRow,iCol,iTime);
1239 inADC[iTime] /= gain;
1240 outADC[iTime] = inADC[iTime];
1243 // Apply the tail cancelation via the digital filter
1244 if (recParam->TCOn())
1246 DeConvExp(inADC,outADC,nTimeTotal,recParam->GetTCnexp());
1249 indexesIn->ResetTbinCounter();
1250 while (indexesIn->NextTbinIndex(iTime))
1252 // Store the amplitude of the digit if above threshold
1253 if (outADC[iTime] > adcThreshold)
1255 digitsOut->SetDataUnchecked(iRow,iCol,iTime,outADC[iTime]);
1256 indexesOut->AddIndexTBin(iRow,iCol,iTime);
1260 } // while irow icol
1269 //_____________________________________________________________________________
1270 void AliTRDclusterizer::DeConvExp(Double_t *source, Double_t *target
1271 , Int_t n, Int_t nexp)
1274 // Tail cancellation by deconvolution for PASA v4 TRF
1278 Double_t coefficients[2];
1280 // Initialization (coefficient = alpha, rates = lambda)
1286 if (nexp == 1) { // 1 Exponentials
1292 if (nexp == 2) { // 2 Exponentials
1299 coefficients[0] = c1;
1300 coefficients[1] = c2;
1304 rates[0] = TMath::Exp(-dt/(r1));
1305 rates[1] = TMath::Exp(-dt/(r2));
1310 Double_t reminder[2];
1311 Double_t correction = 0.0;
1312 Double_t result = 0.0;
1314 // Attention: computation order is important
1315 for (k = 0; k < nexp; k++) {
1319 for (i = 0; i < n; i++) {
1321 result = (source[i] - correction); // No rescaling
1324 for (k = 0; k < nexp; k++) {
1325 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1329 for (k = 0; k < nexp; k++) {
1330 correction += reminder[k];
1337 //_____________________________________________________________________________
1338 void AliTRDclusterizer::ResetRecPoints()
1341 // Resets the list of rec points
1345 fRecPoints->Delete();
1350 //_____________________________________________________________________________
1351 TObjArray *AliTRDclusterizer::RecPoints()
1354 // Returns the list of rec points
1358 fRecPoints = new TObjArray(400);