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();
458 Int_t detOld = -1, nw(0);
459 for (Int_t i = 0; i < nRecPoints; i++) {
460 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
461 if(c->GetDetector() != detOld){
462 nw += ioArray->GetEntriesFast();
463 fClusterTree->Fill();
465 detOld = c->GetDetector();
469 if(ioArray->GetEntriesFast()){
470 nw += ioArray->GetEntriesFast();
471 fClusterTree->Fill();
474 AliDebug(2, Form("Clusters FOUND[%d] WRITTEN[%d] STATUS[%s]", nRecPoints, nw, nw==nRecPoints?"OK":"FAILED"));
481 //_____________________________________________________________________________
482 Bool_t AliTRDclusterizer::WriteTracklets(Int_t det)
485 // Write the raw data tracklets into seperate file
488 UInt_t **leaves = new UInt_t *[2];
489 for (Int_t i=0; i<2 ;i++){
490 leaves[i] = new UInt_t[258];
491 leaves[i][0] = det; // det
492 leaves[i][1] = i; // side
493 memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
497 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
499 fTrackletTree = dl->Tree();
502 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
504 trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
507 for (Int_t i=0; i<2; i++){
508 if (leaves[i][2]>0) {
509 trkbranch->SetAddress(leaves[i]);
510 fTrackletTree->Fill();
514 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
515 dl->WriteData("OVERWRITE");
523 //_____________________________________________________________________________
524 Bool_t AliTRDclusterizer::ReadDigits()
527 // Reads the digits arrays from the input aliroot file
531 AliError("No run loader available");
535 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
536 if (!loader->TreeD()) {
537 loader->LoadDigits();
540 // Read in the digit arrays
541 return (fDigitsManager->ReadDigits(loader->TreeD()));
545 //_____________________________________________________________________________
546 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
549 // Reads the digits arrays from the input tree
552 // Read in the digit arrays
553 return (fDigitsManager->ReadDigits(digitsTree));
557 //_____________________________________________________________________________
558 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
561 // Reads the digits arrays from the ddl file
565 fDigitsManager = raw.Raw2Digits(rawReader);
571 //_____________________________________________________________________________
572 Bool_t AliTRDclusterizer::MakeClusters()
575 // Creates clusters from digits
578 // Propagate info from the digits manager
579 if (TestBit(kLabels)){
580 SetBit(kLabels, fDigitsManager->UsesDictionaries());
583 Bool_t fReturn = kTRUE;
584 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++){
586 AliTRDarrayADC *digitsIn = (AliTRDarrayADC*) fDigitsManager->GetDigits(i); //mod
587 // This is to take care of switched off super modules
588 if (!digitsIn->HasData()) continue;
590 digitsIn->DeleteNegatives(); // Restore digits array to >=0 values
591 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
592 if (indexes->IsAllocated() == kFALSE){
593 fDigitsManager->BuildIndexes(i);
597 if (indexes->HasEntry()){
598 if (TestBit(kLabels)){
599 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++){
600 AliTRDarrayDictionary *tracksIn = 0; //mod
601 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(i,iDict); //mod
605 fR = MakeClusters(i);
606 fReturn = fR && fReturn;
610 // if(IsWritingClusters()) WriteClusters(i);
614 // No compress just remove
615 fDigitsManager->RemoveDigits(i);
616 fDigitsManager->RemoveDictionaries(i);
617 fDigitsManager->ClearIndexes(i);
620 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
622 AliInfo(Form("Number of found clusters : %d", RecPoints()->GetEntriesFast()));
628 //_____________________________________________________________________________
629 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
632 // Creates clusters from raw data
635 return Raw2ClustersChamber(rawReader);
639 //_____________________________________________________________________________
640 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
643 // Creates clusters from raw data
646 // Create the digits manager
647 if (!fDigitsManager){
648 SetBit(knewDM, kTRUE);
649 fDigitsManager = new AliTRDdigitsManager(kTRUE);
650 fDigitsManager->CreateArrays();
653 fDigitsManager->SetUseDictionaries(TestBit(kLabels));
655 // tracklet container for raw tracklet writing
656 if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
657 // maximum tracklets for one HC
658 const Int_t kTrackletChmb=256;
659 fTrackletContainer = new UInt_t *[2];
660 fTrackletContainer[0] = new UInt_t[kTrackletChmb];
661 fTrackletContainer[1] = new UInt_t[kTrackletChmb];
665 fRawStream = AliTRDrawStreamBase::GetRawStream(rawReader);
667 fRawStream->SetReader(rawReader);
669 SetBit(kHLT, fReconstructor->IsHLT());
672 fRawStream->SetSharedPadReadout(kFALSE);
673 fRawStream->SetNoErrorWarning();
676 AliDebug(1,Form("Stream version: %s", fRawStream->IsA()->GetName()));
679 while ((det = fRawStream->NextChamber(fDigitsManager,fTrackletContainer)) >= 0){
680 if (fDigitsManager->GetIndexes(det)->HasEntry())
683 fDigitsManager->ClearArrays(det);
685 if (!fReconstructor->IsWritingTracklets()) continue;
686 if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
689 if (fTrackletContainer){
690 delete [] fTrackletContainer[0];
691 delete [] fTrackletContainer[1];
692 delete [] fTrackletContainer;
693 fTrackletContainer = NULL;
696 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
698 if(!TestBit(knewDM)){
699 delete fDigitsManager;
700 fDigitsManager = NULL;
705 AliInfo(Form("Number of found clusters : %d", fNoOfClusters));
710 //_____________________________________________________________________________
711 UChar_t AliTRDclusterizer::GetStatus(Short_t &signal)
714 // Check if a pad is masked
719 if(signal>0 && TESTBIT(signal, 10)){
721 for(int ibit=0; ibit<4; ibit++){
722 if(TESTBIT(signal, 11+ibit)){
723 SETBIT(status, ibit);
724 CLRBIT(signal, 11+ibit);
731 //_____________________________________________________________________________
732 void AliTRDclusterizer::SetPadStatus(const UChar_t status, UChar_t &out) const {
734 // Set the pad status into out
735 // First three bits are needed for the position encoding
740 //_____________________________________________________________________________
741 UChar_t AliTRDclusterizer::GetPadStatus(UChar_t encoding) const {
743 // return the staus encoding of the corrupted pad
745 return static_cast<UChar_t>(encoding >> 3);
748 //_____________________________________________________________________________
749 Int_t AliTRDclusterizer::GetCorruption(UChar_t encoding) const {
751 // Return the position of the corruption
756 //_____________________________________________________________________________
757 Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
760 // Generates the cluster.
764 fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
765 fBaseline = fDigitsManager->GetDigitsParam()->GetADCbaseline(det);
767 // This is to take care of switched off super modules
768 if (!fDigits->HasData()) return kFALSE;
770 fIndexes = fDigitsManager->GetIndexes(det);
771 if (fIndexes->IsAllocated() == kFALSE) {
772 AliError("Indexes do not exist!");
776 AliTRDcalibDB* const calibration = AliTRDcalibDB::Instance();
778 AliFatal("No AliTRDcalibDB instance available\n");
782 if (!fReconstructor){
783 AliError("Reconstructor not set\n");
787 const AliTRDrecoParam *const recoParam = fReconstructor->GetRecoParam();
789 fMaxThresh = recoParam->GetClusMaxThresh();
790 fSigThresh = recoParam->GetClusSigThresh();
791 fMinMaxCutSigma = recoParam->GetMinMaxCutSigma();
792 fMinLeftRightCutSigma = recoParam->GetMinLeftRightCutSigma();
794 Int_t istack = fIndexes->GetStack();
795 fLayer = fIndexes->GetLayer();
796 Int_t isector = fIndexes->GetSM();
798 // Start clustering in the chamber
800 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
802 AliError("Strange Detector number Missmatch!");
806 AliDebug(2, Form("Det[%d] @ Sec[%d] Stk[%d] Ly[%d]", fDet, isector, istack, fLayer));
808 // TRD space point transformation
809 fTransform->SetDetector(det);
811 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
812 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
813 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
815 if(fReconstructor->IsProcessingTracklets() && fTrackletContainer)
816 AddTrackletsToArray();
818 fColMax = fDigits->GetNcol();
819 fTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
821 // Check consistency between OCDB and raw data
822 Int_t nTimeOCDB = calibration->GetNumberOfTimeBinsDCS();
824 if((nTimeOCDB > -1) && (fTimeTotal != nTimeOCDB)){
825 AliWarning(Form("Number of timebins does not match OCDB value (RAW[%d] OCDB[%d]), using raw value"
826 ,fTimeTotal,nTimeOCDB));
830 AliWarning("Undefined number of timebins in OCDB, using value from raw data.");
832 AliError("Number of timebins in raw data is negative, skipping chamber!");
835 }else if(nTimeOCDB == -2){
836 AliError("Mixed number of timebins in OCDB, no reconstruction of TRD data!");
838 }else if(fTimeTotal != nTimeOCDB){
839 AliError(Form("Number of timebins in raw data does not match OCDB value (RAW[%d] OCDB[%d]), skipping chamber!"
840 ,fTimeTotal,nTimeOCDB));
845 // Detector wise calibration object for the gain factors
846 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
847 // Calibration object with pad wise values for the gain factors
848 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
849 // Calibration value for chamber wise gain factor
850 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
852 // Detector wise calibration object for the noise
853 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
854 // Calibration object with pad wise values for the noise
855 fCalNoiseROC = calibration->GetNoiseROC(fDet);
856 // Calibration value for chamber wise noise
857 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
859 // Calibration object with the pad status
860 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
862 firstClusterROC = -1;
865 SetBit(kLUT, recoParam->UseLUT());
866 SetBit(kGAUS, recoParam->UseGAUS());
868 // Apply the gain and the tail cancelation via digital filter
869 if(recoParam->UseTailCancelation()) TailCancelation(recoParam);
871 MaxStruct curr, last;
872 Int_t nMaximas = 0, nCorrupted = 0;
874 // Here the clusterfining is happening
876 for(curr.time = 0; curr.time < fTimeTotal; curr.time++){
877 while(fIndexes->NextRCIndex(curr.row, curr.col)){
878 if(IsMaximum(curr, curr.padStatus, &curr.signals[0])){
880 if(curr.time==last.time && curr.row==last.row && curr.col==last.col+2) FivePadCluster(last, curr);
883 last=curr; curr.fivePad=kFALSE;
887 if(last.row>-1) CreateCluster(last);
889 if(recoParam->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 2 && fReconstructor->IsDebugStreaming()){
890 TTreeSRedirector* fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
891 (*fDebugStream) << "MakeClusters"
892 << "Detector=" << det
893 << "NMaxima=" << nMaximas
894 << "NClusters=" << fClusterROC
895 << "NCorrupted=" << nCorrupted
898 if (TestBit(kLabels)) AddLabels();
904 //_____________________________________________________________________________
905 Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Short_t *const Signals)
908 // Returns true if this row,col,time combination is a maximum.
909 // Gives back the padStatus and the signals of the center pad and the two neighbouring pads.
912 Float_t gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col,Max.row);
913 Signals[1] = (Short_t)((fDigits->GetData(Max.row, Max.col, Max.time) - fBaseline) / gain + 0.5f);
914 if(Signals[1] < fMaxThresh) return kFALSE;
916 Float_t noiseMiddleThresh = fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.col, Max.row);
917 if (Signals[1] < noiseMiddleThresh) return kFALSE;
919 if (Max.col + 1 >= fColMax || Max.col < 1) return kFALSE;
922 fCalPadStatusROC->GetStatus(Max.col-1, Max.row)
923 ,fCalPadStatusROC->GetStatus(Max.col, Max.row)
924 ,fCalPadStatusROC->GetStatus(Max.col+1, Max.row)
927 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col-1,Max.row);
928 Signals[0] = (Short_t)((fDigits->GetData(Max.row, Max.col-1, Max.time) - fBaseline) / gain + 0.5f);
929 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col+1,Max.row);
930 Signals[2] = (Short_t)((fDigits->GetData(Max.row, Max.col+1, Max.time) - fBaseline) / gain + 0.5f);
932 if(!(status[0] | status[1] | status[2])) {//all pads are good
933 if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) {
934 if ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh)) {
935 if(Signals[0]<0)Signals[0]=0;
936 if(Signals[2]<0)Signals[2]=0;
937 Float_t noiseSumThresh = fMinLeftRightCutSigma
939 * fCalNoiseROC->GetValue(Max.col, Max.row);
940 if ((Signals[2]+Signals[0]+Signals[1]) < noiseSumThresh) return kFALSE;
945 } else { // at least one of the pads is bad, and reject candidates with more than 1 problematic pad
946 if(Signals[0]<0)Signals[0]=0;
947 if(Signals[2]<0)Signals[2]=0;
948 if (status[2] && (!(status[0] || status[1])) && Signals[1] > Signals[0] && Signals[0] >= fSigThresh) {
950 SetPadStatus(status[2], padStatus);
953 else if (status[0] && (!(status[1] || status[2])) && Signals[1] >= Signals[2] && Signals[2] >= fSigThresh) {
955 SetPadStatus(status[0], padStatus);
958 else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh))) {
959 Signals[1] = (Short_t)(fMaxThresh + 0.5f);
960 SetPadStatus(status[1], padStatus);
967 //_____________________________________________________________________________
968 Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
971 // Look for 5 pad cluster with minimum in the middle
972 // Gives back the ratio
975 if (ThisMax.col >= fColMax - 3) return kFALSE;
977 if (ThisMax.col < fColMax - 5){
978 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col+4,ThisMax.row);
979 if (fDigits->GetData(ThisMax.row, ThisMax.col+4, ThisMax.time) - fBaseline >= fSigThresh * gain)
982 if (ThisMax.col > 1) {
983 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col-2,ThisMax.row);
984 if (fDigits->GetData(ThisMax.row, ThisMax.col-2, ThisMax.time) - fBaseline >= fSigThresh * gain)
988 const Float_t kEpsilon = 0.01;
989 Double_t padSignal[5] = {ThisMax.signals[0], ThisMax.signals[1], ThisMax.signals[2],
990 NeighbourMax.signals[1], NeighbourMax.signals[2]};
992 // Unfold the two maxima and set the signal on
993 // the overlapping pad to the ratio
994 Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
995 ThisMax.signals[2] = (Short_t)(ThisMax.signals[2]*ratio + 0.5f);
996 NeighbourMax.signals[0] = (Short_t)(NeighbourMax.signals[0]*(1-ratio) + 0.5f);
997 ThisMax.fivePad=kTRUE;
998 NeighbourMax.fivePad=kTRUE;
1003 //_____________________________________________________________________________
1004 void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
1007 // Creates a cluster at the given position and saves it in fRecPoints
1010 Int_t nPadCount = 1;
1011 Short_t signals[7] = { 0, 0, Max.signals[0], Max.signals[1], Max.signals[2], 0, 0 };
1012 if(!TestBit(kHLT)) CalcAdditionalInfo(Max, signals, nPadCount);
1014 AliTRDcluster cluster(fDet, ((UChar_t) Max.col), ((UChar_t) Max.row), ((UChar_t) Max.time), signals, fVolid);
1015 cluster.SetNPads(nPadCount);
1016 if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
1017 else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
1018 else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
1020 cluster.SetFivePad(Max.fivePad);
1021 // set pads status for the cluster
1022 UChar_t maskPosition = GetCorruption(Max.padStatus);
1024 cluster.SetPadMaskedPosition(maskPosition);
1025 cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
1028 // Transform the local cluster coordinates into calibrated
1029 // space point positions defined in the local tracking system.
1030 // Here the calibration for T0, Vdrift and ExB is applied as well.
1031 if(!fTransform->Transform(&cluster)) return;
1032 // Temporarily store the Max.Row, column and time bin of the center pad
1033 // Used to later on assign the track indices
1034 cluster.SetLabel(Max.row, 0);
1035 cluster.SetLabel(Max.col, 1);
1036 cluster.SetLabel(Max.time,2);
1038 //needed for HLT reconstruction
1039 AddClusterToArray(&cluster);
1041 // Store the index of the first cluster in the current ROC
1042 if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
1048 //_____________________________________________________________________________
1049 void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
1051 // Look to the right
1053 while (fDigits->GetData(Max.row, Max.col-ii, Max.time) >= fSigThresh) {
1056 if (Max.col < ii) break;
1060 while (fDigits->GetData(Max.row, Max.col+ii, Max.time) >= fSigThresh) {
1063 if (Max.col+ii >= fColMax) break;
1066 // Store the amplitudes of the pads in the cluster for later analysis
1067 // and check whether one of these pads is masked in the database
1068 signals[2]=Max.signals[0];
1069 signals[3]=Max.signals[1];
1070 signals[4]=Max.signals[2];
1072 for(Int_t i = 0; i<2; i++)
1075 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col-3+i,Max.row);
1076 signals[i] = (Short_t)((fDigits->GetData(Max.row, Max.col-3+i, Max.time) - fBaseline) / gain + 0.5f);
1078 if(Max.col+3-i < fColMax){
1079 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col+3-i,Max.row);
1080 signals[6-i] = (Short_t)((fDigits->GetData(Max.row, Max.col+3-i, Max.time) - fBaseline) / gain + 0.5f);
1083 /*for (Int_t jPad = Max.Col-3; jPad <= Max.Col+3; jPad++) {
1084 if ((jPad >= 0) && (jPad < fColMax))
1085 signals[jPad-Max.Col+3] = TMath::Nint(fDigits->GetData(Max.Row,jPad,Max.Time));
1089 //_____________________________________________________________________________
1090 void AliTRDclusterizer::AddClusterToArray(AliTRDcluster* cluster)
1093 // Add a cluster to the array
1096 Int_t n = RecPoints()->GetEntriesFast();
1097 if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
1098 new((*RecPoints())[n]) AliTRDcluster(*cluster);
1101 //_____________________________________________________________________________
1102 void AliTRDclusterizer::AddTrackletsToArray()
1105 // Add the online tracklets of this chamber to the array
1108 UInt_t* trackletword;
1109 for(Int_t side=0; side<2; side++)
1112 trackletword=fTrackletContainer[side];
1113 while(trackletword[trkl]>0){
1114 Int_t n = TrackletsArray()->GetEntriesFast();
1115 AliTRDtrackletWord tmp(trackletword[trkl]);
1116 new((*TrackletsArray())[n]) AliTRDcluster(&tmp,fDet,fVolid);
1122 //_____________________________________________________________________________
1123 Bool_t AliTRDclusterizer::AddLabels()
1126 // Add the track indices to the found clusters
1129 const Int_t kNclus = 3;
1130 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1131 const Int_t kNtrack = kNdict * kNclus;
1133 Int_t iClusterROC = 0;
1140 // Temporary array to collect the track indices
1141 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1143 // Loop through the dictionary arrays one-by-one
1144 // to keep memory consumption low
1145 AliTRDarrayDictionary *tracksIn = 0; //mod
1146 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1148 // tracksIn should be expanded beforehand!
1149 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1151 // Loop though the clusters found in this ROC
1152 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1154 AliTRDcluster *cluster = (AliTRDcluster *)
1155 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1156 row = cluster->GetLabel(0);
1157 col = cluster->GetLabel(1);
1158 time = cluster->GetLabel(2);
1160 for (iPad = 0; iPad < kNclus; iPad++) {
1161 Int_t iPadCol = col - 1 + iPad;
1162 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1163 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1170 // Copy the track indices into the cluster
1171 // Loop though the clusters found in this ROC
1172 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1174 AliTRDcluster *cluster = (AliTRDcluster *)
1175 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1176 cluster->SetLabel(-9999,0);
1177 cluster->SetLabel(-9999,1);
1178 cluster->SetLabel(-9999,2);
1180 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1184 delete [] idxTracks;
1190 //_____________________________________________________________________________
1191 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, const Double_t *const padSignal) const
1194 // Method to unfold neighbouring maxima.
1195 // The charge ratio on the overlapping pad is calculated
1196 // until there is no more change within the range given by eps.
1197 // The resulting ratio is then returned to the calling method.
1200 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1202 AliError("No AliTRDcalibDB instance available\n");
1207 Int_t itStep = 0; // Count iteration steps
1209 Double_t ratio = 0.5; // Start value for ratio
1210 Double_t prevRatio = 0.0; // Store previous ratio
1212 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1213 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1214 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1216 // Start the iteration
1217 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1222 // Cluster position according to charge ratio
1223 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1224 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1225 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1226 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1228 // Set cluster charge ratio
1229 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1230 Double_t ampLeft = padSignal[1] / newSignal[1];
1231 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1232 Double_t ampRight = padSignal[3] / newSignal[1];
1234 // Apply pad response to parameters
1235 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1236 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1238 // Calculate new overlapping ratio
1239 ratio = TMath::Min((Double_t) 1.0
1240 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1248 //_____________________________________________________________________________
1249 void AliTRDclusterizer::TailCancelation(const AliTRDrecoParam* const recoParam)
1252 // Applies the tail cancelation
1259 Float_t *arr = new Float_t[fTimeTotal]; // temp array containing the ADC signals
1261 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
1262 Bool_t debugStreaming = recoParam->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 7 && fReconstructor->IsDebugStreaming();
1263 Int_t nexp = recoParam->GetTCnexp();
1264 while(fIndexes->NextRCIndex(iRow, iCol))
1266 // if corrupted then don't make the tail cancallation
1267 if (fCalPadStatusROC->GetStatus(iCol, iRow)) continue;
1269 // Save data into the temporary processing array and substract the baseline,
1270 // since DeConvExp does not expect a baseline
1271 for (iTime = 0; iTime < fTimeTotal; iTime++)
1272 arr[iTime] = fDigits->GetData(iRow,iCol,iTime)-fBaseline;
1275 for (iTime = 0; iTime < fTimeTotal; iTime++)
1276 (*fDebugStream) << "TailCancellation"
1280 << "arr=" << arr[iTime]
1284 // Apply the tail cancelation via the digital filter
1285 DeConvExp(arr,fTimeTotal,nexp);
1287 // Save tailcancalled data and add the baseline
1288 for(iTime = 0; iTime < fTimeTotal; iTime++)
1289 fDigits->SetData(iRow,iCol,iTime,(Short_t)(arr[iTime] + fBaseline + 0.5f));
1291 } // while irow icol
1299 //_____________________________________________________________________________
1300 void AliTRDclusterizer::DeConvExp(Float_t *const arr, const Int_t nTime, const Int_t nexp)
1303 // Tail cancellation by deconvolution for PASA v4 TRF
1307 Float_t coefficients[2];
1309 // Initialization (coefficient = alpha, rates = lambda)
1315 if (nexp == 1) { // 1 Exponentials
1321 if (nexp == 2) { // 2 Exponentials
1323 fReconstructor->GetRecoParam()->GetTCParams(par);
1324 r1 = par[0];//1.156;
1325 r2 = par[1];//0.130;
1326 c1 = par[2];//0.114;
1327 c2 = par[3];//0.624;
1330 coefficients[0] = c1;
1331 coefficients[1] = c2;
1335 rates[0] = TMath::Exp(-dt/(r1));
1336 rates[1] = TMath::Exp(-dt/(r2));
1341 Float_t reminder[2];
1342 Float_t correction = 0.0;
1343 Float_t result = 0.0;
1345 // Attention: computation order is important
1346 for (k = 0; k < nexp; k++) {
1350 for (i = 0; i < nTime; i++) {
1352 result = (arr[i] - correction); // No rescaling
1355 for (k = 0; k < nexp; k++) {
1356 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1360 for (k = 0; k < nexp; k++) {
1361 correction += reminder[k];
1368 //_____________________________________________________________________________
1369 void AliTRDclusterizer::ResetRecPoints()
1372 // Resets the list of rec points
1376 fRecPoints->Delete();
1381 //_____________________________________________________________________________
1382 TClonesArray *AliTRDclusterizer::RecPoints()
1385 // Returns the list of rec points
1389 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1390 // determine number of clusters which has to be allocated
1391 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1393 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1395 //SetClustersOwner(kTRUE);
1396 AliTRDReconstructor::SetClusters(0x0);
1402 //_____________________________________________________________________________
1403 TClonesArray *AliTRDclusterizer::TrackletsArray()
1406 // Returns the list of rec points
1409 if (!fTracklets && fReconstructor->IsProcessingTracklets()) {
1410 fTracklets = new TClonesArray("AliTRDcluster", 2*MAXTRACKLETSPERHC);
1411 //SetClustersOwner(kTRUE);
1412 //AliTRDReconstructor::SetTracklets(0x0);