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)
91 // AliTRDclusterizer default constructor
94 SetBit(kLabels, kTRUE);
95 SetBit(knewDM, kFALSE);
97 AliTRDcalibDB *trd = 0x0;
98 if (!(trd = AliTRDcalibDB::Instance())) {
99 AliFatal("Could not get calibration object");
102 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
104 // Initialize debug stream
106 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 1){
107 TDirectory *savedir = gDirectory;
108 //fgGetDebugStream = new TTreeSRedirector("TRD.ClusterizerDebug.root");
115 //_____________________________________________________________________________
116 AliTRDclusterizer::AliTRDclusterizer(const Text_t *name, const Text_t *title, const AliTRDReconstructor *const rec)
124 ,fDigitsManager(new AliTRDdigitsManager())
125 ,fTrackletContainer(NULL)
127 ,fTransform(new AliTRDtransform(0))
133 ,fMinLeftRightCutSigma(0)
139 ,fCalGainFactorROC(NULL)
140 ,fCalGainFactorDetValue(0)
142 ,fCalNoiseDetValue(0)
143 ,fCalPadStatusROC(NULL)
151 // AliTRDclusterizer constructor
154 SetBit(kLabels, kTRUE);
155 SetBit(knewDM, kFALSE);
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)
179 ,fDigitsManager(NULL)
180 ,fTrackletContainer(NULL)
188 ,fMinLeftRightCutSigma(0)
194 ,fCalGainFactorROC(NULL)
195 ,fCalGainFactorDetValue(0)
197 ,fCalNoiseDetValue(0)
198 ,fCalPadStatusROC(NULL)
206 // AliTRDclusterizer copy constructor
209 SetBit(kLabels, kTRUE);
210 SetBit(knewDM, kFALSE);
216 //_____________________________________________________________________________
217 AliTRDclusterizer::~AliTRDclusterizer()
220 // AliTRDclusterizer destructor
223 if (fRecPoints/* && IsClustersOwner()*/){
224 fRecPoints->Delete();
229 fTracklets->Delete();
233 if (fDigitsManager) {
234 delete fDigitsManager;
235 fDigitsManager = NULL;
238 if (fTrackletContainer){
239 delete [] fTrackletContainer[0];
240 delete [] fTrackletContainer[1];
241 delete [] fTrackletContainer;
242 fTrackletContainer = NULL;
257 //_____________________________________________________________________________
258 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
261 // Assignment operator
266 ((AliTRDclusterizer &) c).Copy(*this);
273 //_____________________________________________________________________________
274 void AliTRDclusterizer::Copy(TObject &c) const
280 ((AliTRDclusterizer &) c).fClusterTree = NULL;
281 ((AliTRDclusterizer &) c).fRecPoints = NULL;
282 ((AliTRDclusterizer &) c).fTrackletTree = NULL;
283 ((AliTRDclusterizer &) c).fDigitsManager = NULL;
284 ((AliTRDclusterizer &) c).fTrackletContainer = NULL;
285 ((AliTRDclusterizer &) c).fRawVersion = fRawVersion;
286 ((AliTRDclusterizer &) c).fTransform = NULL;
287 ((AliTRDclusterizer &) c).fDigits = NULL;
288 ((AliTRDclusterizer &) c).fIndexes = NULL;
289 ((AliTRDclusterizer &) c).fMaxThresh = 0;
290 ((AliTRDclusterizer &) c).fSigThresh = 0;
291 ((AliTRDclusterizer &) c).fMinMaxCutSigma= 0;
292 ((AliTRDclusterizer &) c).fMinLeftRightCutSigma = 0;
293 ((AliTRDclusterizer &) c).fLayer = 0;
294 ((AliTRDclusterizer &) c).fDet = 0;
295 ((AliTRDclusterizer &) c).fVolid = 0;
296 ((AliTRDclusterizer &) c).fColMax = 0;
297 ((AliTRDclusterizer &) c).fTimeTotal = 0;
298 ((AliTRDclusterizer &) c).fCalGainFactorROC = NULL;
299 ((AliTRDclusterizer &) c).fCalGainFactorDetValue = 0;
300 ((AliTRDclusterizer &) c).fCalNoiseROC = NULL;
301 ((AliTRDclusterizer &) c).fCalNoiseDetValue = 0;
302 ((AliTRDclusterizer &) c).fCalPadStatusROC = NULL;
303 ((AliTRDclusterizer &) c).fClusterROC = 0;
304 ((AliTRDclusterizer &) c).firstClusterROC= 0;
305 ((AliTRDclusterizer &) c).fNoOfClusters = 0;
306 ((AliTRDclusterizer &) c).fBaseline = 0;
307 ((AliTRDclusterizer &) c).fRawStream = NULL;
311 //_____________________________________________________________________________
312 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
315 // Opens the AliROOT file. Output and input are in the same file
318 TString evfoldname = AliConfig::GetDefaultEventFolderName();
319 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
322 fRunLoader = AliRunLoader::Open(name);
326 AliError(Form("Can not open session for file %s.",name));
337 //_____________________________________________________________________________
338 Bool_t AliTRDclusterizer::OpenOutput()
341 // Open the output file
344 if (!fReconstructor->IsWritingClusters()) return kTRUE;
346 TObjArray *ioArray = 0x0;
348 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
349 loader->MakeTree("R");
351 fClusterTree = loader->TreeR();
352 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
358 //_____________________________________________________________________________
359 Bool_t AliTRDclusterizer::OpenOutput(TTree *const clusterTree)
362 // Connect the output tree
366 if (fReconstructor->IsWritingClusters()){
367 TObjArray *ioArray = 0x0;
368 fClusterTree = clusterTree;
369 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
374 //_____________________________________________________________________________
375 Bool_t AliTRDclusterizer::OpenTrackletOutput()
381 if (fReconstructor->IsWritingTracklets()){
382 TString evfoldname = AliConfig::GetDefaultEventFolderName();
383 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
386 fRunLoader = AliRunLoader::Open("galice.root");
389 AliError(Form("Can not open session for file galice.root."));
393 UInt_t **leaves = new UInt_t *[2];
394 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
396 AliError("Could not get the tracklets data loader!");
397 dl = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
398 fRunLoader->GetLoader("TRDLoader")->AddDataLoader(dl);
400 fTrackletTree = dl->Tree();
404 fTrackletTree = dl->Tree();
406 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
408 fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
414 //_____________________________________________________________________________
415 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
418 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
421 // Import the Trees for the event nEvent in the file
422 fRunLoader->GetEvent(nEvent);
428 //_____________________________________________________________________________
429 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
432 // Fills TRDcluster branch in the tree with the clusters
433 // found in detector = det. For det=-1 writes the tree.
437 (det >= AliTRDgeometry::Ndet())) {
438 AliError(Form("Unexpected detector index %d.\n",det));
442 TObjArray *ioArray = new TObjArray(400);
443 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
445 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
446 } else branch->SetAddress(&ioArray);
448 Int_t nRecPoints = RecPoints()->GetEntriesFast();
450 for (Int_t i = 0; i < nRecPoints; i++) {
451 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
452 if(det != c->GetDetector()) continue;
455 fClusterTree->Fill();
459 for (Int_t i = 0; i < nRecPoints; i++) {
460 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
461 if(c->GetDetector() != detOld){
462 fClusterTree->Fill();
464 detOld = c->GetDetector();
475 //_____________________________________________________________________________
476 Bool_t AliTRDclusterizer::WriteTracklets(Int_t det)
479 // Write the raw data tracklets into seperate file
482 UInt_t **leaves = new UInt_t *[2];
483 for (Int_t i=0; i<2 ;i++){
484 leaves[i] = new UInt_t[258];
485 leaves[i][0] = det; // det
486 leaves[i][1] = i; // side
487 memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
491 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
493 fTrackletTree = dl->Tree();
496 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
498 trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
501 for (Int_t i=0; i<2; i++){
502 if (leaves[i][2]>0) {
503 trkbranch->SetAddress(leaves[i]);
504 fTrackletTree->Fill();
508 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
509 dl->WriteData("OVERWRITE");
517 //_____________________________________________________________________________
518 Bool_t AliTRDclusterizer::ReadDigits()
521 // Reads the digits arrays from the input aliroot file
525 AliError("No run loader available");
529 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
530 if (!loader->TreeD()) {
531 loader->LoadDigits();
534 // Read in the digit arrays
535 return (fDigitsManager->ReadDigits(loader->TreeD()));
539 //_____________________________________________________________________________
540 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
543 // Reads the digits arrays from the input tree
546 // Read in the digit arrays
547 return (fDigitsManager->ReadDigits(digitsTree));
551 //_____________________________________________________________________________
552 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
555 // Reads the digits arrays from the ddl file
559 fDigitsManager = raw.Raw2Digits(rawReader);
565 //_____________________________________________________________________________
566 Bool_t AliTRDclusterizer::MakeClusters()
569 // Creates clusters from digits
572 // Propagate info from the digits manager
573 if (TestBit(kLabels)){
574 SetBit(kLabels, fDigitsManager->UsesDictionaries());
577 Bool_t fReturn = kTRUE;
578 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++){
580 AliTRDarrayADC *digitsIn = (AliTRDarrayADC*) fDigitsManager->GetDigits(i); //mod
581 // This is to take care of switched off super modules
582 if (!digitsIn->HasData()) continue;
584 digitsIn->DeleteNegatives(); // Restore digits array to >=0 values
585 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
586 if (indexes->IsAllocated() == kFALSE){
587 fDigitsManager->BuildIndexes(i);
591 if (indexes->HasEntry()){
592 if (TestBit(kLabels)){
593 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++){
594 AliTRDarrayDictionary *tracksIn = 0; //mod
595 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(i,iDict); //mod
599 fR = MakeClusters(i);
600 fReturn = fR && fReturn;
604 // if(IsWritingClusters()) WriteClusters(i);
608 // No compress just remove
609 fDigitsManager->RemoveDigits(i);
610 fDigitsManager->RemoveDictionaries(i);
611 fDigitsManager->ClearIndexes(i);
614 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
616 AliInfo(Form("Number of found clusters : %d", RecPoints()->GetEntriesFast()));
622 //_____________________________________________________________________________
623 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
626 // Creates clusters from raw data
629 return Raw2ClustersChamber(rawReader);
633 //_____________________________________________________________________________
634 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
637 // Creates clusters from raw data
640 // Create the digits manager
641 if (!fDigitsManager){
642 SetBit(knewDM, kTRUE);
643 fDigitsManager = new AliTRDdigitsManager(kTRUE);
644 fDigitsManager->CreateArrays();
647 fDigitsManager->SetUseDictionaries(TestBit(kLabels));
649 // tracklet container for raw tracklet writing
650 if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
651 // maximum tracklets for one HC
652 const Int_t kTrackletChmb=256;
653 fTrackletContainer = new UInt_t *[2];
654 fTrackletContainer[0] = new UInt_t[kTrackletChmb];
655 fTrackletContainer[1] = new UInt_t[kTrackletChmb];
659 fRawStream = AliTRDrawStreamBase::GetRawStream(rawReader);
661 fRawStream->SetReader(rawReader);
663 if(fReconstructor->IsHLT())
664 fRawStream->SetSharedPadReadout(kFALSE);
666 AliInfo(Form("Stream version: %s", fRawStream->IsA()->GetName()));
669 while ((det = fRawStream->NextChamber(fDigitsManager,fTrackletContainer)) >= 0){
670 Bool_t iclusterBranch = kFALSE;
671 if (fDigitsManager->GetIndexes(det)->HasEntry()){
672 iclusterBranch = MakeClusters(det);
675 fDigitsManager->ClearArrays(det);
677 if (!fReconstructor->IsWritingTracklets()) continue;
678 if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
681 if (fTrackletContainer){
682 delete [] fTrackletContainer[0];
683 delete [] fTrackletContainer[1];
684 delete [] fTrackletContainer;
685 fTrackletContainer = NULL;
688 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
690 if(!TestBit(knewDM)){
691 delete fDigitsManager;
692 fDigitsManager = NULL;
695 AliInfo(Form("Number of found clusters : %d", fNoOfClusters));
700 //_____________________________________________________________________________
701 UChar_t AliTRDclusterizer::GetStatus(Short_t &signal)
704 // Check if a pad is masked
709 if(signal>0 && TESTBIT(signal, 10)){
711 for(int ibit=0; ibit<4; ibit++){
712 if(TESTBIT(signal, 11+ibit)){
713 SETBIT(status, ibit);
714 CLRBIT(signal, 11+ibit);
721 //_____________________________________________________________________________
722 void AliTRDclusterizer::SetPadStatus(const UChar_t status, UChar_t &out) const {
724 // Set the pad status into out
725 // First three bits are needed for the position encoding
730 //_____________________________________________________________________________
731 UChar_t AliTRDclusterizer::GetPadStatus(UChar_t encoding) const {
733 // return the staus encoding of the corrupted pad
735 return static_cast<UChar_t>(encoding >> 3);
738 //_____________________________________________________________________________
739 Int_t AliTRDclusterizer::GetCorruption(UChar_t encoding) const {
741 // Return the position of the corruption
746 //_____________________________________________________________________________
747 Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
750 // Generates the cluster.
754 fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
755 fBaseline = fDigitsManager->GetDigitsParam()->GetADCbaseline();
757 // This is to take care of switched off super modules
758 if (!fDigits->HasData()) return kFALSE;
760 fIndexes = fDigitsManager->GetIndexes(det);
761 if (fIndexes->IsAllocated() == kFALSE) {
762 AliError("Indexes do not exist!");
766 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
768 AliFatal("No AliTRDcalibDB instance available\n");
772 if (!fReconstructor){
773 AliError("Reconstructor not set\n");
777 fMaxThresh = fReconstructor->GetRecoParam()->GetClusMaxThresh();
778 fSigThresh = fReconstructor->GetRecoParam()->GetClusSigThresh();
779 fMinMaxCutSigma = fReconstructor->GetRecoParam()->GetMinMaxCutSigma();
780 fMinLeftRightCutSigma = fReconstructor->GetRecoParam()->GetMinLeftRightCutSigma();
782 Int_t istack = fIndexes->GetStack();
783 fLayer = fIndexes->GetLayer();
784 Int_t isector = fIndexes->GetSM();
786 // Start clustering in the chamber
788 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
790 AliError("Strange Detector number Missmatch!");
794 // TRD space point transformation
795 fTransform->SetDetector(det);
797 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
798 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
799 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
801 if(fReconstructor->IsProcessingTracklets() && fTrackletContainer)
802 AddTrackletsToArray();
804 fColMax = fDigits->GetNcol();
805 //Int_t nRowMax = fDigits->GetNrow();
806 fTimeTotal = fDigits->GetNtime();
808 // Detector wise calibration object for the gain factors
809 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
810 // Calibration object with pad wise values for the gain factors
811 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
812 // Calibration value for chamber wise gain factor
813 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
815 // Detector wise calibration object for the noise
816 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
817 // Calibration object with pad wise values for the noise
818 fCalNoiseROC = calibration->GetNoiseROC(fDet);
819 // Calibration value for chamber wise noise
820 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
822 // Calibration object with the pad status
823 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
825 SetBit(kLUT, fReconstructor->GetRecoParam()->UseLUT());
826 SetBit(kGAUS, fReconstructor->GetRecoParam()->UseGAUS());
827 SetBit(kHLT, fReconstructor->IsHLT());
829 firstClusterROC = -1;
832 // Apply the gain and the tail cancelation via digital filter
833 if(fReconstructor->GetRecoParam()->UseTailCancelation()) TailCancelation();
835 MaxStruct curr, last;
836 Int_t nMaximas = 0, nCorrupted = 0;
838 // Here the clusterfining is happening
840 for(curr.time = 0; curr.time < fTimeTotal; curr.time++){
841 while(fIndexes->NextRCIndex(curr.row, curr.col)){
842 if(IsMaximum(curr, curr.padStatus, &curr.signals[0])){
844 if(curr.time==last.time && curr.row==last.row && curr.col==last.col+2) FivePadCluster(last, curr);
847 last=curr; curr.fivePad=kFALSE;
851 if(last.row>-1) CreateCluster(last);
853 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 2 && fReconstructor->IsDebugStreaming()){
854 TTreeSRedirector* fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
855 (*fDebugStream) << "MakeClusters"
856 << "Detector=" << det
857 << "NMaxima=" << nMaximas
858 << "NClusters=" << fClusterROC
859 << "NCorrupted=" << nCorrupted
862 if (TestBit(kLabels)) AddLabels();
868 //_____________________________________________________________________________
869 Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Short_t *const Signals)
872 // Returns true if this row,col,time combination is a maximum.
873 // Gives back the padStatus and the signals of the center pad and the two neighbouring pads.
876 Float_t gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col,Max.row);
877 Signals[1] = (Short_t)((fDigits->GetData(Max.row, Max.col, Max.time) - fBaseline) / gain + 0.5f);
878 if(Signals[1] < fMaxThresh) return kFALSE;
880 Float_t noiseMiddleThresh = fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.col, Max.row);
881 if (Signals[1] < noiseMiddleThresh) return kFALSE;
883 if (Max.col + 1 >= fColMax || Max.col < 1) return kFALSE;
886 fCalPadStatusROC->GetStatus(Max.col-1, Max.row)
887 ,fCalPadStatusROC->GetStatus(Max.col, Max.row)
888 ,fCalPadStatusROC->GetStatus(Max.col+1, Max.row)
891 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col-1,Max.row);
892 Signals[0] = (Short_t)((fDigits->GetData(Max.row, Max.col-1, Max.time) - fBaseline) / gain + 0.5f);
893 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col+1,Max.row);
894 Signals[2] = (Short_t)((fDigits->GetData(Max.row, Max.col+1, Max.time) - fBaseline) / gain + 0.5f);
896 if(!(status[0] | status[1] | status[2])) {//all pads are good
897 if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) {
898 if ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh)) {
899 if(Signals[0]<0)Signals[0]=0;
900 if(Signals[2]<0)Signals[2]=0;
901 Float_t noiseSumThresh = fMinLeftRightCutSigma
903 * fCalNoiseROC->GetValue(Max.col, Max.row);
904 if ((Signals[2]+Signals[0]+Signals[1]) < noiseSumThresh) return kFALSE;
909 } else { // at least one of the pads is bad, and reject candidates with more than 1 problematic pad
910 if(Signals[0]<0)Signals[0]=0;
911 if(Signals[2]<0)Signals[2]=0;
912 if (status[2] && (!(status[0] || status[1])) && Signals[1] > Signals[0] && Signals[0] >= fSigThresh) {
914 SetPadStatus(status[2], padStatus);
917 else if (status[0] && (!(status[1] || status[2])) && Signals[1] >= Signals[2] && Signals[2] >= fSigThresh) {
919 SetPadStatus(status[0], padStatus);
922 else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh))) {
923 Signals[1] = (Short_t)(fMaxThresh + 0.5f);
924 SetPadStatus(status[1], padStatus);
931 //_____________________________________________________________________________
932 Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
935 // Look for 5 pad cluster with minimum in the middle
936 // Gives back the ratio
939 if (ThisMax.col >= fColMax - 3) return kFALSE;
941 if (ThisMax.col < fColMax - 5){
942 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col+4,ThisMax.row);
943 if (fDigits->GetData(ThisMax.row, ThisMax.col+4, ThisMax.time) - fBaseline >= fSigThresh * gain)
946 if (ThisMax.col > 1) {
947 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col-2,ThisMax.row);
948 if (fDigits->GetData(ThisMax.row, ThisMax.col-2, ThisMax.time) - fBaseline >= fSigThresh * gain)
952 const Float_t kEpsilon = 0.01;
953 Double_t padSignal[5] = {ThisMax.signals[0], ThisMax.signals[1], ThisMax.signals[2],
954 NeighbourMax.signals[1], NeighbourMax.signals[2]};
956 // Unfold the two maxima and set the signal on
957 // the overlapping pad to the ratio
958 Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
959 ThisMax.signals[2] = (Short_t)(ThisMax.signals[2]*ratio + 0.5f);
960 NeighbourMax.signals[0] = (Short_t)(NeighbourMax.signals[0]*(1-ratio) + 0.5f);
961 ThisMax.fivePad=kTRUE;
962 NeighbourMax.fivePad=kTRUE;
967 //_____________________________________________________________________________
968 void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
971 // Creates a cluster at the given position and saves it in fRecPoints
975 Short_t signals[7] = { 0, 0, Max.signals[0], Max.signals[1], Max.signals[2], 0, 0 };
976 if(!TestBit(kHLT)) CalcAdditionalInfo(Max, signals, nPadCount);
978 AliTRDcluster cluster(fDet, ((UChar_t) Max.col), ((UChar_t) Max.row), ((UChar_t) Max.time), signals, fVolid);
979 cluster.SetNPads(nPadCount);
980 if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
981 else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
982 else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
984 cluster.SetFivePad(Max.fivePad);
985 // set pads status for the cluster
986 UChar_t maskPosition = GetCorruption(Max.padStatus);
988 cluster.SetPadMaskedPosition(maskPosition);
989 cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
992 // Transform the local cluster coordinates into calibrated
993 // space point positions defined in the local tracking system.
994 // Here the calibration for T0, Vdrift and ExB is applied as well.
995 if(!fTransform->Transform(&cluster)) return;
996 // Temporarily store the Max.Row, column and time bin of the center pad
997 // Used to later on assign the track indices
998 cluster.SetLabel(Max.row, 0);
999 cluster.SetLabel(Max.col, 1);
1000 cluster.SetLabel(Max.time,2);
1002 //needed for HLT reconstruction
1003 AddClusterToArray(&cluster);
1005 // Store the index of the first cluster in the current ROC
1006 if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
1012 //_____________________________________________________________________________
1013 void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
1015 // Look to the right
1017 while (fDigits->GetData(Max.row, Max.col-ii, Max.time) >= fSigThresh) {
1020 if (Max.col < ii) break;
1024 while (fDigits->GetData(Max.row, Max.col+ii, Max.time) >= fSigThresh) {
1027 if (Max.col+ii >= fColMax) break;
1030 // Store the amplitudes of the pads in the cluster for later analysis
1031 // and check whether one of these pads is masked in the database
1032 signals[2]=Max.signals[0];
1033 signals[3]=Max.signals[1];
1034 signals[4]=Max.signals[2];
1036 for(Int_t i = 0; i<2; i++)
1039 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col-3+i,Max.row);
1040 signals[i] = (Short_t)((fDigits->GetData(Max.row, Max.col-3+i, Max.time) - fBaseline) / gain + 0.5f);
1042 if(Max.col+3-i < fColMax){
1043 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col+3-i,Max.row);
1044 signals[6-i] = (Short_t)((fDigits->GetData(Max.row, Max.col+3-i, Max.time) - fBaseline) / gain + 0.5f);
1047 /*for (Int_t jPad = Max.Col-3; jPad <= Max.Col+3; jPad++) {
1048 if ((jPad >= 0) && (jPad < fColMax))
1049 signals[jPad-Max.Col+3] = TMath::Nint(fDigits->GetData(Max.Row,jPad,Max.Time));
1053 //_____________________________________________________________________________
1054 void AliTRDclusterizer::AddClusterToArray(AliTRDcluster* cluster)
1057 // Add a cluster to the array
1060 Int_t n = RecPoints()->GetEntriesFast();
1061 if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
1062 new((*RecPoints())[n]) AliTRDcluster(*cluster);
1065 //_____________________________________________________________________________
1066 void AliTRDclusterizer::AddTrackletsToArray()
1069 // Add the online tracklets of this chamber to the array
1072 UInt_t* trackletword;
1073 for(Int_t side=0; side<2; side++)
1076 trackletword=fTrackletContainer[side];
1077 while(trackletword[trkl]>0){
1078 Int_t n = TrackletsArray()->GetEntriesFast();
1079 AliTRDtrackletWord tmp(trackletword[trkl]);
1080 new((*TrackletsArray())[n]) AliTRDcluster(&tmp,fDet,fVolid);
1086 //_____________________________________________________________________________
1087 Bool_t AliTRDclusterizer::AddLabels()
1090 // Add the track indices to the found clusters
1093 const Int_t kNclus = 3;
1094 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1095 const Int_t kNtrack = kNdict * kNclus;
1097 Int_t iClusterROC = 0;
1104 // Temporary array to collect the track indices
1105 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1107 // Loop through the dictionary arrays one-by-one
1108 // to keep memory consumption low
1109 AliTRDarrayDictionary *tracksIn = 0; //mod
1110 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1112 // tracksIn should be expanded beforehand!
1113 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1115 // Loop though the clusters found in this ROC
1116 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1118 AliTRDcluster *cluster = (AliTRDcluster *)
1119 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1120 row = cluster->GetLabel(0);
1121 col = cluster->GetLabel(1);
1122 time = cluster->GetLabel(2);
1124 for (iPad = 0; iPad < kNclus; iPad++) {
1125 Int_t iPadCol = col - 1 + iPad;
1126 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1127 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1134 // Copy the track indices into the cluster
1135 // Loop though the clusters found in this ROC
1136 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1138 AliTRDcluster *cluster = (AliTRDcluster *)
1139 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1140 cluster->SetLabel(-9999,0);
1141 cluster->SetLabel(-9999,1);
1142 cluster->SetLabel(-9999,2);
1144 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1148 delete [] idxTracks;
1154 //_____________________________________________________________________________
1155 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, const Double_t *const padSignal) const
1158 // Method to unfold neighbouring maxima.
1159 // The charge ratio on the overlapping pad is calculated
1160 // until there is no more change within the range given by eps.
1161 // The resulting ratio is then returned to the calling method.
1164 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1166 AliError("No AliTRDcalibDB instance available\n");
1171 Int_t itStep = 0; // Count iteration steps
1173 Double_t ratio = 0.5; // Start value for ratio
1174 Double_t prevRatio = 0.0; // Store previous ratio
1176 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1177 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1178 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1180 // Start the iteration
1181 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1186 // Cluster position according to charge ratio
1187 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1188 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1189 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1190 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1192 // Set cluster charge ratio
1193 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1194 Double_t ampLeft = padSignal[1] / newSignal[1];
1195 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1196 Double_t ampRight = padSignal[3] / newSignal[1];
1198 // Apply pad response to parameters
1199 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1200 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1202 // Calculate new overlapping ratio
1203 ratio = TMath::Min((Double_t) 1.0
1204 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1212 //_____________________________________________________________________________
1213 void AliTRDclusterizer::TailCancelation()
1216 // Applies the tail cancelation and gain factors:
1217 // Transform fDigits to fDigits
1224 Double_t *inADC = new Double_t[fTimeTotal]; // ADC data before tail cancellation
1225 Double_t *outADC = new Double_t[fTimeTotal]; // ADC data after tail cancellation
1227 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
1228 Bool_t debugStreaming = fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 7 && fReconstructor->IsDebugStreaming();
1229 while(fIndexes->NextRCIndex(iRow, iCol))
1231 Bool_t corrupted = kFALSE;
1232 if (fCalPadStatusROC->GetStatus(iCol, iRow)) corrupted = kTRUE;
1234 // Save data into the temporary processing array and substract the baseline,
1235 // since DeConvExp does not expect a baseline
1236 for (iTime = 0; iTime < fTimeTotal; iTime++)
1237 inADC[iTime] = fDigits->GetData(iRow,iCol,iTime)-fBaseline;
1240 for (iTime = 0; iTime < fTimeTotal; iTime++)
1241 (*fDebugStream) << "TailCancellation"
1245 << "inADC=" << inADC[iTime]
1246 << "outADC=" << outADC[iTime]
1247 << "corrupted=" << corrupted
1253 // Apply the tail cancelation via the digital filter
1254 // (only for non-coorupted pads)
1255 DeConvExp(&inADC[0],&outADC[0],fTimeTotal,fReconstructor->GetRecoParam() ->GetTCnexp());
1257 else memcpy(&outADC[0],&inADC[0],fTimeTotal*sizeof(inADC[0]));
1259 // Save tailcancalled data and add the baseline
1260 for(iTime = 0; iTime < fTimeTotal; iTime++)
1261 fDigits->SetData(iRow,iCol,iTime,(Short_t)(outADC[iTime] + fBaseline + 0.5));
1263 } // while irow icol
1272 //_____________________________________________________________________________
1273 void AliTRDclusterizer::DeConvExp(const Double_t *const source, Double_t *const target
1274 ,const Int_t n, const Int_t nexp)
1277 // Tail cancellation by deconvolution for PASA v4 TRF
1281 Double_t coefficients[2];
1283 // Initialization (coefficient = alpha, rates = lambda)
1289 if (nexp == 1) { // 1 Exponentials
1295 if (nexp == 2) { // 2 Exponentials
1297 fReconstructor->GetRecoParam()->GetTCParams(par);
1298 r1 = par[0];//1.156;
1299 r2 = par[1];//0.130;
1300 c1 = par[2];//0.114;
1301 c2 = par[3];//0.624;
1304 coefficients[0] = c1;
1305 coefficients[1] = c2;
1309 rates[0] = TMath::Exp(-dt/(r1));
1310 rates[1] = TMath::Exp(-dt/(r2));
1315 Double_t reminder[2];
1316 Double_t correction = 0.0;
1317 Double_t result = 0.0;
1319 // Attention: computation order is important
1320 for (k = 0; k < nexp; k++) {
1324 for (i = 0; i < n; i++) {
1326 result = (source[i] - correction); // No rescaling
1329 for (k = 0; k < nexp; k++) {
1330 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1334 for (k = 0; k < nexp; k++) {
1335 correction += reminder[k];
1342 //_____________________________________________________________________________
1343 void AliTRDclusterizer::ResetRecPoints()
1346 // Resets the list of rec points
1350 fRecPoints->Delete();
1355 //_____________________________________________________________________________
1356 TClonesArray *AliTRDclusterizer::RecPoints()
1359 // Returns the list of rec points
1363 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1364 // determine number of clusters which has to be allocated
1365 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1367 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1369 //SetClustersOwner(kTRUE);
1370 AliTRDReconstructor::SetClusters(0x0);
1376 //_____________________________________________________________________________
1377 TClonesArray *AliTRDclusterizer::TrackletsArray()
1380 // Returns the list of rec points
1383 if (!fTracklets && fReconstructor->IsProcessingTracklets()) {
1384 fTracklets = new TClonesArray("AliTRDcluster", 2*MAXTRACKLETSPERHC);
1385 //SetClustersOwner(kTRUE);
1386 //AliTRDReconstructor::SetTracklets(0x0);