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 // Subtract the ADC baseline
566 digitsIn->SubtractBaseline(fDigitsManager->GetDigitsParam()->GetADCbaseline());
567 digitsIn->DeleteNegatives(); // Restore digits array to >=0 values
568 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
569 if (indexes->IsAllocated() == kFALSE){
570 fDigitsManager->BuildIndexes(i);
574 if (indexes->HasEntry()){
575 if (TestBit(kLabels)){
576 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++){
577 AliTRDarrayDictionary *tracksIn = 0; //mod
578 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(i,iDict); //mod
582 fR = MakeClusters(i);
583 fReturn = fR && fReturn;
587 // if(IsWritingClusters()) WriteClusters(i);
591 // No compress just remove
592 fDigitsManager->RemoveDigits(i);
593 fDigitsManager->RemoveDictionaries(i);
594 fDigitsManager->ClearIndexes(i);
597 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
599 AliInfo(Form("Number of found clusters : %d", RecPoints()->GetEntriesFast()));
605 //_____________________________________________________________________________
606 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
609 // Creates clusters from raw data
612 return Raw2ClustersChamber(rawReader);
616 //_____________________________________________________________________________
617 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
620 // Creates clusters from raw data
623 // Create the digits manager
624 if (!fDigitsManager){
625 fDigitsManager = new AliTRDdigitsManager(kTRUE);
626 fDigitsManager->CreateArrays();
629 fDigitsManager->SetUseDictionaries(TestBit(kLabels));
631 // tracklet container for raw tracklet writing
632 if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
633 // maximum tracklets for one HC
634 const Int_t kTrackletChmb=256;
635 fTrackletContainer = new UInt_t *[2];
636 fTrackletContainer[0] = new UInt_t[kTrackletChmb];
637 fTrackletContainer[1] = new UInt_t[kTrackletChmb];
640 AliTRDrawStreamBase::SetSubtractBaseline(10);
641 AliTRDrawStreamBase *input = AliTRDrawStreamBase::GetRawStream(rawReader);
642 if(fReconstructor->IsHLT())
643 input->SetSharedPadReadout(kFALSE);
645 AliInfo(Form("Stream version: %s", input->IsA()->GetName()));
648 while ((det = input->NextChamber(fDigitsManager,fTrackletContainer)) >= 0){
649 Bool_t iclusterBranch = kFALSE;
650 if (fDigitsManager->GetIndexes(det)->HasEntry()){
651 iclusterBranch = MakeClusters(det);
654 fDigitsManager->ResetArrays(det);
656 if (!fReconstructor->IsWritingTracklets()) continue;
657 if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
660 if (fTrackletContainer){
661 delete [] fTrackletContainer[0];
662 delete [] fTrackletContainer[1];
663 delete [] fTrackletContainer;
664 fTrackletContainer = NULL;
667 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
669 delete fDigitsManager;
670 fDigitsManager = NULL;
675 AliInfo(Form("Number of found clusters : %d", fNoOfClusters));
680 //_____________________________________________________________________________
681 UChar_t AliTRDclusterizer::GetStatus(Short_t &signal)
684 // Check if a pad is masked
689 if(signal>0 && TESTBIT(signal, 10)){
691 for(int ibit=0; ibit<4; ibit++){
692 if(TESTBIT(signal, 11+ibit)){
693 SETBIT(status, ibit);
694 CLRBIT(signal, 11+ibit);
701 //_____________________________________________________________________________
702 void AliTRDclusterizer::SetPadStatus(const UChar_t status, UChar_t &out) const {
704 // Set the pad status into out
705 // First three bits are needed for the position encoding
710 //_____________________________________________________________________________
711 UChar_t AliTRDclusterizer::GetPadStatus(UChar_t encoding) const {
713 // return the staus encoding of the corrupted pad
715 return static_cast<UChar_t>(encoding >> 3);
718 //_____________________________________________________________________________
719 Int_t AliTRDclusterizer::GetCorruption(UChar_t encoding) const {
721 // Return the position of the corruption
726 //_____________________________________________________________________________
727 Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
730 // Generates the cluster.
734 // digits should be expanded beforehand!
735 // digitsIn->Expand();
736 fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
738 // This is to take care of switched off super modules
739 if (!fDigits->HasData()) return kFALSE;
741 // Subtract the ADC baseline
742 fDigits->SubtractBaseline(fDigitsManager->GetDigitsParam()->GetADCbaseline());
744 fIndexes = fDigitsManager->GetIndexes(det);
745 if (fIndexes->IsAllocated() == kFALSE) {
746 AliError("Indexes do not exist!");
750 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
752 AliFatal("No AliTRDcalibDB instance available\n");
756 if (!fReconstructor){
757 AliError("Reconstructor not set\n");
761 fMaxThresh = fReconstructor->GetRecoParam()->GetClusMaxThresh();
762 fSigThresh = fReconstructor->GetRecoParam()->GetClusSigThresh();
763 fMinMaxCutSigma = fReconstructor->GetRecoParam()->GetMinMaxCutSigma();
764 fMinLeftRightCutSigma = fReconstructor->GetRecoParam()->GetMinLeftRightCutSigma();
766 Int_t istack = fIndexes->GetStack();
767 fLayer = fIndexes->GetLayer();
768 Int_t isector = fIndexes->GetSM();
770 // Start clustering in the chamber
772 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
774 AliError("Strange Detector number Missmatch!");
778 // TRD space point transformation
779 fTransform->SetDetector(det);
781 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
782 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
783 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
785 if(fReconstructor->IsProcessingTracklets() && fTrackletContainer)
786 AddTrackletsToArray();
788 fColMax = fDigits->GetNcol();
789 //Int_t nRowMax = fDigits->GetNrow();
790 fTimeTotal = fDigits->GetNtime();
792 // Detector wise calibration object for the gain factors
793 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
794 // Calibration object with pad wise values for the gain factors
795 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
796 // Calibration value for chamber wise gain factor
797 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
799 // Detector wise calibration object for the noise
800 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
801 // Calibration object with pad wise values for the noise
802 fCalNoiseROC = calibration->GetNoiseROC(fDet);
803 // Calibration value for chamber wise noise
804 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
806 // Calibration object with the pad status
807 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
809 SetBit(kLUT, fReconstructor->GetRecoParam()->UseLUT());
810 SetBit(kGAUS, fReconstructor->GetRecoParam()->UseGAUS());
811 SetBit(kHLT, fReconstructor->IsHLT());
813 firstClusterROC = -1;
816 // Apply the gain and the tail cancelation via digital filter
817 if(fReconstructor->GetRecoParam()->UseTailCancelation()) TailCancelation();
819 MaxStruct curr, last;
820 Int_t nMaximas = 0, nCorrupted = 0;
822 // Here the clusterfining is happening
824 for(curr.Time = 0; curr.Time < fTimeTotal; curr.Time++){
825 while(fIndexes->NextRCIndex(curr.Row, curr.Col)){
826 //printf("\nCHECK r[%2d] c[%3d] t[%d]\n", curr.Row, curr.Col, curr.Time);
827 if(IsMaximum(curr, curr.padStatus, &curr.Signals[0])){
828 //printf("\tMAX s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
830 if(curr.Time==last.Time && curr.Row==last.Row && curr.Col==last.Col+2) FivePadCluster(last, curr);
833 last=curr; curr.FivePad=kFALSE;
835 //printf("\t--- s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
838 if(last.Row>-1) CreateCluster(last);
840 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 2 && fReconstructor->IsDebugStreaming()){
841 TTreeSRedirector* fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
842 (*fDebugStream) << "MakeClusters"
843 << "Detector=" << det
844 << "NMaxima=" << nMaximas
845 << "NClusters=" << fClusterROC
846 << "NCorrupted=" << nCorrupted
849 if (TestBit(kLabels)) AddLabels();
855 //_____________________________________________________________________________
856 Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Short_t *const Signals)
859 // Returns true if this row,col,time combination is a maximum.
860 // Gives back the padStatus and the signals of the center pad and the two neighbouring pads.
863 Signals[1] = fDigits->GetData(Max.Row, Max.Col, Max.Time);
864 if(Signals[1] < fMaxThresh) return kFALSE;
866 Float_t noiseMiddleThresh = fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.Col, Max.Row);
867 if (Signals[1] < noiseMiddleThresh) return kFALSE;
869 if (Max.Col + 1 >= fColMax || Max.Col < 1) return kFALSE;
872 fCalPadStatusROC->GetStatus(Max.Col-1, Max.Row)
873 ,fCalPadStatusROC->GetStatus(Max.Col, Max.Row)
874 ,fCalPadStatusROC->GetStatus(Max.Col+1, Max.Row)
877 Signals[0] = fDigits->GetData(Max.Row, Max.Col-1, Max.Time);
878 Signals[2] = fDigits->GetData(Max.Row, Max.Col+1, Max.Time);
880 if(!(status[0] | status[1] | status[2])) {//all pads are good
881 if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) {
882 if ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh)) {
883 Float_t noiseSumThresh = fMinLeftRightCutSigma
885 * fCalNoiseROC->GetValue(Max.Col, Max.Row);
886 if ((Signals[2]+Signals[0]+Signals[1]) < noiseSumThresh) return kFALSE;
891 } else { // at least one of the pads is bad, and reject candidates with more than 1 problematic pad
892 if (status[2] && (!(status[0] || status[1])) && Signals[1] > Signals[0] && Signals[0] >= fSigThresh) {
894 SetPadStatus(status[2], padStatus);
897 else if (status[0] && (!(status[1] || status[2])) && Signals[1] >= Signals[2] && Signals[2] >= fSigThresh) {
899 SetPadStatus(status[0], padStatus);
902 else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh))) {
903 Signals[1]=TMath::Nint(fMaxThresh);
904 SetPadStatus(status[1], padStatus);
911 //_____________________________________________________________________________
912 Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
915 // Look for 5 pad cluster with minimum in the middle
916 // Gives back the ratio
918 if (ThisMax.Col >= fColMax - 3) return kFALSE;
919 if (ThisMax.Col < fColMax - 5){
920 if (fDigits->GetData(ThisMax.Row, ThisMax.Col+4, ThisMax.Time) >= fSigThresh)
923 if (ThisMax.Col > 1) {
924 if (fDigits->GetData(ThisMax.Row, ThisMax.Col-2, ThisMax.Time) >= fSigThresh)
928 const Float_t kEpsilon = 0.01;
929 Double_t padSignal[5] = {ThisMax.Signals[0], ThisMax.Signals[1], ThisMax.Signals[2],
930 NeighbourMax.Signals[1], NeighbourMax.Signals[2]};
932 // Unfold the two maxima and set the signal on
933 // the overlapping pad to the ratio
934 Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
935 ThisMax.Signals[2] = TMath::Nint(ThisMax.Signals[2]*ratio);
936 NeighbourMax.Signals[0] = TMath::Nint(NeighbourMax.Signals[0]*(1-ratio));
937 ThisMax.FivePad=kTRUE;
938 NeighbourMax.FivePad=kTRUE;
943 //_____________________________________________________________________________
944 void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
947 // Creates a cluster at the given position and saves it in fRecPoints
951 Short_t signals[7] = { 0, 0, Max.Signals[0], Max.Signals[1], Max.Signals[2], 0, 0 };
952 if(!TestBit(kHLT)) CalcAdditionalInfo(Max, signals, nPadCount);
954 AliTRDcluster cluster(fDet, ((UChar_t) Max.Col), ((UChar_t) Max.Row), ((UChar_t) Max.Time), signals, fVolid);
955 cluster.SetNPads(nPadCount);
956 if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
957 else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
958 else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
960 cluster.SetFivePad(Max.FivePad);
961 // set pads status for the cluster
962 UChar_t maskPosition = GetCorruption(Max.padStatus);
964 cluster.SetPadMaskedPosition(maskPosition);
965 cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
968 // Transform the local cluster coordinates into calibrated
969 // space point positions defined in the local tracking system.
970 // Here the calibration for T0, Vdrift and ExB is applied as well.
971 if(!fTransform->Transform(&cluster)) return;
972 // Temporarily store the Max.Row, column and time bin of the center pad
973 // Used to later on assign the track indices
974 cluster.SetLabel(Max.Row, 0);
975 cluster.SetLabel(Max.Col, 1);
976 cluster.SetLabel(Max.Time,2);
978 //needed for HLT reconstruction
979 AddClusterToArray(&cluster);
981 // Store the index of the first cluster in the current ROC
982 if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
988 //_____________________________________________________________________________
989 void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
993 while (fDigits->GetData(Max.Row, Max.Col-ii, Max.Time) >= fSigThresh) {
996 if (Max.Col < ii) break;
1000 while (fDigits->GetData(Max.Row, Max.Col+ii, Max.Time) >= fSigThresh) {
1003 if (Max.Col+ii >= fColMax) break;
1006 // Store the amplitudes of the pads in the cluster for later analysis
1007 // and check whether one of these pads is masked in the database
1008 signals[2]=Max.Signals[0];
1009 signals[3]=Max.Signals[1];
1010 signals[4]=Max.Signals[2];
1011 for(Int_t i = 0; i<2; i++)
1014 signals[i] = fDigits->GetData(Max.Row, Max.Col-3+i, Max.Time);
1015 if(Max.Col+3-i < fColMax)
1016 signals[6-i] = fDigits->GetData(Max.Row, Max.Col+3-i, Max.Time);
1018 /*for (Int_t jPad = Max.Col-3; jPad <= Max.Col+3; jPad++) {
1019 if ((jPad >= 0) && (jPad < fColMax))
1020 signals[jPad-Max.Col+3] = TMath::Nint(fDigits->GetData(Max.Row,jPad,Max.Time));
1024 //_____________________________________________________________________________
1025 void AliTRDclusterizer::AddClusterToArray(AliTRDcluster* cluster)
1028 // Add a cluster to the array
1031 Int_t n = RecPoints()->GetEntriesFast();
1032 if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
1033 new((*RecPoints())[n]) AliTRDcluster(*cluster);
1036 //_____________________________________________________________________________
1037 void AliTRDclusterizer::AddTrackletsToArray()
1040 // Add the online tracklets of this chamber to the array
1043 UInt_t* trackletword;
1044 for(Int_t side=0; side<2; side++)
1047 trackletword=fTrackletContainer[side];
1048 while(trackletword[trkl]>0){
1049 Int_t n = TrackletsArray()->GetEntriesFast();
1050 AliTRDtrackletWord tmp(trackletword[trkl]);
1051 new((*TrackletsArray())[n]) AliTRDcluster(&tmp,fDet,fVolid);
1057 //_____________________________________________________________________________
1058 Bool_t AliTRDclusterizer::AddLabels()
1061 // Add the track indices to the found clusters
1064 const Int_t kNclus = 3;
1065 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1066 const Int_t kNtrack = kNdict * kNclus;
1068 Int_t iClusterROC = 0;
1075 // Temporary array to collect the track indices
1076 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1078 // Loop through the dictionary arrays one-by-one
1079 // to keep memory consumption low
1080 AliTRDarrayDictionary *tracksIn = 0; //mod
1081 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1083 // tracksIn should be expanded beforehand!
1084 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1086 // Loop though the clusters found in this ROC
1087 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1089 AliTRDcluster *cluster = (AliTRDcluster *)
1090 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1091 row = cluster->GetLabel(0);
1092 col = cluster->GetLabel(1);
1093 time = cluster->GetLabel(2);
1095 for (iPad = 0; iPad < kNclus; iPad++) {
1096 Int_t iPadCol = col - 1 + iPad;
1097 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1098 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1105 // Copy the track indices into the cluster
1106 // Loop though the clusters found in this ROC
1107 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1109 AliTRDcluster *cluster = (AliTRDcluster *)
1110 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1111 cluster->SetLabel(-9999,0);
1112 cluster->SetLabel(-9999,1);
1113 cluster->SetLabel(-9999,2);
1115 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1119 delete [] idxTracks;
1125 //_____________________________________________________________________________
1126 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, const Double_t *const padSignal) const
1129 // Method to unfold neighbouring maxima.
1130 // The charge ratio on the overlapping pad is calculated
1131 // until there is no more change within the range given by eps.
1132 // The resulting ratio is then returned to the calling method.
1135 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1137 AliError("No AliTRDcalibDB instance available\n");
1142 Int_t itStep = 0; // Count iteration steps
1144 Double_t ratio = 0.5; // Start value for ratio
1145 Double_t prevRatio = 0.0; // Store previous ratio
1147 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1148 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1149 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1151 // Start the iteration
1152 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1157 // Cluster position according to charge ratio
1158 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1159 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1160 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1161 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1163 // Set cluster charge ratio
1164 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1165 Double_t ampLeft = padSignal[1] / newSignal[1];
1166 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1167 Double_t ampRight = padSignal[3] / newSignal[1];
1169 // Apply pad response to parameters
1170 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1171 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1173 // Calculate new overlapping ratio
1174 ratio = TMath::Min((Double_t) 1.0
1175 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1183 //_____________________________________________________________________________
1184 void AliTRDclusterizer::TailCancelation()
1187 // Applies the tail cancelation and gain factors:
1188 // Transform fDigits to fDigits
1195 Double_t *inADC = new Double_t[fTimeTotal]; // ADC data before tail cancellation
1196 Double_t *outADC = new Double_t[fTimeTotal]; // ADC data after tail cancellation
1198 fIndexes->ResetCounters();
1199 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
1200 while(fIndexes->NextRCIndex(iRow, iCol))
1202 Float_t fCalGainFactorROCValue = fCalGainFactorROC->GetValue(iCol,iRow);
1203 Double_t gain = fCalGainFactorDetValue
1204 * fCalGainFactorROCValue;
1206 Bool_t corrupted = kFALSE;
1207 for (iTime = 0; iTime < fTimeTotal; iTime++)
1209 // Apply gain gain factor
1210 inADC[iTime] = fDigits->GetData(iRow,iCol,iTime);
1211 if (fCalPadStatusROC->GetStatus(iCol, iRow)) corrupted = kTRUE;
1212 inADC[iTime] /= gain;
1213 outADC[iTime] = inADC[iTime];
1214 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 7 && fReconstructor->IsDebugStreaming()){
1215 (*fDebugStream) << "TailCancellation"
1219 << "inADC=" << inADC[iTime]
1221 << "outADC=" << outADC[iTime]
1222 << "corrupted=" << corrupted
1228 // Apply the tail cancelation via the digital filter
1229 // (only for non-coorupted pads)
1230 DeConvExp(&inADC[0],&outADC[0],fTimeTotal,fReconstructor->GetRecoParam() ->GetTCnexp());
1233 for(iTime = 0; iTime < fTimeTotal; iTime++)//while (fIndexes->NextTbinIndex(iTime))
1235 // Store the amplitude of the digit if above threshold
1236 if (outADC[iTime] > 0)
1237 fDigits->SetData(iRow,iCol,iTime,TMath::Nint(outADC[iTime]));
1239 fDigits->SetData(iRow,iCol,iTime,0);
1242 } // while irow icol
1251 //_____________________________________________________________________________
1252 void AliTRDclusterizer::DeConvExp(const Double_t *const source, Double_t *const target
1253 ,const Int_t n, const Int_t nexp)
1256 // Tail cancellation by deconvolution for PASA v4 TRF
1260 Double_t coefficients[2];
1262 // Initialization (coefficient = alpha, rates = lambda)
1268 if (nexp == 1) { // 1 Exponentials
1274 if (nexp == 2) { // 2 Exponentials
1276 fReconstructor->GetRecoParam()->GetTCParams(par);
1277 r1 = par[0];//1.156;
1278 r2 = par[1];//0.130;
1279 c1 = par[2];//0.114;
1280 c2 = par[3];//0.624;
1283 coefficients[0] = c1;
1284 coefficients[1] = c2;
1288 rates[0] = TMath::Exp(-dt/(r1));
1289 rates[1] = TMath::Exp(-dt/(r2));
1294 Double_t reminder[2];
1295 Double_t correction = 0.0;
1296 Double_t result = 0.0;
1298 // Attention: computation order is important
1299 for (k = 0; k < nexp; k++) {
1303 for (i = 0; i < n; i++) {
1305 result = (source[i] - correction); // No rescaling
1308 for (k = 0; k < nexp; k++) {
1309 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1313 for (k = 0; k < nexp; k++) {
1314 correction += reminder[k];
1321 //_____________________________________________________________________________
1322 void AliTRDclusterizer::ResetRecPoints()
1325 // Resets the list of rec points
1329 fRecPoints->Delete();
1334 //_____________________________________________________________________________
1335 TClonesArray *AliTRDclusterizer::RecPoints()
1338 // Returns the list of rec points
1342 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1343 // determine number of clusters which has to be allocated
1344 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1346 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1348 //SetClustersOwner(kTRUE);
1349 AliTRDReconstructor::SetClusters(0x0);
1355 //_____________________________________________________________________________
1356 TClonesArray *AliTRDclusterizer::TrackletsArray()
1359 // Returns the list of rec points
1362 if (!fTracklets && fReconstructor->IsProcessingTracklets()) {
1363 fTracklets = new TClonesArray("AliTRDcluster", 2*MAXTRACKLETSPERHC);
1364 //SetClustersOwner(kTRUE);
1365 //AliTRDReconstructor::SetTracklets(0x0);