1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // TRD cluster finder //
22 ///////////////////////////////////////////////////////////////////////////////
24 #include <TClonesArray.h>
25 #include <TObjArray.h>
27 #include "AliRunLoader.h"
28 #include "AliLoader.h"
29 #include "AliAlignObj.h"
31 #include "AliTRDclusterizer.h"
32 #include "AliTRDcluster.h"
33 #include "AliTRDReconstructor.h"
34 #include "AliTRDgeometry.h"
35 #include "AliTRDarrayDictionary.h"
36 #include "AliTRDarrayADC.h"
37 #include "AliTRDdigitsManager.h"
38 #include "AliTRDdigitsParam.h"
39 #include "AliTRDrawData.h"
40 #include "AliTRDcalibDB.h"
41 #include "AliTRDtransform.h"
42 #include "AliTRDSignalIndex.h"
43 #include "AliTRDrawStreamBase.h"
44 #include "AliTRDfeeParam.h"
45 #include "AliTRDtrackletWord.h"
47 #include "TTreeStream.h"
49 #include "Cal/AliTRDCalROC.h"
50 #include "Cal/AliTRDCalDet.h"
51 #include "Cal/AliTRDCalSingleChamberStatus.h"
53 ClassImp(AliTRDclusterizer)
55 //_____________________________________________________________________________
56 AliTRDclusterizer::AliTRDclusterizer(const AliTRDReconstructor *const rec)
64 ,fDigitsManager(new AliTRDdigitsManager())
65 ,fTrackletContainer(NULL)
67 ,fTransform(new AliTRDtransform(0))
73 ,fMinLeftRightCutSigma(0)
79 ,fCalGainFactorROC(NULL)
80 ,fCalGainFactorDetValue(0)
83 ,fCalPadStatusROC(NULL)
89 // AliTRDclusterizer default constructor
92 SetBit(kLabels, kTRUE);
94 AliTRDcalibDB *trd = 0x0;
95 if (!(trd = AliTRDcalibDB::Instance())) {
96 AliFatal("Could not get calibration object");
99 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
101 // Initialize debug stream
103 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 1){
104 TDirectory *savedir = gDirectory;
105 //fgGetDebugStream = new TTreeSRedirector("TRD.ClusterizerDebug.root");
112 //_____________________________________________________________________________
113 AliTRDclusterizer::AliTRDclusterizer(const Text_t *name, const Text_t *title, const AliTRDReconstructor *const rec)
121 ,fDigitsManager(new AliTRDdigitsManager())
122 ,fTrackletContainer(NULL)
124 ,fTransform(new AliTRDtransform(0))
130 ,fMinLeftRightCutSigma(0)
136 ,fCalGainFactorROC(NULL)
137 ,fCalGainFactorDetValue(0)
139 ,fCalNoiseDetValue(0)
140 ,fCalPadStatusROC(NULL)
146 // AliTRDclusterizer constructor
149 SetBit(kLabels, kTRUE);
151 AliTRDcalibDB *trd = 0x0;
152 if (!(trd = AliTRDcalibDB::Instance())) {
153 AliFatal("Could not get calibration object");
156 fDigitsManager->CreateArrays();
158 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
164 //_____________________________________________________________________________
165 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
167 ,fReconstructor(c.fReconstructor)
173 ,fDigitsManager(NULL)
174 ,fTrackletContainer(NULL)
182 ,fMinLeftRightCutSigma(0)
188 ,fCalGainFactorROC(NULL)
189 ,fCalGainFactorDetValue(0)
191 ,fCalNoiseDetValue(0)
192 ,fCalPadStatusROC(NULL)
198 // AliTRDclusterizer copy constructor
201 SetBit(kLabels, kTRUE);
207 //_____________________________________________________________________________
208 AliTRDclusterizer::~AliTRDclusterizer()
211 // AliTRDclusterizer destructor
214 if (fRecPoints/* && IsClustersOwner()*/){
215 fRecPoints->Delete();
220 fTracklets->Delete();
224 if (fDigitsManager) {
225 delete fDigitsManager;
226 fDigitsManager = NULL;
229 if (fTrackletContainer){
230 delete fTrackletContainer;
231 fTrackletContainer = NULL;
241 //_____________________________________________________________________________
242 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
245 // Assignment operator
250 ((AliTRDclusterizer &) c).Copy(*this);
257 //_____________________________________________________________________________
258 void AliTRDclusterizer::Copy(TObject &c) const
264 ((AliTRDclusterizer &) c).fClusterTree = NULL;
265 ((AliTRDclusterizer &) c).fRecPoints = NULL;
266 ((AliTRDclusterizer &) c).fTrackletTree = NULL;
267 ((AliTRDclusterizer &) c).fDigitsManager = NULL;
268 ((AliTRDclusterizer &) c).fTrackletContainer = NULL;
269 ((AliTRDclusterizer &) c).fRawVersion = fRawVersion;
270 ((AliTRDclusterizer &) c).fTransform = NULL;
271 ((AliTRDclusterizer &) c).fDigits = NULL;
272 ((AliTRDclusterizer &) c).fIndexes = NULL;
273 ((AliTRDclusterizer &) c).fMaxThresh = 0;
274 ((AliTRDclusterizer &) c).fSigThresh = 0;
275 ((AliTRDclusterizer &) c).fMinMaxCutSigma= 0;
276 ((AliTRDclusterizer &) c).fMinLeftRightCutSigma = 0;
277 ((AliTRDclusterizer &) c).fLayer = 0;
278 ((AliTRDclusterizer &) c).fDet = 0;
279 ((AliTRDclusterizer &) c).fVolid = 0;
280 ((AliTRDclusterizer &) c).fColMax = 0;
281 ((AliTRDclusterizer &) c).fTimeTotal = 0;
282 ((AliTRDclusterizer &) c).fCalGainFactorROC = NULL;
283 ((AliTRDclusterizer &) c).fCalGainFactorDetValue = 0;
284 ((AliTRDclusterizer &) c).fCalNoiseROC = NULL;
285 ((AliTRDclusterizer &) c).fCalNoiseDetValue = 0;
286 ((AliTRDclusterizer &) c).fCalPadStatusROC = NULL;
287 ((AliTRDclusterizer &) c).fClusterROC = 0;
288 ((AliTRDclusterizer &) c).firstClusterROC= 0;
289 ((AliTRDclusterizer &) c).fNoOfClusters = 0;
292 //_____________________________________________________________________________
293 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
296 // Opens the AliROOT file. Output and input are in the same file
299 TString evfoldname = AliConfig::GetDefaultEventFolderName();
300 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
303 fRunLoader = AliRunLoader::Open(name);
307 AliError(Form("Can not open session for file %s.",name));
318 //_____________________________________________________________________________
319 Bool_t AliTRDclusterizer::OpenOutput()
322 // Open the output file
325 if (!fReconstructor->IsWritingClusters()) return kTRUE;
327 TObjArray *ioArray = 0x0;
329 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
330 loader->MakeTree("R");
332 fClusterTree = loader->TreeR();
333 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
339 //_____________________________________________________________________________
340 Bool_t AliTRDclusterizer::OpenOutput(TTree *const clusterTree)
343 // Connect the output tree
347 if (fReconstructor->IsWritingClusters()){
348 TObjArray *ioArray = 0x0;
349 fClusterTree = clusterTree;
350 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
355 //_____________________________________________________________________________
356 Bool_t AliTRDclusterizer::OpenTrackletOutput()
362 if (fReconstructor->IsWritingTracklets()){
363 TString evfoldname = AliConfig::GetDefaultEventFolderName();
364 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
367 fRunLoader = AliRunLoader::Open("galice.root");
370 AliError(Form("Can not open session for file galice.root."));
374 UInt_t **leaves = new UInt_t *[2];
375 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
377 AliError("Could not get the tracklets data loader!");
378 dl = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
379 fRunLoader->GetLoader("TRDLoader")->AddDataLoader(dl);
381 fTrackletTree = dl->Tree();
385 fTrackletTree = dl->Tree();
387 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
389 fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
395 //_____________________________________________________________________________
396 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
399 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
402 // Import the Trees for the event nEvent in the file
403 fRunLoader->GetEvent(nEvent);
409 //_____________________________________________________________________________
410 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
413 // Fills TRDcluster branch in the tree with the clusters
414 // found in detector = det. For det=-1 writes the tree.
418 (det >= AliTRDgeometry::Ndet())) {
419 AliError(Form("Unexpected detector index %d.\n",det));
423 TObjArray *ioArray = new TObjArray(400);
424 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
426 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
427 } else branch->SetAddress(&ioArray);
429 Int_t nRecPoints = RecPoints()->GetEntriesFast();
431 for (Int_t i = 0; i < nRecPoints; i++) {
432 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
433 if(det != c->GetDetector()) continue;
436 fClusterTree->Fill();
440 for (Int_t i = 0; i < nRecPoints; i++) {
441 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
442 if(c->GetDetector() != detOld){
443 fClusterTree->Fill();
445 detOld = c->GetDetector();
456 //_____________________________________________________________________________
457 Bool_t AliTRDclusterizer::WriteTracklets(Int_t det)
460 // Write the raw data tracklets into seperate file
463 UInt_t **leaves = new UInt_t *[2];
464 for (Int_t i=0; i<2 ;i++){
465 leaves[i] = new UInt_t[258];
466 leaves[i][0] = det; // det
467 leaves[i][1] = i; // side
468 memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
472 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
474 fTrackletTree = dl->Tree();
477 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
479 trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
482 for (Int_t i=0; i<2; i++){
483 if (leaves[i][2]>0) {
484 trkbranch->SetAddress(leaves[i]);
485 fTrackletTree->Fill();
489 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
490 dl->WriteData("OVERWRITE");
498 //_____________________________________________________________________________
499 Bool_t AliTRDclusterizer::ReadDigits()
502 // Reads the digits arrays from the input aliroot file
506 AliError("No run loader available");
510 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
511 if (!loader->TreeD()) {
512 loader->LoadDigits();
515 // Read in the digit arrays
516 return (fDigitsManager->ReadDigits(loader->TreeD()));
520 //_____________________________________________________________________________
521 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
524 // Reads the digits arrays from the input tree
527 // Read in the digit arrays
528 return (fDigitsManager->ReadDigits(digitsTree));
532 //_____________________________________________________________________________
533 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
536 // Reads the digits arrays from the ddl file
540 fDigitsManager = raw.Raw2Digits(rawReader);
546 //_____________________________________________________________________________
547 Bool_t AliTRDclusterizer::MakeClusters()
550 // Creates clusters from digits
553 // Propagate info from the digits manager
554 if (TestBit(kLabels)){
555 SetBit(kLabels, fDigitsManager->UsesDictionaries());
558 Bool_t fReturn = kTRUE;
559 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++){
561 AliTRDarrayADC *digitsIn = (AliTRDarrayADC*) fDigitsManager->GetDigits(i); //mod
562 // This is to take care of switched off super modules
563 if (!digitsIn->HasData()) continue;
565 digitsIn->DeleteNegatives(); // Restore digits array to >=0 values
566 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
567 if (indexes->IsAllocated() == kFALSE){
568 fDigitsManager->BuildIndexes(i);
572 if (indexes->HasEntry()){
573 if (TestBit(kLabels)){
574 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++){
575 AliTRDarrayDictionary *tracksIn = 0; //mod
576 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(i,iDict); //mod
580 fR = MakeClusters(i);
581 fReturn = fR && fReturn;
585 // if(IsWritingClusters()) WriteClusters(i);
589 // No compress just remove
590 fDigitsManager->RemoveDigits(i);
591 fDigitsManager->RemoveDictionaries(i);
592 fDigitsManager->ClearIndexes(i);
595 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
597 AliInfo(Form("Number of found clusters : %d", RecPoints()->GetEntriesFast()));
603 //_____________________________________________________________________________
604 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
607 // Creates clusters from raw data
610 return Raw2ClustersChamber(rawReader);
614 //_____________________________________________________________________________
615 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
618 // Creates clusters from raw data
621 // Create the digits manager
622 if (!fDigitsManager){
623 fDigitsManager = new AliTRDdigitsManager(kTRUE);
624 fDigitsManager->CreateArrays();
627 fDigitsManager->SetUseDictionaries(TestBit(kLabels));
629 // tracklet container for raw tracklet writing
630 if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
631 // maximum tracklets for one HC
632 const Int_t kTrackletChmb=256;
633 fTrackletContainer = new UInt_t *[2];
634 fTrackletContainer[0] = new UInt_t[kTrackletChmb];
635 fTrackletContainer[1] = new UInt_t[kTrackletChmb];
638 AliTRDrawStreamBase *input = AliTRDrawStreamBase::GetRawStream(rawReader);
639 if(fReconstructor->IsHLT())
640 input->SetSharedPadReadout(kFALSE);
642 AliInfo(Form("Stream version: %s", input->IsA()->GetName()));
645 while ((det = input->NextChamber(fDigitsManager,fTrackletContainer)) >= 0){
646 Bool_t iclusterBranch = kFALSE;
647 if (fDigitsManager->GetIndexes(det)->HasEntry()){
648 iclusterBranch = MakeClusters(det);
651 fDigitsManager->ClearArrays(det);
653 if (!fReconstructor->IsWritingTracklets()) continue;
654 if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
657 if (fTrackletContainer){
658 delete [] fTrackletContainer[0];
659 delete [] fTrackletContainer[1];
660 delete [] fTrackletContainer;
661 fTrackletContainer = NULL;
664 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
666 delete fDigitsManager;
667 fDigitsManager = NULL;
672 AliInfo(Form("Number of found clusters : %d", fNoOfClusters));
677 //_____________________________________________________________________________
678 UChar_t AliTRDclusterizer::GetStatus(Short_t &signal)
681 // Check if a pad is masked
686 if(signal>0 && TESTBIT(signal, 10)){
688 for(int ibit=0; ibit<4; ibit++){
689 if(TESTBIT(signal, 11+ibit)){
690 SETBIT(status, ibit);
691 CLRBIT(signal, 11+ibit);
698 //_____________________________________________________________________________
699 void AliTRDclusterizer::SetPadStatus(const UChar_t status, UChar_t &out) const {
701 // Set the pad status into out
702 // First three bits are needed for the position encoding
707 //_____________________________________________________________________________
708 UChar_t AliTRDclusterizer::GetPadStatus(UChar_t encoding) const {
710 // return the staus encoding of the corrupted pad
712 return static_cast<UChar_t>(encoding >> 3);
715 //_____________________________________________________________________________
716 Int_t AliTRDclusterizer::GetCorruption(UChar_t encoding) const {
718 // Return the position of the corruption
723 //_____________________________________________________________________________
724 Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
727 // Generates the cluster.
731 fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
733 // This is to take care of switched off super modules
734 if (!fDigits->HasData()) return kFALSE;
736 fIndexes = fDigitsManager->GetIndexes(det);
737 if (fIndexes->IsAllocated() == kFALSE) {
738 AliError("Indexes do not exist!");
742 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
744 AliFatal("No AliTRDcalibDB instance available\n");
748 if (!fReconstructor){
749 AliError("Reconstructor not set\n");
753 fMaxThresh = fReconstructor->GetRecoParam()->GetClusMaxThresh();
754 fSigThresh = fReconstructor->GetRecoParam()->GetClusSigThresh();
755 fMinMaxCutSigma = fReconstructor->GetRecoParam()->GetMinMaxCutSigma();
756 fMinLeftRightCutSigma = fReconstructor->GetRecoParam()->GetMinLeftRightCutSigma();
758 Int_t istack = fIndexes->GetStack();
759 fLayer = fIndexes->GetLayer();
760 Int_t isector = fIndexes->GetSM();
762 // Start clustering in the chamber
764 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
766 AliError("Strange Detector number Missmatch!");
770 // TRD space point transformation
771 fTransform->SetDetector(det);
773 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
774 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
775 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
777 if(fReconstructor->IsProcessingTracklets() && fTrackletContainer)
778 AddTrackletsToArray();
780 fColMax = fDigits->GetNcol();
781 //Int_t nRowMax = fDigits->GetNrow();
782 fTimeTotal = fDigits->GetNtime();
784 // Detector wise calibration object for the gain factors
785 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
786 // Calibration object with pad wise values for the gain factors
787 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
788 // Calibration value for chamber wise gain factor
789 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
791 // Detector wise calibration object for the noise
792 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
793 // Calibration object with pad wise values for the noise
794 fCalNoiseROC = calibration->GetNoiseROC(fDet);
795 // Calibration value for chamber wise noise
796 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
798 // Calibration object with the pad status
799 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
801 SetBit(kLUT, fReconstructor->GetRecoParam()->UseLUT());
802 SetBit(kGAUS, fReconstructor->GetRecoParam()->UseGAUS());
803 SetBit(kHLT, fReconstructor->IsHLT());
805 firstClusterROC = -1;
808 // Apply the gain and the tail cancelation via digital filter
809 if(fReconstructor->GetRecoParam()->UseTailCancelation()) TailCancelation();
811 MaxStruct curr, last;
812 Int_t nMaximas = 0, nCorrupted = 0;
814 // Here the clusterfining is happening
816 for(curr.Time = 0; curr.Time < fTimeTotal; curr.Time++){
817 while(fIndexes->NextRCIndex(curr.Row, curr.Col)){
818 //printf("\nCHECK r[%2d] c[%3d] t[%d]\n", curr.Row, curr.Col, curr.Time);
819 if(IsMaximum(curr, curr.padStatus, &curr.Signals[0])){
820 //printf("\tMAX s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
822 if(curr.Time==last.Time && curr.Row==last.Row && curr.Col==last.Col+2) FivePadCluster(last, curr);
825 last=curr; curr.FivePad=kFALSE;
827 //printf("\t--- s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
830 if(last.Row>-1) CreateCluster(last);
832 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 2 && fReconstructor->IsDebugStreaming()){
833 TTreeSRedirector* fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
834 (*fDebugStream) << "MakeClusters"
835 << "Detector=" << det
836 << "NMaxima=" << nMaximas
837 << "NClusters=" << fClusterROC
838 << "NCorrupted=" << nCorrupted
841 if (TestBit(kLabels)) AddLabels();
847 //_____________________________________________________________________________
848 Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Short_t *const Signals)
851 // Returns true if this row,col,time combination is a maximum.
852 // Gives back the padStatus and the signals of the center pad and the two neighbouring pads.
855 Signals[1] = fDigits->GetData(Max.Row, Max.Col, Max.Time);
856 if(Signals[1] < fMaxThresh) return kFALSE;
858 Float_t noiseMiddleThresh = fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.Col, Max.Row);
859 if (Signals[1] < noiseMiddleThresh) return kFALSE;
861 if (Max.Col + 1 >= fColMax || Max.Col < 1) return kFALSE;
864 fCalPadStatusROC->GetStatus(Max.Col-1, Max.Row)
865 ,fCalPadStatusROC->GetStatus(Max.Col, Max.Row)
866 ,fCalPadStatusROC->GetStatus(Max.Col+1, Max.Row)
869 Signals[0] = fDigits->GetData(Max.Row, Max.Col-1, Max.Time);
870 Signals[2] = fDigits->GetData(Max.Row, Max.Col+1, Max.Time);
872 if(!(status[0] | status[1] | status[2])) {//all pads are good
873 if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) {
874 if ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh)) {
875 Float_t noiseSumThresh = fMinLeftRightCutSigma
877 * fCalNoiseROC->GetValue(Max.Col, Max.Row);
878 if ((Signals[2]+Signals[0]+Signals[1]) < noiseSumThresh) return kFALSE;
883 } else { // at least one of the pads is bad, and reject candidates with more than 1 problematic pad
884 if (status[2] && (!(status[0] || status[1])) && Signals[1] > Signals[0] && Signals[0] >= fSigThresh) {
886 SetPadStatus(status[2], padStatus);
889 else if (status[0] && (!(status[1] || status[2])) && Signals[1] >= Signals[2] && Signals[2] >= fSigThresh) {
891 SetPadStatus(status[0], padStatus);
894 else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh))) {
895 Signals[1]=TMath::Nint(fMaxThresh);
896 SetPadStatus(status[1], padStatus);
903 //_____________________________________________________________________________
904 Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
907 // Look for 5 pad cluster with minimum in the middle
908 // Gives back the ratio
910 if (ThisMax.Col >= fColMax - 3) return kFALSE;
911 if (ThisMax.Col < fColMax - 5){
912 if (fDigits->GetData(ThisMax.Row, ThisMax.Col+4, ThisMax.Time) >= fSigThresh)
915 if (ThisMax.Col > 1) {
916 if (fDigits->GetData(ThisMax.Row, ThisMax.Col-2, ThisMax.Time) >= fSigThresh)
920 const Float_t kEpsilon = 0.01;
921 Double_t padSignal[5] = {ThisMax.Signals[0], ThisMax.Signals[1], ThisMax.Signals[2],
922 NeighbourMax.Signals[1], NeighbourMax.Signals[2]};
924 // Unfold the two maxima and set the signal on
925 // the overlapping pad to the ratio
926 Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
927 ThisMax.Signals[2] = TMath::Nint(ThisMax.Signals[2]*ratio);
928 NeighbourMax.Signals[0] = TMath::Nint(NeighbourMax.Signals[0]*(1-ratio));
929 ThisMax.FivePad=kTRUE;
930 NeighbourMax.FivePad=kTRUE;
935 //_____________________________________________________________________________
936 void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
939 // Creates a cluster at the given position and saves it in fRecPoints
943 Short_t signals[7] = { 0, 0, Max.Signals[0], Max.Signals[1], Max.Signals[2], 0, 0 };
944 if(!TestBit(kHLT)) CalcAdditionalInfo(Max, signals, nPadCount);
946 AliTRDcluster cluster(fDet, ((UChar_t) Max.Col), ((UChar_t) Max.Row), ((UChar_t) Max.Time), signals, fVolid);
947 cluster.SetNPads(nPadCount);
948 if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
949 else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
950 else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
952 cluster.SetFivePad(Max.FivePad);
953 // set pads status for the cluster
954 UChar_t maskPosition = GetCorruption(Max.padStatus);
956 cluster.SetPadMaskedPosition(maskPosition);
957 cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
960 // Transform the local cluster coordinates into calibrated
961 // space point positions defined in the local tracking system.
962 // Here the calibration for T0, Vdrift and ExB is applied as well.
963 if(!fTransform->Transform(&cluster)) return;
964 // Temporarily store the Max.Row, column and time bin of the center pad
965 // Used to later on assign the track indices
966 cluster.SetLabel(Max.Row, 0);
967 cluster.SetLabel(Max.Col, 1);
968 cluster.SetLabel(Max.Time,2);
970 //needed for HLT reconstruction
971 AddClusterToArray(&cluster);
973 // Store the index of the first cluster in the current ROC
974 if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
980 //_____________________________________________________________________________
981 void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
985 while (fDigits->GetData(Max.Row, Max.Col-ii, Max.Time) >= fSigThresh) {
988 if (Max.Col < ii) break;
992 while (fDigits->GetData(Max.Row, Max.Col+ii, Max.Time) >= fSigThresh) {
995 if (Max.Col+ii >= fColMax) break;
998 // Store the amplitudes of the pads in the cluster for later analysis
999 // and check whether one of these pads is masked in the database
1000 signals[2]=Max.Signals[0];
1001 signals[3]=Max.Signals[1];
1002 signals[4]=Max.Signals[2];
1003 for(Int_t i = 0; i<2; i++)
1006 signals[i] = fDigits->GetData(Max.Row, Max.Col-3+i, Max.Time);
1007 if(Max.Col+3-i < fColMax)
1008 signals[6-i] = fDigits->GetData(Max.Row, Max.Col+3-i, Max.Time);
1010 /*for (Int_t jPad = Max.Col-3; jPad <= Max.Col+3; jPad++) {
1011 if ((jPad >= 0) && (jPad < fColMax))
1012 signals[jPad-Max.Col+3] = TMath::Nint(fDigits->GetData(Max.Row,jPad,Max.Time));
1016 //_____________________________________________________________________________
1017 void AliTRDclusterizer::AddClusterToArray(AliTRDcluster* cluster)
1020 // Add a cluster to the array
1023 Int_t n = RecPoints()->GetEntriesFast();
1024 if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
1025 new((*RecPoints())[n]) AliTRDcluster(*cluster);
1028 //_____________________________________________________________________________
1029 void AliTRDclusterizer::AddTrackletsToArray()
1032 // Add the online tracklets of this chamber to the array
1035 UInt_t* trackletword;
1036 for(Int_t side=0; side<2; side++)
1039 trackletword=fTrackletContainer[side];
1040 while(trackletword[trkl]>0){
1041 Int_t n = TrackletsArray()->GetEntriesFast();
1042 AliTRDtrackletWord tmp(trackletword[trkl]);
1043 new((*TrackletsArray())[n]) AliTRDcluster(&tmp,fDet,fVolid);
1049 //_____________________________________________________________________________
1050 Bool_t AliTRDclusterizer::AddLabels()
1053 // Add the track indices to the found clusters
1056 const Int_t kNclus = 3;
1057 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1058 const Int_t kNtrack = kNdict * kNclus;
1060 Int_t iClusterROC = 0;
1067 // Temporary array to collect the track indices
1068 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1070 // Loop through the dictionary arrays one-by-one
1071 // to keep memory consumption low
1072 AliTRDarrayDictionary *tracksIn = 0; //mod
1073 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1075 // tracksIn should be expanded beforehand!
1076 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1078 // Loop though the clusters found in this ROC
1079 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1081 AliTRDcluster *cluster = (AliTRDcluster *)
1082 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1083 row = cluster->GetLabel(0);
1084 col = cluster->GetLabel(1);
1085 time = cluster->GetLabel(2);
1087 for (iPad = 0; iPad < kNclus; iPad++) {
1088 Int_t iPadCol = col - 1 + iPad;
1089 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1090 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1097 // Copy the track indices into the cluster
1098 // Loop though the clusters found in this ROC
1099 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1101 AliTRDcluster *cluster = (AliTRDcluster *)
1102 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1103 cluster->SetLabel(-9999,0);
1104 cluster->SetLabel(-9999,1);
1105 cluster->SetLabel(-9999,2);
1107 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1111 delete [] idxTracks;
1117 //_____________________________________________________________________________
1118 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, const Double_t *const padSignal) const
1121 // Method to unfold neighbouring maxima.
1122 // The charge ratio on the overlapping pad is calculated
1123 // until there is no more change within the range given by eps.
1124 // The resulting ratio is then returned to the calling method.
1127 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1129 AliError("No AliTRDcalibDB instance available\n");
1134 Int_t itStep = 0; // Count iteration steps
1136 Double_t ratio = 0.5; // Start value for ratio
1137 Double_t prevRatio = 0.0; // Store previous ratio
1139 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1140 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1141 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1143 // Start the iteration
1144 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1149 // Cluster position according to charge ratio
1150 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1151 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1152 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1153 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1155 // Set cluster charge ratio
1156 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1157 Double_t ampLeft = padSignal[1] / newSignal[1];
1158 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1159 Double_t ampRight = padSignal[3] / newSignal[1];
1161 // Apply pad response to parameters
1162 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1163 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1165 // Calculate new overlapping ratio
1166 ratio = TMath::Min((Double_t) 1.0
1167 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1175 //_____________________________________________________________________________
1176 void AliTRDclusterizer::TailCancelation()
1179 // Applies the tail cancelation and gain factors:
1180 // Transform fDigits to fDigits
1187 Double_t *inADC = new Double_t[fTimeTotal]; // ADC data before tail cancellation
1188 Double_t *outADC = new Double_t[fTimeTotal]; // ADC data after tail cancellation
1190 fIndexes->ResetCounters();
1191 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
1192 while(fIndexes->NextRCIndex(iRow, iCol))
1194 Float_t fCalGainFactorROCValue = fCalGainFactorROC->GetValue(iCol,iRow);
1195 Double_t gain = fCalGainFactorDetValue
1196 * fCalGainFactorROCValue;
1198 Bool_t corrupted = kFALSE;
1199 for (iTime = 0; iTime < fTimeTotal; iTime++)
1201 // Apply gain gain factor
1202 inADC[iTime] = fDigits->GetData(iRow,iCol,iTime);
1203 if (fCalPadStatusROC->GetStatus(iCol, iRow)) corrupted = kTRUE;
1204 inADC[iTime] /= gain;
1205 outADC[iTime] = inADC[iTime];
1206 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 7 && fReconstructor->IsDebugStreaming()){
1207 (*fDebugStream) << "TailCancellation"
1211 << "inADC=" << inADC[iTime]
1213 << "outADC=" << outADC[iTime]
1214 << "corrupted=" << corrupted
1220 // Apply the tail cancelation via the digital filter
1221 // (only for non-coorupted pads)
1222 DeConvExp(&inADC[0],&outADC[0],fTimeTotal,fReconstructor->GetRecoParam() ->GetTCnexp());
1225 for(iTime = 0; iTime < fTimeTotal; iTime++)//while (fIndexes->NextTbinIndex(iTime))
1227 // Store the amplitude of the digit if above threshold
1228 if (outADC[iTime] > 0)
1229 fDigits->SetData(iRow,iCol,iTime,TMath::Nint(outADC[iTime]));
1231 fDigits->SetData(iRow,iCol,iTime,0);
1234 } // while irow icol
1243 //_____________________________________________________________________________
1244 void AliTRDclusterizer::DeConvExp(const Double_t *const source, Double_t *const target
1245 ,const Int_t n, const Int_t nexp)
1248 // Tail cancellation by deconvolution for PASA v4 TRF
1252 Double_t coefficients[2];
1254 // Initialization (coefficient = alpha, rates = lambda)
1260 if (nexp == 1) { // 1 Exponentials
1266 if (nexp == 2) { // 2 Exponentials
1268 fReconstructor->GetRecoParam()->GetTCParams(par);
1269 r1 = par[0];//1.156;
1270 r2 = par[1];//0.130;
1271 c1 = par[2];//0.114;
1272 c2 = par[3];//0.624;
1275 coefficients[0] = c1;
1276 coefficients[1] = c2;
1280 rates[0] = TMath::Exp(-dt/(r1));
1281 rates[1] = TMath::Exp(-dt/(r2));
1286 Double_t reminder[2];
1287 Double_t correction = 0.0;
1288 Double_t result = 0.0;
1290 // Attention: computation order is important
1291 for (k = 0; k < nexp; k++) {
1295 for (i = 0; i < n; i++) {
1297 result = (source[i] - correction); // No rescaling
1300 for (k = 0; k < nexp; k++) {
1301 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1305 for (k = 0; k < nexp; k++) {
1306 correction += reminder[k];
1313 //_____________________________________________________________________________
1314 void AliTRDclusterizer::ResetRecPoints()
1317 // Resets the list of rec points
1321 fRecPoints->Delete();
1326 //_____________________________________________________________________________
1327 TClonesArray *AliTRDclusterizer::RecPoints()
1330 // Returns the list of rec points
1334 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1335 // determine number of clusters which has to be allocated
1336 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1338 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1340 //SetClustersOwner(kTRUE);
1341 AliTRDReconstructor::SetClusters(0x0);
1347 //_____________________________________________________________________________
1348 TClonesArray *AliTRDclusterizer::TrackletsArray()
1351 // Returns the list of rec points
1354 if (!fTracklets && fReconstructor->IsProcessingTracklets()) {
1355 fTracklets = new TClonesArray("AliTRDcluster", 2*MAXTRACKLETSPERHC);
1356 //SetClustersOwner(kTRUE);
1357 //AliTRDReconstructor::SetTracklets(0x0);