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 "AliTRDrawStreamBase.h"
52 // #include "AliTRDRawStream.h"
53 // #include "AliTRDRawStreamV2.h"
54 #include "AliTRDfeeParam.h"
56 #include "Cal/AliTRDCalROC.h"
57 #include "Cal/AliTRDCalDet.h"
59 ClassImp(AliTRDclusterizer)
61 //_____________________________________________________________________________
62 AliTRDclusterizer::AliTRDclusterizer()
72 ,fTransform(new AliTRDtransform(0))
75 // AliTRDclusterizer default constructor
78 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
82 //_____________________________________________________________________________
83 AliTRDclusterizer::AliTRDclusterizer(const Text_t *name, const Text_t *title)
88 ,fDigitsManager(new AliTRDdigitsManager())
93 ,fTransform(new AliTRDtransform(0))
96 // AliTRDclusterizer constructor
99 fDigitsManager->CreateArrays();
101 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
105 //_____________________________________________________________________________
106 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
111 ,fDigitsManager(NULL)
115 ,fIndexesMaxima(NULL)
119 // AliTRDclusterizer copy constructor
124 //_____________________________________________________________________________
125 AliTRDclusterizer::~AliTRDclusterizer()
128 // AliTRDclusterizer destructor
133 fRecPoints->Delete();
139 delete fDigitsManager;
140 fDigitsManager = NULL;
151 delete fIndexesMaxima;
152 fIndexesMaxima = NULL;
163 //_____________________________________________________________________________
164 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
167 // Assignment operator
172 ((AliTRDclusterizer &) c).Copy(*this);
178 //_____________________________________________________________________________
179 void AliTRDclusterizer::Copy(TObject &c) const
185 ((AliTRDclusterizer &) c).fClusterTree = NULL;
186 ((AliTRDclusterizer &) c).fRecPoints = NULL;
187 ((AliTRDclusterizer &) c).fDigitsManager = NULL;
188 ((AliTRDclusterizer &) c).fAddLabels = fAddLabels;
189 ((AliTRDclusterizer &) c).fRawVersion = fRawVersion;
190 ((AliTRDclusterizer &) c).fIndexesOut = NULL;
191 ((AliTRDclusterizer &) c).fIndexesMaxima = NULL;
192 ((AliTRDclusterizer &) c).fTransform = NULL;
196 //_____________________________________________________________________________
197 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
200 // Opens the AliROOT file. Output and input are in the same file
203 TString evfoldname = AliConfig::GetDefaultEventFolderName();
204 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
207 fRunLoader = AliRunLoader::Open(name);
211 AliError(Form("Can not open session for file %s.",name));
222 //_____________________________________________________________________________
223 Bool_t AliTRDclusterizer::OpenOutput()
226 // Open the output file
229 TObjArray *ioArray = 0;
231 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
232 loader->MakeTree("R");
234 fClusterTree = loader->TreeR();
235 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
241 //_____________________________________________________________________________
242 Bool_t AliTRDclusterizer::OpenOutput(TTree *clusterTree)
245 // Connect the output tree
248 TObjArray *ioArray = 0;
250 fClusterTree = clusterTree;
251 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
257 //_____________________________________________________________________________
258 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
261 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
264 // Import the Trees for the event nEvent in the file
265 fRunLoader->GetEvent(nEvent);
271 //_____________________________________________________________________________
272 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
275 // Fills TRDcluster branch in the tree with the clusters
276 // found in detector = det. For det=-1 writes the tree.
280 (det >= AliTRDgeometry::Ndet())) {
281 AliError(Form("Unexpected detector index %d.\n",det));
285 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
287 TObjArray *ioArray = 0;
288 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
292 (det < AliTRDgeometry::Ndet())) {
294 Int_t nRecPoints = RecPoints()->GetEntriesFast();
295 TObjArray *detRecPoints = new TObjArray(400);
297 for (Int_t i = 0; i < nRecPoints; i++) {
298 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
299 if (det == c->GetDetector()) {
300 detRecPoints->AddLast(c);
303 AliError(Form("Attempt to write a cluster with unexpected detector index: got=%d expected=%d\n"
309 branch->SetAddress(&detRecPoints);
310 fClusterTree->Fill();
320 AliInfo(Form("Writing the cluster tree %s for event %d."
321 ,fClusterTree->GetName(),fRunLoader->GetEventNumber()));
325 branch->SetAddress(&fRecPoints);
327 AliLoader *loader = fRunLoader->GetLoader("TRDLoader");
328 loader->WriteRecPoints("OVERWRITE");
333 AliError("Cluster tree does not exist. Cannot write clusters.\n");
342 AliError(Form("Unexpected detector index %d.\n",det));
348 //_____________________________________________________________________________
349 void AliTRDclusterizer::ResetHelperIndexes(AliTRDSignalIndex *indexesIn)
352 // Reset the helper indexes
357 // carefull here - we assume that only row number may change - most probable
358 if (indexesIn->GetNrow() <= fIndexesOut->GetNrow())
359 fIndexesOut->ResetContent();
361 fIndexesOut->ResetContentConditional(indexesIn->GetNrow()
362 , indexesIn->GetNcol()
363 , indexesIn->GetNtime());
367 fIndexesOut = new AliTRDSignalIndex(indexesIn->GetNrow()
368 , indexesIn->GetNcol()
369 , indexesIn->GetNtime());
374 // carefull here - we assume that only row number may change - most probable
375 if (indexesIn->GetNrow() <= fIndexesMaxima->GetNrow())
377 fIndexesMaxima->ResetContent();
381 fIndexesMaxima->ResetContentConditional(indexesIn->GetNrow()
382 , indexesIn->GetNcol()
383 , indexesIn->GetNtime());
388 fIndexesMaxima = new AliTRDSignalIndex(indexesIn->GetNrow()
389 , indexesIn->GetNcol()
390 , indexesIn->GetNtime());
395 //_____________________________________________________________________________
396 Bool_t AliTRDclusterizer::ReadDigits()
399 // Reads the digits arrays from the input aliroot file
403 AliError("No run loader available");
407 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
408 if (!loader->TreeD()) {
409 loader->LoadDigits();
412 // Read in the digit arrays
413 return (fDigitsManager->ReadDigits(loader->TreeD()));
417 //_____________________________________________________________________________
418 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
421 // Reads the digits arrays from the input tree
424 // Read in the digit arrays
425 return (fDigitsManager->ReadDigits(digitsTree));
429 //_____________________________________________________________________________
430 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
433 // Reads the digits arrays from the ddl file
437 fDigitsManager = raw.Raw2Digits(rawReader);
443 //_____________________________________________________________________________
444 Bool_t AliTRDclusterizer::MakeClusters()
447 // Creates clusters from digits
450 // Propagate info from the digits manager
451 if (fAddLabels == kTRUE)
453 fAddLabels = fDigitsManager->UsesDictionaries();
456 Bool_t fReturn = kTRUE;
457 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++)
460 AliTRDdataArrayS *digitsIn = (AliTRDdataArrayS *) fDigitsManager->GetDigits(i);
461 // This is to take care of switched off super modules
462 if (!digitsIn->HasData())
467 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
468 if (indexes->IsAllocated() == kFALSE)
470 fDigitsManager->BuildIndexes(i);
474 if (indexes->HasEntry())
478 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++)
480 AliTRDdataArrayI *tracksIn = 0;
481 tracksIn = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(i,iDict);
485 fR = MakeClusters(i);
486 fReturn = fR && fReturn;
495 // No compress just remove
496 fDigitsManager->RemoveDigits(i);
497 fDigitsManager->RemoveDictionaries(i);
498 fDigitsManager->ClearIndexes(i);
506 //_____________________________________________________________________________
507 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
510 // Creates clusters from raw data
513 // AliTRDdataArrayS *digits = 0;
514 // AliTRDdataArrayI *track0 = 0;
515 // AliTRDdataArrayI *track1 = 0;
516 // AliTRDdataArrayI *track2 = 0;
518 // AliTRDSignalIndex *indexes = 0;
520 // // Create the digits manager
521 // if (!fDigitsManager)
523 // fDigitsManager = new AliTRDdigitsManager();
524 // fDigitsManager->CreateArrays();
527 // // AliTRDRawStreamV2 input(rawReader);
528 // // input.SetRawVersion( fRawVersion );
530 // AliTRDrawStreamBase &input = *AliTRDrawStreamBase::GetRawStream(rawReader);
532 // AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
534 // // Loop through the digits
535 // Int_t lastdet = -1;
538 // while (input.Next())
541 // det = input.GetDet();
543 // if (det != lastdet)
546 // if (lastdet != -1)
548 // digits = (AliTRDdataArrayS *) fDigitsManager->GetDigits(lastdet);
549 // Bool_t iclusterBranch = kFALSE;
550 // if (indexes->HasEntry())
551 // iclusterBranch = MakeClusters(lastdet);
552 // if (iclusterBranch == kFALSE)
554 // WriteClusters(lastdet);
561 // fDigitsManager->RemoveDigits(lastdet);
562 // fDigitsManager->RemoveDictionaries(lastdet);
563 // fDigitsManager->ClearIndexes(lastdet);
568 // // Add a container for the digits of this detector
569 // digits = (AliTRDdataArrayS *) fDigitsManager->GetDigits(det);
570 // track0 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,0);
571 // track1 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,1);
572 // track2 = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(det,2);
574 // // Allocate memory space for the digits buffer
575 // if (!digits->HasData())
577 // //AliDebug(5, Form("Alloc digits for det %d", det));
578 // digits->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
579 // track0->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
580 // track1->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
581 // track2->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
584 // indexes = fDigitsManager->GetIndexes(det);
585 // indexes->SetSM(input.GetSM());
586 // indexes->SetStack(input.GetStack());
587 // indexes->SetLayer(input.GetLayer());
588 // indexes->SetDetNumber(det);
589 // if (indexes->IsAllocated() == kFALSE)
591 // indexes->Allocate(input.GetMaxRow(), input.GetMaxCol(), input.GetNumberOfTimeBins());
596 // for (it = 0; it < 3; it++)
598 // if ( input.GetTimeBin() + it < input.GetNumberOfTimeBins() )
600 // if (input.GetSignals()[it] > 0)
602 // digits->SetDataUnchecked(input.GetRow(), input.GetCol(),
603 // input.GetTimeBin() + it, input.GetSignals()[it]);
605 // indexes->AddIndexTBin(input.GetRow(), input.GetCol(),
606 // input.GetTimeBin() + it);
607 // track0->SetDataUnchecked(input.GetRow(), input.GetCol(),
608 // input.GetTimeBin() + it, 0);
609 // track1->SetDataUnchecked(input.GetRow(), input.GetCol(),
610 // input.GetTimeBin() + it, 0);
611 // track2->SetDataUnchecked(input.GetRow(), input.GetCol(),
612 // input.GetTimeBin() + it, 0);
619 // if (lastdet != -1)
621 // Bool_t iclusterBranch = kFALSE;
622 // if (indexes->HasEntry())
624 // iclusterBranch = MakeClusters(lastdet);
626 // if (iclusterBranch == kFALSE)
628 // WriteClusters(lastdet);
631 // //MakeClusters(lastdet);
634 // fDigitsManager->RemoveDigits(lastdet);
635 // fDigitsManager->RemoveDictionaries(lastdet);
636 // fDigitsManager->ClearIndexes(lastdet);
640 // delete fDigitsManager;
641 // fDigitsManager = NULL;
644 return Raw2ClustersChamber(rawReader);
647 //_____________________________________________________________________________
648 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
651 // Creates clusters from raw data
654 // Create the digits manager
657 fDigitsManager = new AliTRDdigitsManager();
658 fDigitsManager->CreateArrays();
661 fDigitsManager->SetUseDictionaries(fAddLabels);
663 // AliTRDRawStreamV2 input(rawReader);
664 // input.SetRawVersion( fRawVersion );
666 AliTRDrawStreamBase *pinput = AliTRDrawStreamBase::GetRawStream(rawReader);
667 AliTRDrawStreamBase &input = *pinput;
669 AliInfo(Form("Stream version: %s", input.IsA()->GetName()));
672 while ((det = input.NextChamber(fDigitsManager)) >= 0)
674 Bool_t iclusterBranch = kFALSE;
675 if (fDigitsManager->GetIndexes(det)->HasEntry())
677 iclusterBranch = MakeClusters(det);
679 if (iclusterBranch == kFALSE)
684 fDigitsManager->RemoveDigits(det);
685 fDigitsManager->RemoveDictionaries(det);
686 fDigitsManager->ClearIndexes(det);
689 delete fDigitsManager;
690 fDigitsManager = NULL;
698 //_____________________________________________________________________________
699 Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
702 // Generates the cluster.
706 // digits should be expanded beforehand!
707 // digitsIn->Expand();
708 AliTRDdataArrayS *digitsIn = (AliTRDdataArrayS *) fDigitsManager->GetDigits(det);
710 // This is to take care of switched off super modules
711 if (!digitsIn->HasData())
716 AliTRDSignalIndex *indexesIn = fDigitsManager->GetIndexes(det);
717 if (indexesIn->IsAllocated() == kFALSE)
719 AliError("Indexes do not exist!");
723 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
726 AliFatal("No AliTRDcalibDB instance available\n");
730 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
733 AliError("No AliTRDRecParam instance available\n");
738 // There is no ADC threshold anymore, and simParam should not be used in clusterizer. KO
739 Float_t adcThreshold = 0;
741 // Threshold value for the maximum
742 Float_t maxThresh = recParam->GetClusMaxThresh();
743 // Threshold value for the digit signal
744 Float_t sigThresh = recParam->GetClusSigThresh();
746 // Iteration limit for unfolding procedure
747 const Float_t kEpsilon = 0.01;
748 const Int_t kNclus = 3;
749 const Int_t kNsig = 5;
752 Double_t ratioLeft = 1.0;
753 Double_t ratioRight = 1.0;
755 Double_t padSignal[kNsig];
756 Double_t clusterSignal[kNclus];
758 Int_t icham = indexesIn->GetChamber();
759 Int_t iplan = indexesIn->GetPlane();
760 Int_t isect = indexesIn->GetSM();
762 // Start clustering in the chamber
764 Int_t idet = AliTRDgeometry::GetDetector(iplan,icham,isect);
767 AliError("Strange Detector number Missmatch!");
771 // TRD space point transformation
772 fTransform->SetDetector(det);
774 Int_t ilayer = AliGeomManager::kTRD1 + iplan;
775 Int_t imodule = icham + AliTRDgeometry::Ncham() * isect;
776 UShort_t volid = AliGeomManager::LayerToVolUID(ilayer,imodule);
778 Int_t nColMax = digitsIn->GetNcol();
779 Int_t nTimeTotal = digitsIn->GetNtime();
781 // Detector wise calibration object for the gain factors
782 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
783 // Calibration object with pad wise values for the gain factors
784 AliTRDCalROC *calGainFactorROC = calibration->GetGainFactorROC(idet);
785 // Calibration value for chamber wise gain factor
786 Float_t calGainFactorDetValue = calGainFactorDet->GetValue(idet);
790 AliTRDdataArrayF *digitsOut = new AliTRDdataArrayF(digitsIn->GetNrow()
792 ,digitsIn->GetNtime());
794 ResetHelperIndexes(indexesIn);
796 // Apply the gain and the tail cancelation via digital filter
797 TailCancelation(digitsIn
804 ,calGainFactorDetValue);
811 fIndexesOut->ResetCounters();
812 while (fIndexesOut->NextRCTbinIndex(row, col, time))
815 Float_t signalM = TMath::Abs(digitsOut->GetDataUnchecked(row,col,time));
817 // Look for the maximum
818 if (signalM >= maxThresh)
821 if (col + 1 >= nColMax || col-1 < 0)
824 Float_t signalL = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time));
825 Float_t signalR = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time));
827 if ((TMath::Abs(signalL) <= signalM) &&
828 (TMath::Abs(signalR) < signalM))
830 if ((TMath::Abs(signalL) >= sigThresh) ||
831 (TMath::Abs(signalR) >= sigThresh))
833 // Maximum found, mark the position by a negative signal
834 digitsOut->SetDataUnchecked(row,col,time,-signalM);
835 fIndexesMaxima->AddIndexTBin(row,col,time);
843 // The index to the first cluster of a given ROC
844 Int_t firstClusterROC = -1;
845 // The number of cluster in a given ROC
846 Int_t nClusterROC = 0;
848 // Now check the maxima and calculate the cluster position
849 fIndexesMaxima->ResetCounters();
850 while (fIndexesMaxima->NextRCTbinIndex(row, col, time))
854 if (digitsOut->GetDataUnchecked(row,col,time) < 0.0)
857 for (iPad = 0; iPad < kNclus; iPad++)
859 Int_t iPadCol = col - 1 + iPad;
860 clusterSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row,iPadCol,time));
863 // Count the number of pads in the cluster
868 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col-ii ,time)) >= sigThresh)
872 if (col-ii < 0) break;
876 while (TMath::Abs(digitsOut->GetDataUnchecked(row,col+ii+1,time)) >= sigThresh)
880 if (col+ii+1 >= nColMax) break;
884 // Look for 5 pad cluster with minimum in the middle
885 Bool_t fivePadCluster = kFALSE;
886 if (col < (nColMax - 3))
888 if (digitsOut->GetDataUnchecked(row,col+2,time) < 0)
890 fivePadCluster = kTRUE;
892 if ((fivePadCluster) && (col < (nColMax - 5)))
894 if (digitsOut->GetDataUnchecked(row,col+4,time) >= sigThresh)
896 fivePadCluster = kFALSE;
899 if ((fivePadCluster) && (col > 1))
901 if (digitsOut->GetDataUnchecked(row,col-2,time) >= sigThresh)
903 fivePadCluster = kFALSE;
909 // Modify the signal of the overlapping pad for the left part
910 // of the cluster which remains from a previous unfolding
913 clusterSignal[0] *= ratioLeft;
917 // Unfold the 5 pad cluster
920 for (iPad = 0; iPad < kNsig; iPad++)
922 padSignal[iPad] = TMath::Abs(digitsOut->GetDataUnchecked(row
926 // Unfold the two maxima and set the signal on
927 // the overlapping pad to the ratio
928 ratioRight = Unfold(kEpsilon,iplan,padSignal);
929 ratioLeft = 1.0 - ratioRight;
930 clusterSignal[2] *= ratioRight;
934 // The position of the cluster in COL direction relative to the center pad (pad units)
935 Double_t clusterPosCol = 0.0;
936 if (recParam->LUTOn())
938 // Calculate the position of the cluster by using the
939 // lookup table method
940 clusterPosCol = recParam->LUTposition(iplan
947 // Calculate the position of the cluster by using the
948 // center of gravity method
949 for (Int_t i = 0; i < kNsig; i++)
953 padSignal[2] = TMath::Abs(digitsOut->GetDataUnchecked(row,col ,time)); // Central pad
954 padSignal[1] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-1,time)); // Left pad
955 padSignal[3] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+1,time)); // Right pad
957 (TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time)) < padSignal[1]))
959 padSignal[0] = TMath::Abs(digitsOut->GetDataUnchecked(row,col-2,time));
961 if ((col < nColMax - 3) &&
962 (TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time)) < padSignal[3]))
964 padSignal[4] = TMath::Abs(digitsOut->GetDataUnchecked(row,col+2,time));
966 clusterPosCol = GetCOG(padSignal);
969 // Store the amplitudes of the pads in the cluster for later analysis
970 Short_t signals[7] = { 0, 0, 0, 0, 0, 0, 0 };
971 for (Int_t jPad = col-3; jPad <= col+3; jPad++)
978 signals[jPad-col+3] = TMath::Nint(TMath::Abs(digitsOut->GetDataUnchecked(row,jPad,time)));
981 // Transform the local cluster coordinates into calibrated
982 // space point positions defined in the local tracking system.
983 // Here the calibration for T0, Vdrift and ExB is applied as well.
984 Double_t clusterXYZ[6];
985 clusterXYZ[0] = clusterPosCol;
986 clusterXYZ[1] = clusterSignal[0];
987 clusterXYZ[2] = clusterSignal[1];
988 clusterXYZ[3] = clusterSignal[2];
997 if (fTransform->Transform(clusterXYZ, clusterRCT, ((UInt_t) time), out, 0)) {
999 // Add the cluster to the output array
1000 // The track indices will be stored later
1001 Float_t clusterPos[3];
1002 clusterPos[0] = clusterXYZ[0];
1003 clusterPos[1] = clusterXYZ[1];
1004 clusterPos[2] = clusterXYZ[2];
1005 Float_t clusterSig[2];
1006 clusterSig[0] = clusterXYZ[4];
1007 clusterSig[1] = clusterXYZ[5];
1008 Double_t clusterCharge = clusterXYZ[3];
1009 Char_t clusterTimeBin = ((Char_t) clusterRCT[2]);
1010 AliTRDcluster *cluster = new AliTRDcluster(idet
1015 ,((Char_t) nPadCount)
1023 cluster->SetInChamber(!out);
1025 // Temporarily store the row, column and time bin of the center pad
1026 // Used to later on assign the track indices
1027 cluster->SetLabel( row,0);
1028 cluster->SetLabel( col,1);
1029 cluster->SetLabel(time,2);
1031 RecPoints()->Add(cluster);
1033 // Store the index of the first cluster in the current ROC
1034 if (firstClusterROC < 0)
1036 firstClusterROC = RecPoints()->GetEntriesFast() - 1;
1039 // Count the number of cluster in the current ROC
1042 } // if: Transform ok ?
1044 } // if: Maximum found ?
1052 AddLabels(idet, firstClusterROC, nClusterROC);
1055 // Write the cluster and reset the array
1056 WriteClusters(idet);
1063 //_____________________________________________________________________________
1064 Bool_t AliTRDclusterizer::AddLabels(Int_t idet, Int_t firstClusterROC, Int_t nClusterROC)
1067 // Add the track indices to the found clusters
1070 const Int_t kNclus = 3;
1071 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1072 const Int_t kNtrack = kNdict * kNclus;
1074 Int_t iClusterROC = 0;
1081 // Temporary array to collect the track indices
1082 Int_t *idxTracks = new Int_t[kNtrack*nClusterROC];
1084 // Loop through the dictionary arrays one-by-one
1085 // to keep memory consumption low
1086 AliTRDdataArrayI *tracksIn = 0;
1087 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1089 // tracksIn should be expanded beforehand!
1090 tracksIn = (AliTRDdataArrayI *) fDigitsManager->GetDictionary(idet,iDict);
1092 // Loop though the clusters found in this ROC
1093 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
1095 AliTRDcluster *cluster = (AliTRDcluster *)
1096 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1097 row = cluster->GetLabel(0);
1098 col = cluster->GetLabel(1);
1099 time = cluster->GetLabel(2);
1101 for (iPad = 0; iPad < kNclus; iPad++) {
1102 Int_t iPadCol = col - 1 + iPad;
1103 Int_t index = tracksIn->GetDataUnchecked(row,iPadCol,time) - 1;
1104 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1111 // Copy the track indices into the cluster
1112 // Loop though the clusters found in this ROC
1113 for (iClusterROC = 0; iClusterROC < nClusterROC; iClusterROC++) {
1115 AliTRDcluster *cluster = (AliTRDcluster *)
1116 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1117 cluster->SetLabel(-9999,0);
1118 cluster->SetLabel(-9999,1);
1119 cluster->SetLabel(-9999,2);
1121 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1125 delete [] idxTracks;
1131 //_____________________________________________________________________________
1132 Double_t AliTRDclusterizer::GetCOG(Double_t signal[5]) const
1136 // Used for clusters with more than 3 pads - where LUT not applicable
1139 Double_t sum = signal[0]
1145 Double_t res = (0.0 * (-signal[0] + signal[4])
1146 + (-signal[1] + signal[3])) / sum;
1152 //_____________________________________________________________________________
1153 Double_t AliTRDclusterizer::Unfold(Double_t eps, Int_t plane, Double_t *padSignal)
1156 // Method to unfold neighbouring maxima.
1157 // The charge ratio on the overlapping pad is calculated
1158 // until there is no more change within the range given by eps.
1159 // The resulting ratio is then returned to the calling method.
1162 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1164 AliError("No AliTRDcalibDB instance available\n");
1169 Int_t itStep = 0; // Count iteration steps
1171 Double_t ratio = 0.5; // Start value for ratio
1172 Double_t prevRatio = 0.0; // Store previous ratio
1174 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1175 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1176 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1178 // Start the iteration
1179 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1184 // Cluster position according to charge ratio
1185 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1186 / (padSignal[0] + padSignal[1] + ratio*padSignal[2]);
1187 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1188 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1190 // Set cluster charge ratio
1191 irc = calibration->PadResponse(1.0,maxLeft ,plane,newSignal);
1192 Double_t ampLeft = padSignal[1] / newSignal[1];
1193 irc = calibration->PadResponse(1.0,maxRight,plane,newSignal);
1194 Double_t ampRight = padSignal[3] / newSignal[1];
1196 // Apply pad response to parameters
1197 irc = calibration->PadResponse(ampLeft ,maxLeft ,plane,newLeftSignal );
1198 irc = calibration->PadResponse(ampRight,maxRight,plane,newRightSignal);
1200 // Calculate new overlapping ratio
1201 ratio = TMath::Min((Double_t) 1.0
1202 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1210 //_____________________________________________________________________________
1211 void AliTRDclusterizer::TailCancelation(AliTRDdataArrayS *digitsIn
1212 , AliTRDdataArrayF *digitsOut
1213 , AliTRDSignalIndex *indexesIn
1214 , AliTRDSignalIndex *indexesOut
1216 , Float_t adcThreshold
1217 , AliTRDCalROC *calGainFactorROC
1218 , Float_t calGainFactorDetValue)
1221 // Applies the tail cancelation and gain factors:
1222 // Transform digitsIn to digitsOut
1229 AliTRDRecParam *recParam = AliTRDRecParam::Instance();
1232 AliError("No AliTRDRecParam instance available\n");
1236 Double_t *inADC = new Double_t[nTimeTotal]; // ADC data before tail cancellation
1237 Double_t *outADC = new Double_t[nTimeTotal]; // ADC data after tail cancellation
1238 indexesIn->ResetCounters();
1239 while (indexesIn->NextRCIndex(iRow, iCol))
1241 Float_t calGainFactorROCValue = calGainFactorROC->GetValue(iCol,iRow);
1242 Double_t gain = calGainFactorDetValue
1243 * calGainFactorROCValue;
1245 for (iTime = 0; iTime < nTimeTotal; iTime++)
1247 // Apply gain gain factor
1248 inADC[iTime] = digitsIn->GetDataUnchecked(iRow,iCol,iTime);
1249 inADC[iTime] /= gain;
1250 outADC[iTime] = inADC[iTime];
1253 // Apply the tail cancelation via the digital filter
1254 if (recParam->TCOn())
1256 DeConvExp(inADC,outADC,nTimeTotal,recParam->GetTCnexp());
1259 indexesIn->ResetTbinCounter();
1260 while (indexesIn->NextTbinIndex(iTime))
1262 // Store the amplitude of the digit if above threshold
1263 if (outADC[iTime] > adcThreshold)
1265 digitsOut->SetDataUnchecked(iRow,iCol,iTime,outADC[iTime]);
1266 indexesOut->AddIndexTBin(iRow,iCol,iTime);
1270 } // while irow icol
1279 //_____________________________________________________________________________
1280 void AliTRDclusterizer::DeConvExp(Double_t *source, Double_t *target
1281 , Int_t n, Int_t nexp)
1284 // Tail cancellation by deconvolution for PASA v4 TRF
1288 Double_t coefficients[2];
1290 // Initialization (coefficient = alpha, rates = lambda)
1296 if (nexp == 1) { // 1 Exponentials
1302 if (nexp == 2) { // 2 Exponentials
1309 coefficients[0] = c1;
1310 coefficients[1] = c2;
1314 rates[0] = TMath::Exp(-dt/(r1));
1315 rates[1] = TMath::Exp(-dt/(r2));
1320 Double_t reminder[2];
1321 Double_t correction = 0.0;
1322 Double_t result = 0.0;
1324 // Attention: computation order is important
1325 for (k = 0; k < nexp; k++) {
1329 for (i = 0; i < n; i++) {
1331 result = (source[i] - correction); // No rescaling
1334 for (k = 0; k < nexp; k++) {
1335 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1339 for (k = 0; k < nexp; k++) {
1340 correction += reminder[k];
1347 //_____________________________________________________________________________
1348 void AliTRDclusterizer::ResetRecPoints()
1351 // Resets the list of rec points
1355 fRecPoints->Delete();
1360 //_____________________________________________________________________________
1361 TObjArray *AliTRDclusterizer::RecPoints()
1364 // Returns the list of rec points
1368 fRecPoints = new TObjArray(400);