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->ResetArrays(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 // digits should be expanded beforehand!
732 // digitsIn->Expand();
733 fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
735 // This is to take care of switched off super modules
736 if (!fDigits->HasData()) return kFALSE;
738 // Subtract the ADC baseline
739 fDigits->SubtractBaseline(fDigitsManager->GetDigitsParam()->GetADCbaseline());
741 fIndexes = fDigitsManager->GetIndexes(det);
742 if (fIndexes->IsAllocated() == kFALSE) {
743 AliError("Indexes do not exist!");
747 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
749 AliFatal("No AliTRDcalibDB instance available\n");
753 if (!fReconstructor){
754 AliError("Reconstructor not set\n");
758 fMaxThresh = fReconstructor->GetRecoParam()->GetClusMaxThresh();
759 fSigThresh = fReconstructor->GetRecoParam()->GetClusSigThresh();
760 fMinMaxCutSigma = fReconstructor->GetRecoParam()->GetMinMaxCutSigma();
761 fMinLeftRightCutSigma = fReconstructor->GetRecoParam()->GetMinLeftRightCutSigma();
763 Int_t istack = fIndexes->GetStack();
764 fLayer = fIndexes->GetLayer();
765 Int_t isector = fIndexes->GetSM();
767 // Start clustering in the chamber
769 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
771 AliError("Strange Detector number Missmatch!");
775 // TRD space point transformation
776 fTransform->SetDetector(det);
778 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
779 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
780 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
782 if(fReconstructor->IsProcessingTracklets() && fTrackletContainer)
783 AddTrackletsToArray();
785 fColMax = fDigits->GetNcol();
786 //Int_t nRowMax = fDigits->GetNrow();
787 fTimeTotal = fDigits->GetNtime();
789 // Detector wise calibration object for the gain factors
790 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
791 // Calibration object with pad wise values for the gain factors
792 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
793 // Calibration value for chamber wise gain factor
794 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
796 // Detector wise calibration object for the noise
797 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
798 // Calibration object with pad wise values for the noise
799 fCalNoiseROC = calibration->GetNoiseROC(fDet);
800 // Calibration value for chamber wise noise
801 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
803 // Calibration object with the pad status
804 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
806 SetBit(kLUT, fReconstructor->GetRecoParam()->UseLUT());
807 SetBit(kGAUS, fReconstructor->GetRecoParam()->UseGAUS());
808 SetBit(kHLT, fReconstructor->IsHLT());
810 firstClusterROC = -1;
813 // Apply the gain and the tail cancelation via digital filter
814 if(fReconstructor->GetRecoParam()->UseTailCancelation()) TailCancelation();
816 MaxStruct curr, last;
817 Int_t nMaximas = 0, nCorrupted = 0;
819 // Here the clusterfining is happening
821 for(curr.Time = 0; curr.Time < fTimeTotal; curr.Time++){
822 while(fIndexes->NextRCIndex(curr.Row, curr.Col)){
823 //printf("\nCHECK r[%2d] c[%3d] t[%d]\n", curr.Row, curr.Col, curr.Time);
824 if(IsMaximum(curr, curr.padStatus, &curr.Signals[0])){
825 //printf("\tMAX s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
827 if(curr.Time==last.Time && curr.Row==last.Row && curr.Col==last.Col+2) FivePadCluster(last, curr);
830 last=curr; curr.FivePad=kFALSE;
832 //printf("\t--- s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
835 if(last.Row>-1) CreateCluster(last);
837 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 2 && fReconstructor->IsDebugStreaming()){
838 TTreeSRedirector* fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
839 (*fDebugStream) << "MakeClusters"
840 << "Detector=" << det
841 << "NMaxima=" << nMaximas
842 << "NClusters=" << fClusterROC
843 << "NCorrupted=" << nCorrupted
846 if (TestBit(kLabels)) AddLabels();
852 //_____________________________________________________________________________
853 Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Short_t *const Signals)
856 // Returns true if this row,col,time combination is a maximum.
857 // Gives back the padStatus and the signals of the center pad and the two neighbouring pads.
860 Signals[1] = fDigits->GetData(Max.Row, Max.Col, Max.Time);
861 if(Signals[1] < fMaxThresh) return kFALSE;
863 Float_t noiseMiddleThresh = fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.Col, Max.Row);
864 if (Signals[1] < noiseMiddleThresh) return kFALSE;
866 if (Max.Col + 1 >= fColMax || Max.Col < 1) return kFALSE;
869 fCalPadStatusROC->GetStatus(Max.Col-1, Max.Row)
870 ,fCalPadStatusROC->GetStatus(Max.Col, Max.Row)
871 ,fCalPadStatusROC->GetStatus(Max.Col+1, Max.Row)
874 Signals[0] = fDigits->GetData(Max.Row, Max.Col-1, Max.Time);
875 Signals[2] = fDigits->GetData(Max.Row, Max.Col+1, Max.Time);
877 if(!(status[0] | status[1] | status[2])) {//all pads are good
878 if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) {
879 if ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh)) {
880 Float_t noiseSumThresh = fMinLeftRightCutSigma
882 * fCalNoiseROC->GetValue(Max.Col, Max.Row);
883 if ((Signals[2]+Signals[0]+Signals[1]) < noiseSumThresh) return kFALSE;
888 } else { // at least one of the pads is bad, and reject candidates with more than 1 problematic pad
889 if (status[2] && (!(status[0] || status[1])) && Signals[1] > Signals[0] && Signals[0] >= fSigThresh) {
891 SetPadStatus(status[2], padStatus);
894 else if (status[0] && (!(status[1] || status[2])) && Signals[1] >= Signals[2] && Signals[2] >= fSigThresh) {
896 SetPadStatus(status[0], padStatus);
899 else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh))) {
900 Signals[1]=TMath::Nint(fMaxThresh);
901 SetPadStatus(status[1], padStatus);
908 //_____________________________________________________________________________
909 Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
912 // Look for 5 pad cluster with minimum in the middle
913 // Gives back the ratio
915 if (ThisMax.Col >= fColMax - 3) return kFALSE;
916 if (ThisMax.Col < fColMax - 5){
917 if (fDigits->GetData(ThisMax.Row, ThisMax.Col+4, ThisMax.Time) >= fSigThresh)
920 if (ThisMax.Col > 1) {
921 if (fDigits->GetData(ThisMax.Row, ThisMax.Col-2, ThisMax.Time) >= fSigThresh)
925 const Float_t kEpsilon = 0.01;
926 Double_t padSignal[5] = {ThisMax.Signals[0], ThisMax.Signals[1], ThisMax.Signals[2],
927 NeighbourMax.Signals[1], NeighbourMax.Signals[2]};
929 // Unfold the two maxima and set the signal on
930 // the overlapping pad to the ratio
931 Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
932 ThisMax.Signals[2] = TMath::Nint(ThisMax.Signals[2]*ratio);
933 NeighbourMax.Signals[0] = TMath::Nint(NeighbourMax.Signals[0]*(1-ratio));
934 ThisMax.FivePad=kTRUE;
935 NeighbourMax.FivePad=kTRUE;
940 //_____________________________________________________________________________
941 void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
944 // Creates a cluster at the given position and saves it in fRecPoints
948 Short_t signals[7] = { 0, 0, Max.Signals[0], Max.Signals[1], Max.Signals[2], 0, 0 };
949 if(!TestBit(kHLT)) CalcAdditionalInfo(Max, signals, nPadCount);
951 AliTRDcluster cluster(fDet, ((UChar_t) Max.Col), ((UChar_t) Max.Row), ((UChar_t) Max.Time), signals, fVolid);
952 cluster.SetNPads(nPadCount);
953 if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
954 else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
955 else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
957 cluster.SetFivePad(Max.FivePad);
958 // set pads status for the cluster
959 UChar_t maskPosition = GetCorruption(Max.padStatus);
961 cluster.SetPadMaskedPosition(maskPosition);
962 cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
965 // Transform the local cluster coordinates into calibrated
966 // space point positions defined in the local tracking system.
967 // Here the calibration for T0, Vdrift and ExB is applied as well.
968 if(!fTransform->Transform(&cluster)) return;
969 // Temporarily store the Max.Row, column and time bin of the center pad
970 // Used to later on assign the track indices
971 cluster.SetLabel(Max.Row, 0);
972 cluster.SetLabel(Max.Col, 1);
973 cluster.SetLabel(Max.Time,2);
975 //needed for HLT reconstruction
976 AddClusterToArray(&cluster);
978 // Store the index of the first cluster in the current ROC
979 if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
985 //_____________________________________________________________________________
986 void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
990 while (fDigits->GetData(Max.Row, Max.Col-ii, Max.Time) >= fSigThresh) {
993 if (Max.Col < ii) break;
997 while (fDigits->GetData(Max.Row, Max.Col+ii, Max.Time) >= fSigThresh) {
1000 if (Max.Col+ii >= fColMax) break;
1003 // Store the amplitudes of the pads in the cluster for later analysis
1004 // and check whether one of these pads is masked in the database
1005 signals[2]=Max.Signals[0];
1006 signals[3]=Max.Signals[1];
1007 signals[4]=Max.Signals[2];
1008 for(Int_t i = 0; i<2; i++)
1011 signals[i] = fDigits->GetData(Max.Row, Max.Col-3+i, Max.Time);
1012 if(Max.Col+3-i < fColMax)
1013 signals[6-i] = fDigits->GetData(Max.Row, Max.Col+3-i, Max.Time);
1015 /*for (Int_t jPad = Max.Col-3; jPad <= Max.Col+3; jPad++) {
1016 if ((jPad >= 0) && (jPad < fColMax))
1017 signals[jPad-Max.Col+3] = TMath::Nint(fDigits->GetData(Max.Row,jPad,Max.Time));
1021 //_____________________________________________________________________________
1022 void AliTRDclusterizer::AddClusterToArray(AliTRDcluster* cluster)
1025 // Add a cluster to the array
1028 Int_t n = RecPoints()->GetEntriesFast();
1029 if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
1030 new((*RecPoints())[n]) AliTRDcluster(*cluster);
1033 //_____________________________________________________________________________
1034 void AliTRDclusterizer::AddTrackletsToArray()
1037 // Add the online tracklets of this chamber to the array
1040 UInt_t* trackletword;
1041 for(Int_t side=0; side<2; side++)
1044 trackletword=fTrackletContainer[side];
1045 while(trackletword[trkl]>0){
1046 Int_t n = TrackletsArray()->GetEntriesFast();
1047 AliTRDtrackletWord tmp(trackletword[trkl]);
1048 new((*TrackletsArray())[n]) AliTRDcluster(&tmp,fDet,fVolid);
1054 //_____________________________________________________________________________
1055 Bool_t AliTRDclusterizer::AddLabels()
1058 // Add the track indices to the found clusters
1061 const Int_t kNclus = 3;
1062 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1063 const Int_t kNtrack = kNdict * kNclus;
1065 Int_t iClusterROC = 0;
1072 // Temporary array to collect the track indices
1073 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1075 // Loop through the dictionary arrays one-by-one
1076 // to keep memory consumption low
1077 AliTRDarrayDictionary *tracksIn = 0; //mod
1078 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1080 // tracksIn should be expanded beforehand!
1081 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1083 // Loop though the clusters found in this ROC
1084 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1086 AliTRDcluster *cluster = (AliTRDcluster *)
1087 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1088 row = cluster->GetLabel(0);
1089 col = cluster->GetLabel(1);
1090 time = cluster->GetLabel(2);
1092 for (iPad = 0; iPad < kNclus; iPad++) {
1093 Int_t iPadCol = col - 1 + iPad;
1094 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1095 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1102 // Copy the track indices into the cluster
1103 // Loop though the clusters found in this ROC
1104 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1106 AliTRDcluster *cluster = (AliTRDcluster *)
1107 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1108 cluster->SetLabel(-9999,0);
1109 cluster->SetLabel(-9999,1);
1110 cluster->SetLabel(-9999,2);
1112 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1116 delete [] idxTracks;
1122 //_____________________________________________________________________________
1123 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, const Double_t *const padSignal) const
1126 // Method to unfold neighbouring maxima.
1127 // The charge ratio on the overlapping pad is calculated
1128 // until there is no more change within the range given by eps.
1129 // The resulting ratio is then returned to the calling method.
1132 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1134 AliError("No AliTRDcalibDB instance available\n");
1139 Int_t itStep = 0; // Count iteration steps
1141 Double_t ratio = 0.5; // Start value for ratio
1142 Double_t prevRatio = 0.0; // Store previous ratio
1144 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1145 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1146 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1148 // Start the iteration
1149 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1154 // Cluster position according to charge ratio
1155 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1156 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1157 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1158 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1160 // Set cluster charge ratio
1161 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1162 Double_t ampLeft = padSignal[1] / newSignal[1];
1163 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1164 Double_t ampRight = padSignal[3] / newSignal[1];
1166 // Apply pad response to parameters
1167 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1168 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1170 // Calculate new overlapping ratio
1171 ratio = TMath::Min((Double_t) 1.0
1172 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1180 //_____________________________________________________________________________
1181 void AliTRDclusterizer::TailCancelation()
1184 // Applies the tail cancelation and gain factors:
1185 // Transform fDigits to fDigits
1192 Double_t *inADC = new Double_t[fTimeTotal]; // ADC data before tail cancellation
1193 Double_t *outADC = new Double_t[fTimeTotal]; // ADC data after tail cancellation
1195 fIndexes->ResetCounters();
1196 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
1197 while(fIndexes->NextRCIndex(iRow, iCol))
1199 Float_t fCalGainFactorROCValue = fCalGainFactorROC->GetValue(iCol,iRow);
1200 Double_t gain = fCalGainFactorDetValue
1201 * fCalGainFactorROCValue;
1203 Bool_t corrupted = kFALSE;
1204 for (iTime = 0; iTime < fTimeTotal; iTime++)
1206 // Apply gain gain factor
1207 inADC[iTime] = fDigits->GetData(iRow,iCol,iTime);
1208 if (fCalPadStatusROC->GetStatus(iCol, iRow)) corrupted = kTRUE;
1209 inADC[iTime] /= gain;
1210 outADC[iTime] = inADC[iTime];
1211 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 7 && fReconstructor->IsDebugStreaming()){
1212 (*fDebugStream) << "TailCancellation"
1216 << "inADC=" << inADC[iTime]
1218 << "outADC=" << outADC[iTime]
1219 << "corrupted=" << corrupted
1225 // Apply the tail cancelation via the digital filter
1226 // (only for non-coorupted pads)
1227 DeConvExp(&inADC[0],&outADC[0],fTimeTotal,fReconstructor->GetRecoParam() ->GetTCnexp());
1230 for(iTime = 0; iTime < fTimeTotal; iTime++)//while (fIndexes->NextTbinIndex(iTime))
1232 // Store the amplitude of the digit if above threshold
1233 if (outADC[iTime] > 0)
1234 fDigits->SetData(iRow,iCol,iTime,TMath::Nint(outADC[iTime]));
1236 fDigits->SetData(iRow,iCol,iTime,0);
1239 } // while irow icol
1248 //_____________________________________________________________________________
1249 void AliTRDclusterizer::DeConvExp(const Double_t *const source, Double_t *const target
1250 ,const Int_t n, const Int_t nexp)
1253 // Tail cancellation by deconvolution for PASA v4 TRF
1257 Double_t coefficients[2];
1259 // Initialization (coefficient = alpha, rates = lambda)
1265 if (nexp == 1) { // 1 Exponentials
1271 if (nexp == 2) { // 2 Exponentials
1273 fReconstructor->GetRecoParam()->GetTCParams(par);
1274 r1 = par[0];//1.156;
1275 r2 = par[1];//0.130;
1276 c1 = par[2];//0.114;
1277 c2 = par[3];//0.624;
1280 coefficients[0] = c1;
1281 coefficients[1] = c2;
1285 rates[0] = TMath::Exp(-dt/(r1));
1286 rates[1] = TMath::Exp(-dt/(r2));
1291 Double_t reminder[2];
1292 Double_t correction = 0.0;
1293 Double_t result = 0.0;
1295 // Attention: computation order is important
1296 for (k = 0; k < nexp; k++) {
1300 for (i = 0; i < n; i++) {
1302 result = (source[i] - correction); // No rescaling
1305 for (k = 0; k < nexp; k++) {
1306 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1310 for (k = 0; k < nexp; k++) {
1311 correction += reminder[k];
1318 //_____________________________________________________________________________
1319 void AliTRDclusterizer::ResetRecPoints()
1322 // Resets the list of rec points
1326 fRecPoints->Delete();
1331 //_____________________________________________________________________________
1332 TClonesArray *AliTRDclusterizer::RecPoints()
1335 // Returns the list of rec points
1339 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1340 // determine number of clusters which has to be allocated
1341 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1343 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1345 //SetClustersOwner(kTRUE);
1346 AliTRDReconstructor::SetClusters(0x0);
1352 //_____________________________________________________________________________
1353 TClonesArray *AliTRDclusterizer::TrackletsArray()
1356 // Returns the list of rec points
1359 if (!fTracklets && fReconstructor->IsProcessingTracklets()) {
1360 fTracklets = new TClonesArray("AliTRDcluster", 2*MAXTRACKLETSPERHC);
1361 //SetClustersOwner(kTRUE);
1362 //AliTRDReconstructor::SetTracklets(0x0);