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 "AliTRDrawData.h"
39 #include "AliTRDcalibDB.h"
40 #include "AliTRDtransform.h"
41 #include "AliTRDSignalIndex.h"
42 #include "AliTRDrawStreamBase.h"
43 #include "AliTRDfeeParam.h"
44 #include "AliTRDtrackletWord.h"
46 #include "TTreeStream.h"
48 #include "Cal/AliTRDCalROC.h"
49 #include "Cal/AliTRDCalDet.h"
50 #include "Cal/AliTRDCalSingleChamberStatus.h"
52 ClassImp(AliTRDclusterizer)
54 //_____________________________________________________________________________
55 AliTRDclusterizer::AliTRDclusterizer(const AliTRDReconstructor *const rec)
63 ,fDigitsManager(new AliTRDdigitsManager())
64 ,fTrackletContainer(NULL)
66 ,fTransform(new AliTRDtransform(0))
72 ,fMinLeftRightCutSigma(0)
78 ,fCalGainFactorROC(NULL)
79 ,fCalGainFactorDetValue(0)
82 ,fCalPadStatusROC(NULL)
88 // AliTRDclusterizer default constructor
91 SetBit(kLabels, kTRUE);
93 AliTRDcalibDB *trd = 0x0;
94 if (!(trd = AliTRDcalibDB::Instance())) {
95 AliFatal("Could not get calibration object");
98 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
100 // Initialize debug stream
102 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 1){
103 TDirectory *savedir = gDirectory;
104 //fgGetDebugStream = new TTreeSRedirector("TRD.ClusterizerDebug.root");
111 //_____________________________________________________________________________
112 AliTRDclusterizer::AliTRDclusterizer(const Text_t *name, const Text_t *title, const AliTRDReconstructor *const rec)
120 ,fDigitsManager(new AliTRDdigitsManager())
121 ,fTrackletContainer(NULL)
123 ,fTransform(new AliTRDtransform(0))
129 ,fMinLeftRightCutSigma(0)
135 ,fCalGainFactorROC(NULL)
136 ,fCalGainFactorDetValue(0)
138 ,fCalNoiseDetValue(0)
139 ,fCalPadStatusROC(NULL)
145 // AliTRDclusterizer constructor
148 SetBit(kLabels, kTRUE);
150 AliTRDcalibDB *trd = 0x0;
151 if (!(trd = AliTRDcalibDB::Instance())) {
152 AliFatal("Could not get calibration object");
155 fDigitsManager->CreateArrays();
157 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
163 //_____________________________________________________________________________
164 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
166 ,fReconstructor(c.fReconstructor)
172 ,fDigitsManager(NULL)
173 ,fTrackletContainer(NULL)
181 ,fMinLeftRightCutSigma(0)
187 ,fCalGainFactorROC(NULL)
188 ,fCalGainFactorDetValue(0)
190 ,fCalNoiseDetValue(0)
191 ,fCalPadStatusROC(NULL)
197 // AliTRDclusterizer copy constructor
200 SetBit(kLabels, kTRUE);
206 //_____________________________________________________________________________
207 AliTRDclusterizer::~AliTRDclusterizer()
210 // AliTRDclusterizer destructor
213 if (fRecPoints/* && IsClustersOwner()*/){
214 fRecPoints->Delete();
219 fTracklets->Delete();
223 if (fDigitsManager) {
224 delete fDigitsManager;
225 fDigitsManager = NULL;
228 if (fTrackletContainer){
229 delete fTrackletContainer;
230 fTrackletContainer = NULL;
240 //_____________________________________________________________________________
241 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
244 // Assignment operator
249 ((AliTRDclusterizer &) c).Copy(*this);
256 //_____________________________________________________________________________
257 void AliTRDclusterizer::Copy(TObject &c) const
263 ((AliTRDclusterizer &) c).fClusterTree = NULL;
264 ((AliTRDclusterizer &) c).fRecPoints = NULL;
265 ((AliTRDclusterizer &) c).fTrackletTree = NULL;
266 ((AliTRDclusterizer &) c).fDigitsManager = NULL;
267 ((AliTRDclusterizer &) c).fTrackletContainer = NULL;
268 ((AliTRDclusterizer &) c).fRawVersion = fRawVersion;
269 ((AliTRDclusterizer &) c).fTransform = NULL;
270 ((AliTRDclusterizer &) c).fDigits = NULL;
271 ((AliTRDclusterizer &) c).fIndexes = NULL;
272 ((AliTRDclusterizer &) c).fMaxThresh = 0;
273 ((AliTRDclusterizer &) c).fSigThresh = 0;
274 ((AliTRDclusterizer &) c).fMinMaxCutSigma= 0;
275 ((AliTRDclusterizer &) c).fMinLeftRightCutSigma = 0;
276 ((AliTRDclusterizer &) c).fLayer = 0;
277 ((AliTRDclusterizer &) c).fDet = 0;
278 ((AliTRDclusterizer &) c).fVolid = 0;
279 ((AliTRDclusterizer &) c).fColMax = 0;
280 ((AliTRDclusterizer &) c).fTimeTotal = 0;
281 ((AliTRDclusterizer &) c).fCalGainFactorROC = NULL;
282 ((AliTRDclusterizer &) c).fCalGainFactorDetValue = 0;
283 ((AliTRDclusterizer &) c).fCalNoiseROC = NULL;
284 ((AliTRDclusterizer &) c).fCalNoiseDetValue = 0;
285 ((AliTRDclusterizer &) c).fCalPadStatusROC = NULL;
286 ((AliTRDclusterizer &) c).fClusterROC = 0;
287 ((AliTRDclusterizer &) c).firstClusterROC= 0;
288 ((AliTRDclusterizer &) c).fNoOfClusters = 0;
291 //_____________________________________________________________________________
292 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
295 // Opens the AliROOT file. Output and input are in the same file
298 TString evfoldname = AliConfig::GetDefaultEventFolderName();
299 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
302 fRunLoader = AliRunLoader::Open(name);
306 AliError(Form("Can not open session for file %s.",name));
317 //_____________________________________________________________________________
318 Bool_t AliTRDclusterizer::OpenOutput()
321 // Open the output file
324 if (!fReconstructor->IsWritingClusters()) return kTRUE;
326 TObjArray *ioArray = 0x0;
328 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
329 loader->MakeTree("R");
331 fClusterTree = loader->TreeR();
332 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
338 //_____________________________________________________________________________
339 Bool_t AliTRDclusterizer::OpenOutput(TTree *const clusterTree)
342 // Connect the output tree
346 if (fReconstructor->IsWritingClusters()){
347 TObjArray *ioArray = 0x0;
348 fClusterTree = clusterTree;
349 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
354 //_____________________________________________________________________________
355 Bool_t AliTRDclusterizer::OpenTrackletOutput()
361 if (fReconstructor->IsWritingTracklets()){
362 TString evfoldname = AliConfig::GetDefaultEventFolderName();
363 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
366 fRunLoader = AliRunLoader::Open("galice.root");
369 AliError(Form("Can not open session for file galice.root."));
373 UInt_t **leaves = new UInt_t *[2];
374 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
376 AliError("Could not get the tracklets data loader!");
377 dl = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
378 fRunLoader->GetLoader("TRDLoader")->AddDataLoader(dl);
380 fTrackletTree = dl->Tree();
384 fTrackletTree = dl->Tree();
386 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
388 fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
394 //_____________________________________________________________________________
395 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
398 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
401 // Import the Trees for the event nEvent in the file
402 fRunLoader->GetEvent(nEvent);
408 //_____________________________________________________________________________
409 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
412 // Fills TRDcluster branch in the tree with the clusters
413 // found in detector = det. For det=-1 writes the tree.
417 (det >= AliTRDgeometry::Ndet())) {
418 AliError(Form("Unexpected detector index %d.\n",det));
422 TObjArray *ioArray = new TObjArray(400);
423 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
425 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
426 } else branch->SetAddress(&ioArray);
428 Int_t nRecPoints = RecPoints()->GetEntriesFast();
430 for (Int_t i = 0; i < nRecPoints; i++) {
431 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
432 if(det != c->GetDetector()) continue;
435 fClusterTree->Fill();
439 for (Int_t i = 0; i < nRecPoints; i++) {
440 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
441 if(c->GetDetector() != detOld){
442 fClusterTree->Fill();
444 detOld = c->GetDetector();
455 //_____________________________________________________________________________
456 Bool_t AliTRDclusterizer::WriteTracklets(Int_t det)
459 // Write the raw data tracklets into seperate file
462 UInt_t **leaves = new UInt_t *[2];
463 for (Int_t i=0; i<2 ;i++){
464 leaves[i] = new UInt_t[258];
465 leaves[i][0] = det; // det
466 leaves[i][1] = i; // side
467 memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
471 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
473 fTrackletTree = dl->Tree();
476 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
478 trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
481 for (Int_t i=0; i<2; i++){
482 if (leaves[i][2]>0) {
483 trkbranch->SetAddress(leaves[i]);
484 fTrackletTree->Fill();
488 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
489 dl->WriteData("OVERWRITE");
497 //_____________________________________________________________________________
498 Bool_t AliTRDclusterizer::ReadDigits()
501 // Reads the digits arrays from the input aliroot file
505 AliError("No run loader available");
509 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
510 if (!loader->TreeD()) {
511 loader->LoadDigits();
514 // Read in the digit arrays
515 return (fDigitsManager->ReadDigits(loader->TreeD()));
519 //_____________________________________________________________________________
520 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
523 // Reads the digits arrays from the input tree
526 // Read in the digit arrays
527 return (fDigitsManager->ReadDigits(digitsTree));
531 //_____________________________________________________________________________
532 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
535 // Reads the digits arrays from the ddl file
539 fDigitsManager = raw.Raw2Digits(rawReader);
545 //_____________________________________________________________________________
546 Bool_t AliTRDclusterizer::MakeClusters()
549 // Creates clusters from digits
552 // Propagate info from the digits manager
553 if (TestBit(kLabels)){
554 SetBit(kLabels, fDigitsManager->UsesDictionaries());
557 Bool_t fReturn = kTRUE;
558 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++){
560 AliTRDarrayADC *digitsIn = (AliTRDarrayADC*) fDigitsManager->GetDigits(i); //mod
561 // This is to take care of switched off super modules
562 if (!digitsIn->HasData()) continue;
564 digitsIn->DeleteNegatives(); // Restore digits array to >=0 values
565 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
566 if (indexes->IsAllocated() == kFALSE){
567 fDigitsManager->BuildIndexes(i);
571 if (indexes->HasEntry()){
572 if (TestBit(kLabels)){
573 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++){
574 AliTRDarrayDictionary *tracksIn = 0; //mod
575 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(i,iDict); //mod
579 fR = MakeClusters(i);
580 fReturn = fR && fReturn;
584 // if(IsWritingClusters()) WriteClusters(i);
588 // No compress just remove
589 fDigitsManager->RemoveDigits(i);
590 fDigitsManager->RemoveDictionaries(i);
591 fDigitsManager->ClearIndexes(i);
594 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
596 AliInfo(Form("Number of found clusters : %d", RecPoints()->GetEntriesFast()));
602 //_____________________________________________________________________________
603 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
606 // Creates clusters from raw data
609 return Raw2ClustersChamber(rawReader);
613 //_____________________________________________________________________________
614 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
617 // Creates clusters from raw data
620 // Create the digits manager
621 if (!fDigitsManager){
622 fDigitsManager = new AliTRDdigitsManager(kTRUE);
623 fDigitsManager->CreateArrays();
626 fDigitsManager->SetUseDictionaries(TestBit(kLabels));
628 // tracklet container for raw tracklet writing
629 if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
630 // maximum tracklets for one HC
631 const Int_t kTrackletChmb=256;
632 fTrackletContainer = new UInt_t *[2];
633 fTrackletContainer[0] = new UInt_t[kTrackletChmb];
634 fTrackletContainer[1] = new UInt_t[kTrackletChmb];
637 AliTRDrawStreamBase::SetSubtractBaseline(10);
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 fIndexes = fDigitsManager->GetIndexes(det);
739 if (fIndexes->IsAllocated() == kFALSE) {
740 AliError("Indexes do not exist!");
744 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
746 AliFatal("No AliTRDcalibDB instance available\n");
750 if (!fReconstructor){
751 AliError("Reconstructor not set\n");
755 fMaxThresh = fReconstructor->GetRecoParam()->GetClusMaxThresh();
756 fSigThresh = fReconstructor->GetRecoParam()->GetClusSigThresh();
757 fMinMaxCutSigma = fReconstructor->GetRecoParam()->GetMinMaxCutSigma();
758 fMinLeftRightCutSigma = fReconstructor->GetRecoParam()->GetMinLeftRightCutSigma();
760 Int_t istack = fIndexes->GetStack();
761 fLayer = fIndexes->GetLayer();
762 Int_t isector = fIndexes->GetSM();
764 // Start clustering in the chamber
766 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
768 AliError("Strange Detector number Missmatch!");
772 // TRD space point transformation
773 fTransform->SetDetector(det);
775 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
776 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
777 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
779 if(fReconstructor->IsProcessingTracklets() && fTrackletContainer)
780 AddTrackletsToArray();
782 fColMax = fDigits->GetNcol();
783 //Int_t nRowMax = fDigits->GetNrow();
784 fTimeTotal = fDigits->GetNtime();
786 // Detector wise calibration object for the gain factors
787 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
788 // Calibration object with pad wise values for the gain factors
789 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
790 // Calibration value for chamber wise gain factor
791 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
793 // Detector wise calibration object for the noise
794 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
795 // Calibration object with pad wise values for the noise
796 fCalNoiseROC = calibration->GetNoiseROC(fDet);
797 // Calibration value for chamber wise noise
798 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
800 // Calibration object with the pad status
801 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
803 SetBit(kLUT, fReconstructor->GetRecoParam()->UseLUT());
804 SetBit(kGAUS, fReconstructor->GetRecoParam()->UseGAUS());
805 SetBit(kHLT, fReconstructor->IsHLT());
807 firstClusterROC = -1;
810 // Apply the gain and the tail cancelation via digital filter
811 if(fReconstructor->GetRecoParam()->UseTailCancelation()) TailCancelation();
813 MaxStruct curr, last;
814 Int_t nMaximas = 0, nCorrupted = 0;
816 // Here the clusterfining is happening
818 for(curr.Time = 0; curr.Time < fTimeTotal; curr.Time++){
819 while(fIndexes->NextRCIndex(curr.Row, curr.Col)){
820 //printf("\nCHECK r[%2d] c[%3d] t[%d]\n", curr.Row, curr.Col, curr.Time);
821 if(IsMaximum(curr, curr.padStatus, &curr.Signals[0])){
822 //printf("\tMAX s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
824 if(curr.Time==last.Time && curr.Row==last.Row && curr.Col==last.Col+2) FivePadCluster(last, curr);
827 last=curr; curr.FivePad=kFALSE;
829 //printf("\t--- s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
832 if(last.Row>-1) CreateCluster(last);
834 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 2 && fReconstructor->IsDebugStreaming()){
835 TTreeSRedirector* fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
836 (*fDebugStream) << "MakeClusters"
837 << "Detector=" << det
838 << "NMaxima=" << nMaximas
839 << "NClusters=" << fClusterROC
840 << "NCorrupted=" << nCorrupted
843 if (TestBit(kLabels)) AddLabels();
849 //_____________________________________________________________________________
850 Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Short_t *const Signals)
853 // Returns true if this row,col,time combination is a maximum.
854 // Gives back the padStatus and the signals of the center pad and the two neighbouring pads.
857 Signals[1] = fDigits->GetData(Max.Row, Max.Col, Max.Time);
858 if(Signals[1] < fMaxThresh) return kFALSE;
860 Float_t noiseMiddleThresh = fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.Col, Max.Row);
861 if (Signals[1] < noiseMiddleThresh) return kFALSE;
863 if (Max.Col + 1 >= fColMax || Max.Col < 1) return kFALSE;
866 fCalPadStatusROC->GetStatus(Max.Col-1, Max.Row)
867 ,fCalPadStatusROC->GetStatus(Max.Col, Max.Row)
868 ,fCalPadStatusROC->GetStatus(Max.Col+1, Max.Row)
871 Signals[0] = fDigits->GetData(Max.Row, Max.Col-1, Max.Time);
872 Signals[2] = fDigits->GetData(Max.Row, Max.Col+1, Max.Time);
874 if(!(status[0] | status[1] | status[2])) {//all pads are good
875 if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) {
876 if ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh)) {
877 Float_t noiseSumThresh = fMinLeftRightCutSigma
879 * fCalNoiseROC->GetValue(Max.Col, Max.Row);
880 if ((Signals[2]+Signals[0]+Signals[1]) < noiseSumThresh) return kFALSE;
885 } else { // at least one of the pads is bad, and reject candidates with more than 1 problematic pad
886 if (status[2] && (!(status[0] || status[1])) && Signals[1] > Signals[0] && Signals[0] >= fSigThresh) {
888 SetPadStatus(status[2], padStatus);
891 else if (status[0] && (!(status[1] || status[2])) && Signals[1] >= Signals[2] && Signals[2] >= fSigThresh) {
893 SetPadStatus(status[0], padStatus);
896 else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh))) {
897 Signals[1]=TMath::Nint(fMaxThresh);
898 SetPadStatus(status[1], padStatus);
905 //_____________________________________________________________________________
906 Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
909 // Look for 5 pad cluster with minimum in the middle
910 // Gives back the ratio
912 if (ThisMax.Col >= fColMax - 3) return kFALSE;
913 if (ThisMax.Col < fColMax - 5){
914 if (fDigits->GetData(ThisMax.Row, ThisMax.Col+4, ThisMax.Time) >= fSigThresh)
917 if (ThisMax.Col > 1) {
918 if (fDigits->GetData(ThisMax.Row, ThisMax.Col-2, ThisMax.Time) >= fSigThresh)
922 const Float_t kEpsilon = 0.01;
923 Double_t padSignal[5] = {ThisMax.Signals[0], ThisMax.Signals[1], ThisMax.Signals[2],
924 NeighbourMax.Signals[1], NeighbourMax.Signals[2]};
926 // Unfold the two maxima and set the signal on
927 // the overlapping pad to the ratio
928 Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
929 ThisMax.Signals[2] = TMath::Nint(ThisMax.Signals[2]*ratio);
930 NeighbourMax.Signals[0] = TMath::Nint(NeighbourMax.Signals[0]*(1-ratio));
931 ThisMax.FivePad=kTRUE;
932 NeighbourMax.FivePad=kTRUE;
937 //_____________________________________________________________________________
938 void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
941 // Creates a cluster at the given position and saves it in fRecPoints
945 Short_t signals[7] = { 0, 0, Max.Signals[0], Max.Signals[1], Max.Signals[2], 0, 0 };
946 if(!TestBit(kHLT)) CalcAdditionalInfo(Max, signals, nPadCount);
948 AliTRDcluster cluster(fDet, ((UChar_t) Max.Col), ((UChar_t) Max.Row), ((UChar_t) Max.Time), signals, fVolid);
949 cluster.SetNPads(nPadCount);
950 if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
951 else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
952 else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
954 cluster.SetFivePad(Max.FivePad);
955 // set pads status for the cluster
956 UChar_t maskPosition = GetCorruption(Max.padStatus);
958 cluster.SetPadMaskedPosition(maskPosition);
959 cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
962 // Transform the local cluster coordinates into calibrated
963 // space point positions defined in the local tracking system.
964 // Here the calibration for T0, Vdrift and ExB is applied as well.
965 if(!fTransform->Transform(&cluster)) return;
966 // Temporarily store the Max.Row, column and time bin of the center pad
967 // Used to later on assign the track indices
968 cluster.SetLabel(Max.Row, 0);
969 cluster.SetLabel(Max.Col, 1);
970 cluster.SetLabel(Max.Time,2);
972 //needed for HLT reconstruction
973 AddClusterToArray(&cluster);
975 // Store the index of the first cluster in the current ROC
976 if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
982 //_____________________________________________________________________________
983 void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
987 while (fDigits->GetData(Max.Row, Max.Col-ii, Max.Time) >= fSigThresh) {
990 if (Max.Col < ii) break;
994 while (fDigits->GetData(Max.Row, Max.Col+ii, Max.Time) >= fSigThresh) {
997 if (Max.Col+ii >= fColMax) break;
1000 // Store the amplitudes of the pads in the cluster for later analysis
1001 // and check whether one of these pads is masked in the database
1002 signals[2]=Max.Signals[0];
1003 signals[3]=Max.Signals[1];
1004 signals[4]=Max.Signals[2];
1005 for(Int_t i = 0; i<2; i++)
1008 signals[i] = fDigits->GetData(Max.Row, Max.Col-3+i, Max.Time);
1009 if(Max.Col+3-i < fColMax)
1010 signals[6-i] = fDigits->GetData(Max.Row, Max.Col+3-i, Max.Time);
1012 /*for (Int_t jPad = Max.Col-3; jPad <= Max.Col+3; jPad++) {
1013 if ((jPad >= 0) && (jPad < fColMax))
1014 signals[jPad-Max.Col+3] = TMath::Nint(fDigits->GetData(Max.Row,jPad,Max.Time));
1018 //_____________________________________________________________________________
1019 void AliTRDclusterizer::AddClusterToArray(AliTRDcluster* cluster)
1022 // Add a cluster to the array
1025 Int_t n = RecPoints()->GetEntriesFast();
1026 if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
1027 new((*RecPoints())[n]) AliTRDcluster(*cluster);
1030 //_____________________________________________________________________________
1031 void AliTRDclusterizer::AddTrackletsToArray()
1034 // Add the online tracklets of this chamber to the array
1037 UInt_t* trackletword;
1038 for(Int_t side=0; side<2; side++)
1041 trackletword=fTrackletContainer[side];
1042 while(trackletword[trkl]>0){
1043 Int_t n = TrackletsArray()->GetEntriesFast();
1044 AliTRDtrackletWord tmp(trackletword[trkl]);
1045 new((*TrackletsArray())[n]) AliTRDcluster(&tmp,fDet,fVolid);
1051 //_____________________________________________________________________________
1052 Bool_t AliTRDclusterizer::AddLabels()
1055 // Add the track indices to the found clusters
1058 const Int_t kNclus = 3;
1059 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1060 const Int_t kNtrack = kNdict * kNclus;
1062 Int_t iClusterROC = 0;
1069 // Temporary array to collect the track indices
1070 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1072 // Loop through the dictionary arrays one-by-one
1073 // to keep memory consumption low
1074 AliTRDarrayDictionary *tracksIn = 0; //mod
1075 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1077 // tracksIn should be expanded beforehand!
1078 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1080 // Loop though the clusters found in this ROC
1081 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1083 AliTRDcluster *cluster = (AliTRDcluster *)
1084 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1085 row = cluster->GetLabel(0);
1086 col = cluster->GetLabel(1);
1087 time = cluster->GetLabel(2);
1089 for (iPad = 0; iPad < kNclus; iPad++) {
1090 Int_t iPadCol = col - 1 + iPad;
1091 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1092 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1099 // Copy the track indices into the cluster
1100 // Loop though the clusters found in this ROC
1101 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1103 AliTRDcluster *cluster = (AliTRDcluster *)
1104 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1105 cluster->SetLabel(-9999,0);
1106 cluster->SetLabel(-9999,1);
1107 cluster->SetLabel(-9999,2);
1109 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1113 delete [] idxTracks;
1119 //_____________________________________________________________________________
1120 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, const Double_t *const padSignal) const
1123 // Method to unfold neighbouring maxima.
1124 // The charge ratio on the overlapping pad is calculated
1125 // until there is no more change within the range given by eps.
1126 // The resulting ratio is then returned to the calling method.
1129 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1131 AliError("No AliTRDcalibDB instance available\n");
1136 Int_t itStep = 0; // Count iteration steps
1138 Double_t ratio = 0.5; // Start value for ratio
1139 Double_t prevRatio = 0.0; // Store previous ratio
1141 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1142 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1143 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1145 // Start the iteration
1146 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1151 // Cluster position according to charge ratio
1152 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1153 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1154 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1155 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1157 // Set cluster charge ratio
1158 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1159 Double_t ampLeft = padSignal[1] / newSignal[1];
1160 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1161 Double_t ampRight = padSignal[3] / newSignal[1];
1163 // Apply pad response to parameters
1164 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1165 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1167 // Calculate new overlapping ratio
1168 ratio = TMath::Min((Double_t) 1.0
1169 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1177 //_____________________________________________________________________________
1178 void AliTRDclusterizer::TailCancelation()
1181 // Applies the tail cancelation and gain factors:
1182 // Transform fDigits to fDigits
1189 Double_t *inADC = new Double_t[fTimeTotal]; // ADC data before tail cancellation
1190 Double_t *outADC = new Double_t[fTimeTotal]; // ADC data after tail cancellation
1192 fIndexes->ResetCounters();
1193 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
1194 while(fIndexes->NextRCIndex(iRow, iCol))
1196 Float_t fCalGainFactorROCValue = fCalGainFactorROC->GetValue(iCol,iRow);
1197 Double_t gain = fCalGainFactorDetValue
1198 * fCalGainFactorROCValue;
1200 Bool_t corrupted = kFALSE;
1201 for (iTime = 0; iTime < fTimeTotal; iTime++)
1203 // Apply gain gain factor
1204 inADC[iTime] = fDigits->GetData(iRow,iCol,iTime);
1205 if (fCalPadStatusROC->GetStatus(iCol, iRow)) corrupted = kTRUE;
1206 inADC[iTime] /= gain;
1207 outADC[iTime] = inADC[iTime];
1208 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 7 && fReconstructor->IsDebugStreaming()){
1209 (*fDebugStream) << "TailCancellation"
1213 << "inADC=" << inADC[iTime]
1215 << "outADC=" << outADC[iTime]
1216 << "corrupted=" << corrupted
1222 // Apply the tail cancelation via the digital filter
1223 // (only for non-coorupted pads)
1224 DeConvExp(&inADC[0],&outADC[0],fTimeTotal,fReconstructor->GetRecoParam() ->GetTCnexp());
1227 for(iTime = 0; iTime < fTimeTotal; iTime++)//while (fIndexes->NextTbinIndex(iTime))
1229 // Store the amplitude of the digit if above threshold
1230 if (outADC[iTime] > 0)
1231 fDigits->SetData(iRow,iCol,iTime,TMath::Nint(outADC[iTime]));
1233 fDigits->SetData(iRow,iCol,iTime,0);
1236 } // while irow icol
1245 //_____________________________________________________________________________
1246 void AliTRDclusterizer::DeConvExp(const Double_t *const source, Double_t *const target
1247 ,const Int_t n, const Int_t nexp)
1250 // Tail cancellation by deconvolution for PASA v4 TRF
1254 Double_t coefficients[2];
1256 // Initialization (coefficient = alpha, rates = lambda)
1262 if (nexp == 1) { // 1 Exponentials
1268 if (nexp == 2) { // 2 Exponentials
1270 fReconstructor->GetRecoParam()->GetTCParams(par);
1271 r1 = par[0];//1.156;
1272 r2 = par[1];//0.130;
1273 c1 = par[2];//0.114;
1274 c2 = par[3];//0.624;
1277 coefficients[0] = c1;
1278 coefficients[1] = c2;
1282 rates[0] = TMath::Exp(-dt/(r1));
1283 rates[1] = TMath::Exp(-dt/(r2));
1288 Double_t reminder[2];
1289 Double_t correction = 0.0;
1290 Double_t result = 0.0;
1292 // Attention: computation order is important
1293 for (k = 0; k < nexp; k++) {
1297 for (i = 0; i < n; i++) {
1299 result = (source[i] - correction); // No rescaling
1302 for (k = 0; k < nexp; k++) {
1303 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1307 for (k = 0; k < nexp; k++) {
1308 correction += reminder[k];
1315 //_____________________________________________________________________________
1316 void AliTRDclusterizer::ResetRecPoints()
1319 // Resets the list of rec points
1323 fRecPoints->Delete();
1328 //_____________________________________________________________________________
1329 TClonesArray *AliTRDclusterizer::RecPoints()
1332 // Returns the list of rec points
1336 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1337 // determine number of clusters which has to be allocated
1338 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1340 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1342 //SetClustersOwner(kTRUE);
1343 AliTRDReconstructor::SetClusters(0x0);
1349 //_____________________________________________________________________________
1350 TClonesArray *AliTRDclusterizer::TrackletsArray()
1353 // Returns the list of rec points
1356 if (!fTracklets && fReconstructor->IsProcessingTracklets()) {
1357 fTracklets = new TClonesArray("AliTRDcluster", 2*MAXTRACKLETSPERHC);
1358 //SetClustersOwner(kTRUE);
1359 //AliTRDReconstructor::SetTracklets(0x0);