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 ///////////////////////////////////////////////////////////////////////////////
28 #include <TClonesArray.h>
29 #include <TObjArray.h>
31 #include "AliRunLoader.h"
32 #include "AliLoader.h"
33 #include "AliRawReader.h"
35 #include "AliAlignObj.h"
37 #include "AliTRDclusterizer.h"
38 #include "AliTRDcluster.h"
39 #include "AliTRDReconstructor.h"
40 #include "AliTRDgeometry.h"
41 #include "AliTRDarrayDictionary.h"
42 #include "AliTRDarrayADC.h"
43 #include "AliTRDdigitsManager.h"
44 #include "AliTRDrawData.h"
45 #include "AliTRDcalibDB.h"
46 #include "AliTRDrecoParam.h"
47 #include "AliTRDCommonParam.h"
48 #include "AliTRDtransform.h"
49 #include "AliTRDSignalIndex.h"
50 #include "AliTRDrawStreamBase.h"
51 #include "AliTRDfeeParam.h"
53 #include "TTreeStream.h"
55 #include "Cal/AliTRDCalROC.h"
56 #include "Cal/AliTRDCalDet.h"
57 #include "Cal/AliTRDCalSingleChamberStatus.h"
59 ClassImp(AliTRDclusterizer)
61 //_____________________________________________________________________________
62 AliTRDclusterizer::AliTRDclusterizer(const AliTRDReconstructor *const rec)
69 ,fDigitsManager(new AliTRDdigitsManager())
70 ,fTrackletContainer(NULL)
72 ,fTransform(new AliTRDtransform(0))
79 ,fMinLeftRightCutSigma(0)
85 ,fCalGainFactorROC(NULL)
86 ,fCalGainFactorDetValue(0)
89 ,fCalPadStatusROC(NULL)
95 // AliTRDclusterizer default constructor
98 SetBit(kLabels, kTRUE);
100 AliTRDcalibDB *trd = 0x0;
101 if (!(trd = AliTRDcalibDB::Instance())) {
102 AliFatal("Could not get calibration object");
105 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
107 // Initialize debug stream
109 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kClusterizer) > 1){
110 TDirectory *savedir = gDirectory;
111 //fgGetDebugStream = new TTreeSRedirector("TRD.ClusterizerDebug.root");
118 //_____________________________________________________________________________
119 AliTRDclusterizer::AliTRDclusterizer(const Text_t *name, const Text_t *title, const AliTRDReconstructor *const rec)
126 ,fDigitsManager(new AliTRDdigitsManager())
127 ,fTrackletContainer(NULL)
129 ,fTransform(new AliTRDtransform(0))
136 ,fMinLeftRightCutSigma(0)
142 ,fCalGainFactorROC(NULL)
143 ,fCalGainFactorDetValue(0)
145 ,fCalNoiseDetValue(0)
146 ,fCalPadStatusROC(NULL)
152 // AliTRDclusterizer constructor
155 SetBit(kLabels, kTRUE);
157 AliTRDcalibDB *trd = 0x0;
158 if (!(trd = AliTRDcalibDB::Instance())) {
159 AliFatal("Could not get calibration object");
162 fDigitsManager->CreateArrays();
164 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
170 //_____________________________________________________________________________
171 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
173 ,fReconstructor(c.fReconstructor)
178 ,fDigitsManager(NULL)
179 ,fTrackletContainer(NULL)
188 ,fMinLeftRightCutSigma(0)
194 ,fCalGainFactorROC(NULL)
195 ,fCalGainFactorDetValue(0)
197 ,fCalNoiseDetValue(0)
198 ,fCalPadStatusROC(NULL)
204 // AliTRDclusterizer copy constructor
207 SetBit(kLabels, kTRUE);
213 //_____________________________________________________________________________
214 AliTRDclusterizer::~AliTRDclusterizer()
217 // AliTRDclusterizer destructor
220 if (fRecPoints/* && IsClustersOwner()*/){
221 fRecPoints->Delete();
225 if (fDigitsManager) {
226 delete fDigitsManager;
227 fDigitsManager = NULL;
230 if (fTrackletContainer){
231 delete fTrackletContainer;
232 fTrackletContainer = NULL;
247 //_____________________________________________________________________________
248 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
251 // Assignment operator
256 ((AliTRDclusterizer &) c).Copy(*this);
263 //_____________________________________________________________________________
264 void AliTRDclusterizer::Copy(TObject &c) const
270 ((AliTRDclusterizer &) c).fClusterTree = NULL;
271 ((AliTRDclusterizer &) c).fRecPoints = NULL;
272 ((AliTRDclusterizer &) c).fTrackletTree = NULL;
273 ((AliTRDclusterizer &) c).fDigitsManager = NULL;
274 ((AliTRDclusterizer &) c).fTrackletContainer = NULL;
275 ((AliTRDclusterizer &) c).fRawVersion = fRawVersion;
276 ((AliTRDclusterizer &) c).fTransform = NULL;
277 ((AliTRDclusterizer &) c).fDigits = NULL;
278 ((AliTRDclusterizer &) c).fIndexes = NULL;
279 ((AliTRDclusterizer &) c).fADCthresh = 0;
280 ((AliTRDclusterizer &) c).fMaxThresh = 0;
281 ((AliTRDclusterizer &) c).fSigThresh = 0;
282 ((AliTRDclusterizer &) c).fMinMaxCutSigma= 0;
283 ((AliTRDclusterizer &) c).fMinLeftRightCutSigma = 0;
284 ((AliTRDclusterizer &) c).fLayer = 0;
285 ((AliTRDclusterizer &) c).fDet = 0;
286 ((AliTRDclusterizer &) c).fVolid = 0;
287 ((AliTRDclusterizer &) c).fColMax = 0;
288 ((AliTRDclusterizer &) c).fTimeTotal = 0;
289 ((AliTRDclusterizer &) c).fCalGainFactorROC = NULL;
290 ((AliTRDclusterizer &) c).fCalGainFactorDetValue = 0;
291 ((AliTRDclusterizer &) c).fCalNoiseROC = NULL;
292 ((AliTRDclusterizer &) c).fCalNoiseDetValue = 0;
293 ((AliTRDclusterizer &) c).fCalPadStatusROC = NULL;
294 ((AliTRDclusterizer &) c).fClusterROC = 0;
295 ((AliTRDclusterizer &) c).firstClusterROC= 0;
296 ((AliTRDclusterizer &) c).fNoOfClusters = 0;
299 //_____________________________________________________________________________
300 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
303 // Opens the AliROOT file. Output and input are in the same file
306 TString evfoldname = AliConfig::GetDefaultEventFolderName();
307 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
310 fRunLoader = AliRunLoader::Open(name);
314 AliError(Form("Can not open session for file %s.",name));
325 //_____________________________________________________________________________
326 Bool_t AliTRDclusterizer::OpenOutput()
329 // Open the output file
332 if (!fReconstructor->IsWritingClusters()) return kTRUE;
334 TObjArray *ioArray = 0x0;
336 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
337 loader->MakeTree("R");
339 fClusterTree = loader->TreeR();
340 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
346 //_____________________________________________________________________________
347 Bool_t AliTRDclusterizer::OpenOutput(TTree *clusterTree)
350 // Connect the output tree
354 if (fReconstructor->IsWritingClusters()){
355 TObjArray *ioArray = 0x0;
356 fClusterTree = clusterTree;
357 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
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);
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");
397 //_____________________________________________________________________________
398 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
401 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
404 // Import the Trees for the event nEvent in the file
405 fRunLoader->GetEvent(nEvent);
411 //_____________________________________________________________________________
412 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
415 // Fills TRDcluster branch in the tree with the clusters
416 // found in detector = det. For det=-1 writes the tree.
420 (det >= AliTRDgeometry::Ndet())) {
421 AliError(Form("Unexpected detector index %d.\n",det));
425 TObjArray *ioArray = new TObjArray(400);
426 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
428 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
429 } else branch->SetAddress(&ioArray);
431 Int_t nRecPoints = RecPoints()->GetEntriesFast();
433 for (Int_t i = 0; i < nRecPoints; i++) {
434 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
435 if(det != c->GetDetector()) continue;
438 fClusterTree->Fill();
442 for (Int_t i = 0; i < nRecPoints; i++) {
443 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
444 if(c->GetDetector() != detOld){
445 fClusterTree->Fill();
447 detOld = c->GetDetector();
458 //_____________________________________________________________________________
459 Bool_t AliTRDclusterizer::WriteTracklets(Int_t det)
462 // Write the raw data tracklets into seperate file
465 UInt_t **leaves = new UInt_t *[2];
466 for (Int_t i=0; i<2 ;i++){
467 leaves[i] = new UInt_t[258];
468 leaves[i][0] = det; // det
469 leaves[i][1] = i; // side
470 memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
474 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
476 fTrackletTree = dl->Tree();
479 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
481 trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
484 for (Int_t i=0; i<2; i++){
485 if (leaves[i][2]>0) {
486 trkbranch->SetAddress(leaves[i]);
487 fTrackletTree->Fill();
491 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
492 dl->WriteData("OVERWRITE");
500 //_____________________________________________________________________________
501 Bool_t AliTRDclusterizer::ReadDigits()
504 // Reads the digits arrays from the input aliroot file
508 AliError("No run loader available");
512 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
513 if (!loader->TreeD()) {
514 loader->LoadDigits();
517 // Read in the digit arrays
518 return (fDigitsManager->ReadDigits(loader->TreeD()));
522 //_____________________________________________________________________________
523 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
526 // Reads the digits arrays from the input tree
529 // Read in the digit arrays
530 return (fDigitsManager->ReadDigits(digitsTree));
534 //_____________________________________________________________________________
535 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
538 // Reads the digits arrays from the ddl file
542 fDigitsManager = raw.Raw2Digits(rawReader);
548 //_____________________________________________________________________________
549 Bool_t AliTRDclusterizer::MakeClusters()
552 // Creates clusters from digits
555 // Propagate info from the digits manager
556 if (TestBit(kLabels)){
557 SetBit(kLabels, fDigitsManager->UsesDictionaries());
560 Bool_t fReturn = kTRUE;
561 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++){
563 AliTRDarrayADC *digitsIn = (AliTRDarrayADC*) fDigitsManager->GetDigits(i); //mod
564 // This is to take care of switched off super modules
565 if (!digitsIn->HasData()) continue;
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()) {
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 *input = AliTRDrawStreamBase::GetRawStream(rawReader);
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 (fReconstructor->IsWritingTracklets()){
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){
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");
752 if (!fReconstructor){
753 AliError("Reconstructor not set\n");
757 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDReconstructor::kClusterizer);
759 fMaxThresh = fReconstructor->GetRecoParam()->GetClusMaxThresh();
760 fSigThresh = fReconstructor->GetRecoParam()->GetClusSigThresh();
761 fMinMaxCutSigma = fReconstructor->GetRecoParam()->GetMinMaxCutSigma();
762 fMinLeftRightCutSigma = fReconstructor->GetRecoParam()->GetMinLeftRightCutSigma();
764 Int_t istack = fIndexes->GetStack();
765 fLayer = fIndexes->GetLayer();
766 Int_t isector = fIndexes->GetSM();
768 // Start clustering in the chamber
770 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
772 AliError("Strange Detector number Missmatch!");
776 // TRD space point transformation
777 fTransform->SetDetector(det);
779 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
780 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
781 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
783 fColMax = fDigits->GetNcol();
784 //Int_t nRowMax = fDigits->GetNrow();
785 fTimeTotal = fDigits->GetNtime();
787 // Detector wise calibration object for the gain factors
788 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
789 // Calibration object with pad wise values for the gain factors
790 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
791 // Calibration value for chamber wise gain factor
792 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
794 // Detector wise calibration object for the noise
795 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
796 // Calibration object with pad wise values for the noise
797 fCalNoiseROC = calibration->GetNoiseROC(fDet);
798 // Calibration value for chamber wise noise
799 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
801 // Calibration object with the pad status
802 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
804 SetBit(kLUT, fReconstructor->UseLUT());
805 SetBit(kGAUS, fReconstructor->UseGAUS());
806 SetBit(kHLT, fReconstructor->IsHLT());
808 firstClusterROC = -1;
811 // Apply the gain and the tail cancelation via digital filter
812 if(fReconstructor->UseTailCancelation()) TailCancelation();
814 MaxStruct curr, last;
815 Int_t nMaximas = 0, nCorrupted = 0;
817 // Here the clusterfining is happening
819 for(curr.Time = 0; curr.Time < fTimeTotal; curr.Time++){
820 while(fIndexes->NextRCIndex(curr.Row, curr.Col)){
821 //printf("\nCHECK r[%2d] c[%3d] t[%d]\n", curr.Row, curr.Col, curr.Time);
822 if(IsMaximum(curr, curr.padStatus, &curr.Signals[0])){
823 //printf("\tMAX s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
825 if(curr.Time==last.Time && curr.Row==last.Row && curr.Col==last.Col+2) FivePadCluster(last, curr);
828 last=curr; curr.FivePad=kFALSE;
830 //printf("\t--- s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
833 if(last.Row>-1) CreateCluster(last);
835 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kClusterizer) > 2){
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 Bool_t AliTRDclusterizer::AddLabels()
1034 // Add the track indices to the found clusters
1037 const Int_t kNclus = 3;
1038 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1039 const Int_t kNtrack = kNdict * kNclus;
1041 Int_t iClusterROC = 0;
1048 // Temporary array to collect the track indices
1049 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1051 // Loop through the dictionary arrays one-by-one
1052 // to keep memory consumption low
1053 AliTRDarrayDictionary *tracksIn = 0; //mod
1054 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1056 // tracksIn should be expanded beforehand!
1057 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1059 // Loop though the clusters found in this ROC
1060 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1062 AliTRDcluster *cluster = (AliTRDcluster *)
1063 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1064 row = cluster->GetLabel(0);
1065 col = cluster->GetLabel(1);
1066 time = cluster->GetLabel(2);
1068 for (iPad = 0; iPad < kNclus; iPad++) {
1069 Int_t iPadCol = col - 1 + iPad;
1070 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1071 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1078 // Copy the track indices into the cluster
1079 // Loop though the clusters found in this ROC
1080 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1082 AliTRDcluster *cluster = (AliTRDcluster *)
1083 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1084 cluster->SetLabel(-9999,0);
1085 cluster->SetLabel(-9999,1);
1086 cluster->SetLabel(-9999,2);
1088 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1092 delete [] idxTracks;
1098 //_____________________________________________________________________________
1099 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, Double_t *padSignal) const
1102 // Method to unfold neighbouring maxima.
1103 // The charge ratio on the overlapping pad is calculated
1104 // until there is no more change within the range given by eps.
1105 // The resulting ratio is then returned to the calling method.
1108 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1110 AliError("No AliTRDcalibDB instance available\n");
1115 Int_t itStep = 0; // Count iteration steps
1117 Double_t ratio = 0.5; // Start value for ratio
1118 Double_t prevRatio = 0.0; // Store previous ratio
1120 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1121 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1122 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1124 // Start the iteration
1125 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1130 // Cluster position according to charge ratio
1131 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1132 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1133 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1134 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1136 // Set cluster charge ratio
1137 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1138 Double_t ampLeft = padSignal[1] / newSignal[1];
1139 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1140 Double_t ampRight = padSignal[3] / newSignal[1];
1142 // Apply pad response to parameters
1143 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1144 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1146 // Calculate new overlapping ratio
1147 ratio = TMath::Min((Double_t) 1.0
1148 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1156 //_____________________________________________________________________________
1157 void AliTRDclusterizer::TailCancelation()
1160 // Applies the tail cancelation and gain factors:
1161 // Transform fDigits to fDigits
1168 Double_t *inADC = new Double_t[fTimeTotal]; // ADC data before tail cancellation
1169 Double_t *outADC = new Double_t[fTimeTotal]; // ADC data after tail cancellation
1171 fIndexes->ResetCounters();
1172 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDReconstructor::kClusterizer);
1173 while(fIndexes->NextRCIndex(iRow, iCol))
1175 Float_t fCalGainFactorROCValue = fCalGainFactorROC->GetValue(iCol,iRow);
1176 Double_t gain = fCalGainFactorDetValue
1177 * fCalGainFactorROCValue;
1179 Bool_t corrupted = kFALSE;
1180 for (iTime = 0; iTime < fTimeTotal; iTime++)
1182 // Apply gain gain factor
1183 inADC[iTime] = fDigits->GetData(iRow,iCol,iTime);
1184 if (fCalPadStatusROC->GetStatus(iCol, iRow)) corrupted = kTRUE;
1185 inADC[iTime] /= gain;
1186 outADC[iTime] = inADC[iTime];
1187 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kClusterizer) > 7){
1188 (*fDebugStream) << "TailCancellation"
1192 << "inADC=" << inADC[iTime]
1194 << "outADC=" << outADC[iTime]
1195 << "corrupted=" << corrupted
1201 // Apply the tail cancelation via the digital filter
1202 // (only for non-coorupted pads)
1203 DeConvExp(&inADC[0],&outADC[0],fTimeTotal,fReconstructor->GetRecoParam() ->GetTCnexp());
1206 for(iTime = 0; iTime < fTimeTotal; iTime++)//while (fIndexes->NextTbinIndex(iTime))
1208 // Store the amplitude of the digit if above threshold
1209 if (outADC[iTime] > fADCthresh)
1210 fDigits->SetData(iRow,iCol,iTime,TMath::Nint(outADC[iTime]));
1212 fDigits->SetData(iRow,iCol,iTime,0);
1215 } // while irow icol
1224 //_____________________________________________________________________________
1225 void AliTRDclusterizer::DeConvExp(const Double_t *const source, Double_t *const target
1226 ,const Int_t n, const Int_t nexp)
1229 // Tail cancellation by deconvolution for PASA v4 TRF
1233 Double_t coefficients[2];
1235 // Initialization (coefficient = alpha, rates = lambda)
1241 if (nexp == 1) { // 1 Exponentials
1247 if (nexp == 2) { // 2 Exponentials
1249 fReconstructor->GetTCParams(par);
1250 r1 = par[0];//1.156;
1251 r2 = par[1];//0.130;
1252 c1 = par[2];//0.114;
1253 c2 = par[3];//0.624;
1256 coefficients[0] = c1;
1257 coefficients[1] = c2;
1261 rates[0] = TMath::Exp(-dt/(r1));
1262 rates[1] = TMath::Exp(-dt/(r2));
1267 Double_t reminder[2];
1268 Double_t correction = 0.0;
1269 Double_t result = 0.0;
1271 // Attention: computation order is important
1272 for (k = 0; k < nexp; k++) {
1276 for (i = 0; i < n; i++) {
1278 result = (source[i] - correction); // No rescaling
1281 for (k = 0; k < nexp; k++) {
1282 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1286 for (k = 0; k < nexp; k++) {
1287 correction += reminder[k];
1294 //_____________________________________________________________________________
1295 void AliTRDclusterizer::ResetRecPoints()
1298 // Resets the list of rec points
1302 fRecPoints->Delete();
1307 //_____________________________________________________________________________
1308 TClonesArray *AliTRDclusterizer::RecPoints()
1311 // Returns the list of rec points
1315 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1316 // determine number of clusters which has to be allocated
1317 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1319 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1321 //SetClustersOwner(kTRUE);
1322 AliTRDReconstructor::SetClusters(0x0);