1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // TRD cluster finder //
22 ///////////////////////////////////////////////////////////////////////////////
24 #include <TClonesArray.h>
25 #include <TObjArray.h>
27 #include "AliRunLoader.h"
28 #include "AliLoader.h"
29 #include "AliAlignObj.h"
31 #include "AliTRDclusterizer.h"
32 #include "AliTRDcluster.h"
33 #include "AliTRDReconstructor.h"
34 #include "AliTRDgeometry.h"
35 #include "AliTRDarrayDictionary.h"
36 #include "AliTRDarrayADC.h"
37 #include "AliTRDdigitsManager.h"
38 #include "AliTRDrawData.h"
39 #include "AliTRDcalibDB.h"
40 #include "AliTRDtransform.h"
41 #include "AliTRDSignalIndex.h"
42 #include "AliTRDrawStreamBase.h"
43 #include "AliTRDfeeParam.h"
44 #include "AliTRDtrackletWord.h"
46 #include "TTreeStream.h"
48 #include "Cal/AliTRDCalROC.h"
49 #include "Cal/AliTRDCalDet.h"
50 #include "Cal/AliTRDCalSingleChamberStatus.h"
52 ClassImp(AliTRDclusterizer)
54 //_____________________________________________________________________________
55 AliTRDclusterizer::AliTRDclusterizer(const AliTRDReconstructor *const rec)
63 ,fDigitsManager(new AliTRDdigitsManager())
64 ,fTrackletContainer(NULL)
66 ,fTransform(new AliTRDtransform(0))
73 ,fMinLeftRightCutSigma(0)
79 ,fCalGainFactorROC(NULL)
80 ,fCalGainFactorDetValue(0)
83 ,fCalPadStatusROC(NULL)
89 // AliTRDclusterizer default constructor
92 SetBit(kLabels, kTRUE);
94 AliTRDcalibDB *trd = 0x0;
95 if (!(trd = AliTRDcalibDB::Instance())) {
96 AliFatal("Could not get calibration object");
99 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
101 // Initialize debug stream
103 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kClusterizer) > 1){
104 TDirectory *savedir = gDirectory;
105 //fgGetDebugStream = new TTreeSRedirector("TRD.ClusterizerDebug.root");
112 //_____________________________________________________________________________
113 AliTRDclusterizer::AliTRDclusterizer(const Text_t *name, const Text_t *title, const AliTRDReconstructor *const rec)
121 ,fDigitsManager(new AliTRDdigitsManager())
122 ,fTrackletContainer(NULL)
124 ,fTransform(new AliTRDtransform(0))
131 ,fMinLeftRightCutSigma(0)
137 ,fCalGainFactorROC(NULL)
138 ,fCalGainFactorDetValue(0)
140 ,fCalNoiseDetValue(0)
141 ,fCalPadStatusROC(NULL)
147 // AliTRDclusterizer constructor
150 SetBit(kLabels, kTRUE);
152 AliTRDcalibDB *trd = 0x0;
153 if (!(trd = AliTRDcalibDB::Instance())) {
154 AliFatal("Could not get calibration object");
157 fDigitsManager->CreateArrays();
159 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
165 //_____________________________________________________________________________
166 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
168 ,fReconstructor(c.fReconstructor)
174 ,fDigitsManager(NULL)
175 ,fTrackletContainer(NULL)
184 ,fMinLeftRightCutSigma(0)
190 ,fCalGainFactorROC(NULL)
191 ,fCalGainFactorDetValue(0)
193 ,fCalNoiseDetValue(0)
194 ,fCalPadStatusROC(NULL)
200 // AliTRDclusterizer copy constructor
203 SetBit(kLabels, kTRUE);
209 //_____________________________________________________________________________
210 AliTRDclusterizer::~AliTRDclusterizer()
213 // AliTRDclusterizer destructor
216 if (fRecPoints/* && IsClustersOwner()*/){
217 fRecPoints->Delete();
222 fTracklets->Delete();
226 if (fDigitsManager) {
227 delete fDigitsManager;
228 fDigitsManager = NULL;
231 if (fTrackletContainer){
232 delete fTrackletContainer;
233 fTrackletContainer = NULL;
243 //_____________________________________________________________________________
244 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
247 // Assignment operator
252 ((AliTRDclusterizer &) c).Copy(*this);
259 //_____________________________________________________________________________
260 void AliTRDclusterizer::Copy(TObject &c) const
266 ((AliTRDclusterizer &) c).fClusterTree = NULL;
267 ((AliTRDclusterizer &) c).fRecPoints = NULL;
268 ((AliTRDclusterizer &) c).fTrackletTree = NULL;
269 ((AliTRDclusterizer &) c).fDigitsManager = NULL;
270 ((AliTRDclusterizer &) c).fTrackletContainer = NULL;
271 ((AliTRDclusterizer &) c).fRawVersion = fRawVersion;
272 ((AliTRDclusterizer &) c).fTransform = NULL;
273 ((AliTRDclusterizer &) c).fDigits = NULL;
274 ((AliTRDclusterizer &) c).fIndexes = NULL;
275 ((AliTRDclusterizer &) c).fADCthresh = 0;
276 ((AliTRDclusterizer &) c).fMaxThresh = 0;
277 ((AliTRDclusterizer &) c).fSigThresh = 0;
278 ((AliTRDclusterizer &) c).fMinMaxCutSigma= 0;
279 ((AliTRDclusterizer &) c).fMinLeftRightCutSigma = 0;
280 ((AliTRDclusterizer &) c).fLayer = 0;
281 ((AliTRDclusterizer &) c).fDet = 0;
282 ((AliTRDclusterizer &) c).fVolid = 0;
283 ((AliTRDclusterizer &) c).fColMax = 0;
284 ((AliTRDclusterizer &) c).fTimeTotal = 0;
285 ((AliTRDclusterizer &) c).fCalGainFactorROC = NULL;
286 ((AliTRDclusterizer &) c).fCalGainFactorDetValue = 0;
287 ((AliTRDclusterizer &) c).fCalNoiseROC = NULL;
288 ((AliTRDclusterizer &) c).fCalNoiseDetValue = 0;
289 ((AliTRDclusterizer &) c).fCalPadStatusROC = NULL;
290 ((AliTRDclusterizer &) c).fClusterROC = 0;
291 ((AliTRDclusterizer &) c).firstClusterROC= 0;
292 ((AliTRDclusterizer &) c).fNoOfClusters = 0;
295 //_____________________________________________________________________________
296 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
299 // Opens the AliROOT file. Output and input are in the same file
302 TString evfoldname = AliConfig::GetDefaultEventFolderName();
303 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
306 fRunLoader = AliRunLoader::Open(name);
310 AliError(Form("Can not open session for file %s.",name));
321 //_____________________________________________________________________________
322 Bool_t AliTRDclusterizer::OpenOutput()
325 // Open the output file
328 if (!fReconstructor->IsWritingClusters()) return kTRUE;
330 TObjArray *ioArray = 0x0;
332 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
333 loader->MakeTree("R");
335 fClusterTree = loader->TreeR();
336 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
342 //_____________________________________________________________________________
343 Bool_t AliTRDclusterizer::OpenOutput(TTree *const clusterTree)
346 // Connect the output tree
350 if (fReconstructor->IsWritingClusters()){
351 TObjArray *ioArray = 0x0;
352 fClusterTree = clusterTree;
353 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
358 //_____________________________________________________________________________
359 Bool_t AliTRDclusterizer::OpenTrackletOutput()
365 if (fReconstructor->IsWritingTracklets()){
366 TString evfoldname = AliConfig::GetDefaultEventFolderName();
367 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
370 fRunLoader = AliRunLoader::Open("galice.root");
373 AliError(Form("Can not open session for file galice.root."));
377 UInt_t **leaves = new UInt_t *[2];
378 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
380 AliError("Could not get the tracklets data loader!");
381 dl = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
382 fRunLoader->GetLoader("TRDLoader")->AddDataLoader(dl);
384 fTrackletTree = dl->Tree();
388 fTrackletTree = dl->Tree();
390 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
392 fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
398 //_____________________________________________________________________________
399 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
402 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
405 // Import the Trees for the event nEvent in the file
406 fRunLoader->GetEvent(nEvent);
412 //_____________________________________________________________________________
413 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
416 // Fills TRDcluster branch in the tree with the clusters
417 // found in detector = det. For det=-1 writes the tree.
421 (det >= AliTRDgeometry::Ndet())) {
422 AliError(Form("Unexpected detector index %d.\n",det));
426 TObjArray *ioArray = new TObjArray(400);
427 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
429 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
430 } else branch->SetAddress(&ioArray);
432 Int_t nRecPoints = RecPoints()->GetEntriesFast();
434 for (Int_t i = 0; i < nRecPoints; i++) {
435 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
436 if(det != c->GetDetector()) continue;
439 fClusterTree->Fill();
443 for (Int_t i = 0; i < nRecPoints; i++) {
444 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
445 if(c->GetDetector() != detOld){
446 fClusterTree->Fill();
448 detOld = c->GetDetector();
459 //_____________________________________________________________________________
460 Bool_t AliTRDclusterizer::WriteTracklets(Int_t det)
463 // Write the raw data tracklets into seperate file
466 UInt_t **leaves = new UInt_t *[2];
467 for (Int_t i=0; i<2 ;i++){
468 leaves[i] = new UInt_t[258];
469 leaves[i][0] = det; // det
470 leaves[i][1] = i; // side
471 memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
475 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
477 fTrackletTree = dl->Tree();
480 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
482 trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
485 for (Int_t i=0; i<2; i++){
486 if (leaves[i][2]>0) {
487 trkbranch->SetAddress(leaves[i]);
488 fTrackletTree->Fill();
492 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
493 dl->WriteData("OVERWRITE");
501 //_____________________________________________________________________________
502 Bool_t AliTRDclusterizer::ReadDigits()
505 // Reads the digits arrays from the input aliroot file
509 AliError("No run loader available");
513 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
514 if (!loader->TreeD()) {
515 loader->LoadDigits();
518 // Read in the digit arrays
519 return (fDigitsManager->ReadDigits(loader->TreeD()));
523 //_____________________________________________________________________________
524 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
527 // Reads the digits arrays from the input tree
530 // Read in the digit arrays
531 return (fDigitsManager->ReadDigits(digitsTree));
535 //_____________________________________________________________________________
536 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
539 // Reads the digits arrays from the ddl file
543 fDigitsManager = raw.Raw2Digits(rawReader);
549 //_____________________________________________________________________________
550 Bool_t AliTRDclusterizer::MakeClusters()
553 // Creates clusters from digits
556 // Propagate info from the digits manager
557 if (TestBit(kLabels)){
558 SetBit(kLabels, fDigitsManager->UsesDictionaries());
561 Bool_t fReturn = kTRUE;
562 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++){
564 AliTRDarrayADC *digitsIn = (AliTRDarrayADC*) fDigitsManager->GetDigits(i); //mod
565 // This is to take care of switched off super modules
566 if (!digitsIn->HasData()) continue;
568 digitsIn->DeleteNegatives(); // Restore digits array to >=0 values
569 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
570 if (indexes->IsAllocated() == kFALSE){
571 fDigitsManager->BuildIndexes(i);
575 if (indexes->HasEntry()){
576 if (TestBit(kLabels)){
577 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++){
578 AliTRDarrayDictionary *tracksIn = 0; //mod
579 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(i,iDict); //mod
583 fR = MakeClusters(i);
584 fReturn = fR && fReturn;
588 // if(IsWritingClusters()) WriteClusters(i);
592 // No compress just remove
593 fDigitsManager->RemoveDigits(i);
594 fDigitsManager->RemoveDictionaries(i);
595 fDigitsManager->ClearIndexes(i);
598 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
600 AliInfo(Form("Number of found clusters : %d", RecPoints()->GetEntriesFast()));
606 //_____________________________________________________________________________
607 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
610 // Creates clusters from raw data
613 return Raw2ClustersChamber(rawReader);
617 //_____________________________________________________________________________
618 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
621 // Creates clusters from raw data
624 // Create the digits manager
625 if (!fDigitsManager){
626 fDigitsManager = new AliTRDdigitsManager(kTRUE);
627 fDigitsManager->CreateArrays();
630 fDigitsManager->SetUseDictionaries(TestBit(kLabels));
632 // tracklet container for raw tracklet writing
633 if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
634 // maximum tracklets for one HC
635 const Int_t kTrackletChmb=256;
636 fTrackletContainer = new UInt_t *[2];
637 fTrackletContainer[0] = new UInt_t[kTrackletChmb];
638 fTrackletContainer[1] = new UInt_t[kTrackletChmb];
641 AliTRDrawStreamBase *input = AliTRDrawStreamBase::GetRawStream(rawReader);
643 AliInfo(Form("Stream version: %s", input->IsA()->GetName()));
646 while ((det = input->NextChamber(fDigitsManager,fTrackletContainer)) >= 0){
647 Bool_t iclusterBranch = kFALSE;
648 if (fDigitsManager->GetIndexes(det)->HasEntry()){
649 iclusterBranch = MakeClusters(det);
652 fDigitsManager->ResetArrays(det);
654 if (!fReconstructor->IsWritingTracklets()) continue;
655 if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
658 if (fTrackletContainer){
659 delete [] fTrackletContainer[0];
660 delete [] fTrackletContainer[1];
661 delete [] fTrackletContainer;
662 fTrackletContainer = NULL;
665 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
667 delete fDigitsManager;
668 fDigitsManager = NULL;
673 AliInfo(Form("Number of found clusters : %d", fNoOfClusters));
678 //_____________________________________________________________________________
679 UChar_t AliTRDclusterizer::GetStatus(Short_t &signal)
682 // Check if a pad is masked
687 if(signal>0 && TESTBIT(signal, 10)){
689 for(int ibit=0; ibit<4; ibit++){
690 if(TESTBIT(signal, 11+ibit)){
691 SETBIT(status, ibit);
692 CLRBIT(signal, 11+ibit);
699 //_____________________________________________________________________________
700 void AliTRDclusterizer::SetPadStatus(const UChar_t status, UChar_t &out) const {
702 // Set the pad status into out
703 // First three bits are needed for the position encoding
708 //_____________________________________________________________________________
709 UChar_t AliTRDclusterizer::GetPadStatus(UChar_t encoding) const {
711 // return the staus encoding of the corrupted pad
713 return static_cast<UChar_t>(encoding >> 3);
716 //_____________________________________________________________________________
717 Int_t AliTRDclusterizer::GetCorruption(UChar_t encoding) const {
719 // Return the position of the corruption
724 //_____________________________________________________________________________
725 Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
728 // Generates the cluster.
732 // digits should be expanded beforehand!
733 // digitsIn->Expand();
734 fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
736 // This is to take care of switched off super modules
737 if (!fDigits->HasData()) return kFALSE;
739 fIndexes = fDigitsManager->GetIndexes(det);
740 if (fIndexes->IsAllocated() == kFALSE) {
741 AliError("Indexes do not exist!");
745 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
747 AliFatal("No AliTRDcalibDB instance available\n");
753 if (!fReconstructor){
754 AliError("Reconstructor not set\n");
758 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDReconstructor::kClusterizer);
760 fMaxThresh = fReconstructor->GetRecoParam()->GetClusMaxThresh();
761 fSigThresh = fReconstructor->GetRecoParam()->GetClusSigThresh();
762 fMinMaxCutSigma = fReconstructor->GetRecoParam()->GetMinMaxCutSigma();
763 fMinLeftRightCutSigma = fReconstructor->GetRecoParam()->GetMinLeftRightCutSigma();
765 Int_t istack = fIndexes->GetStack();
766 fLayer = fIndexes->GetLayer();
767 Int_t isector = fIndexes->GetSM();
769 // Start clustering in the chamber
771 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
773 AliError("Strange Detector number Missmatch!");
777 // TRD space point transformation
778 fTransform->SetDetector(det);
780 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
781 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
782 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
784 if(fReconstructor->IsProcessingTracklets() && fTrackletContainer)
785 AddTrackletsToArray();
787 fColMax = fDigits->GetNcol();
788 //Int_t nRowMax = fDigits->GetNrow();
789 fTimeTotal = fDigits->GetNtime();
791 // Detector wise calibration object for the gain factors
792 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
793 // Calibration object with pad wise values for the gain factors
794 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
795 // Calibration value for chamber wise gain factor
796 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
798 // Detector wise calibration object for the noise
799 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
800 // Calibration object with pad wise values for the noise
801 fCalNoiseROC = calibration->GetNoiseROC(fDet);
802 // Calibration value for chamber wise noise
803 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
805 // Calibration object with the pad status
806 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
808 SetBit(kLUT, fReconstructor->UseLUT());
809 SetBit(kGAUS, fReconstructor->UseGAUS());
810 SetBit(kHLT, fReconstructor->IsHLT());
812 firstClusterROC = -1;
815 // Apply the gain and the tail cancelation via digital filter
816 if(fReconstructor->UseTailCancelation()) TailCancelation();
818 MaxStruct curr, last;
819 Int_t nMaximas = 0, nCorrupted = 0;
821 // Here the clusterfining is happening
823 for(curr.Time = 0; curr.Time < fTimeTotal; curr.Time++){
824 while(fIndexes->NextRCIndex(curr.Row, curr.Col)){
825 //printf("\nCHECK r[%2d] c[%3d] t[%d]\n", curr.Row, curr.Col, curr.Time);
826 if(IsMaximum(curr, curr.padStatus, &curr.Signals[0])){
827 //printf("\tMAX s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
829 if(curr.Time==last.Time && curr.Row==last.Row && curr.Col==last.Col+2) FivePadCluster(last, curr);
832 last=curr; curr.FivePad=kFALSE;
834 //printf("\t--- s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
837 if(last.Row>-1) CreateCluster(last);
839 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kClusterizer) > 2){
840 (*fDebugStream) << "MakeClusters"
841 << "Detector=" << det
842 << "NMaxima=" << nMaximas
843 << "NClusters=" << fClusterROC
844 << "NCorrupted=" << nCorrupted
847 if (TestBit(kLabels)) AddLabels();
853 //_____________________________________________________________________________
854 Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Short_t *const Signals)
857 // Returns true if this row,col,time combination is a maximum.
858 // Gives back the padStatus and the signals of the center pad and the two neighbouring pads.
861 Signals[1] = fDigits->GetData(Max.Row, Max.Col, Max.Time);
862 if(Signals[1] < fMaxThresh) return kFALSE;
864 Float_t noiseMiddleThresh = fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.Col, Max.Row);
865 if (Signals[1] < noiseMiddleThresh) return kFALSE;
867 if (Max.Col + 1 >= fColMax || Max.Col < 1) return kFALSE;
870 fCalPadStatusROC->GetStatus(Max.Col-1, Max.Row)
871 ,fCalPadStatusROC->GetStatus(Max.Col, Max.Row)
872 ,fCalPadStatusROC->GetStatus(Max.Col+1, Max.Row)
875 Signals[0] = fDigits->GetData(Max.Row, Max.Col-1, Max.Time);
876 Signals[2] = fDigits->GetData(Max.Row, Max.Col+1, Max.Time);
878 if(!(status[0] | status[1] | status[2])) {//all pads are good
879 if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) {
880 if ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh)) {
881 Float_t noiseSumThresh = fMinLeftRightCutSigma
883 * fCalNoiseROC->GetValue(Max.Col, Max.Row);
884 if ((Signals[2]+Signals[0]+Signals[1]) < noiseSumThresh) return kFALSE;
889 } else { // at least one of the pads is bad, and reject candidates with more than 1 problematic pad
890 if (status[2] && (!(status[0] || status[1])) && Signals[1] > Signals[0] && Signals[0] >= fSigThresh) {
892 SetPadStatus(status[2], padStatus);
895 else if (status[0] && (!(status[1] || status[2])) && Signals[1] >= Signals[2] && Signals[2] >= fSigThresh) {
897 SetPadStatus(status[0], padStatus);
900 else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh))) {
901 Signals[1]=TMath::Nint(fMaxThresh);
902 SetPadStatus(status[1], padStatus);
909 //_____________________________________________________________________________
910 Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
913 // Look for 5 pad cluster with minimum in the middle
914 // Gives back the ratio
916 if (ThisMax.Col >= fColMax - 3) return kFALSE;
917 if (ThisMax.Col < fColMax - 5){
918 if (fDigits->GetData(ThisMax.Row, ThisMax.Col+4, ThisMax.Time) >= fSigThresh)
921 if (ThisMax.Col > 1) {
922 if (fDigits->GetData(ThisMax.Row, ThisMax.Col-2, ThisMax.Time) >= fSigThresh)
926 const Float_t kEpsilon = 0.01;
927 Double_t padSignal[5] = {ThisMax.Signals[0], ThisMax.Signals[1], ThisMax.Signals[2],
928 NeighbourMax.Signals[1], NeighbourMax.Signals[2]};
930 // Unfold the two maxima and set the signal on
931 // the overlapping pad to the ratio
932 Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
933 ThisMax.Signals[2] = TMath::Nint(ThisMax.Signals[2]*ratio);
934 NeighbourMax.Signals[0] = TMath::Nint(NeighbourMax.Signals[0]*(1-ratio));
935 ThisMax.FivePad=kTRUE;
936 NeighbourMax.FivePad=kTRUE;
941 //_____________________________________________________________________________
942 void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
945 // Creates a cluster at the given position and saves it in fRecPoints
949 Short_t signals[7] = { 0, 0, Max.Signals[0], Max.Signals[1], Max.Signals[2], 0, 0 };
950 if(!TestBit(kHLT)) CalcAdditionalInfo(Max, signals, nPadCount);
952 AliTRDcluster cluster(fDet, ((UChar_t) Max.Col), ((UChar_t) Max.Row), ((UChar_t) Max.Time), signals, fVolid);
953 cluster.SetNPads(nPadCount);
954 if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
955 else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
956 else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
958 cluster.SetFivePad(Max.FivePad);
959 // set pads status for the cluster
960 UChar_t maskPosition = GetCorruption(Max.padStatus);
962 cluster.SetPadMaskedPosition(maskPosition);
963 cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
966 // Transform the local cluster coordinates into calibrated
967 // space point positions defined in the local tracking system.
968 // Here the calibration for T0, Vdrift and ExB is applied as well.
969 if(!fTransform->Transform(&cluster)) return;
970 // Temporarily store the Max.Row, column and time bin of the center pad
971 // Used to later on assign the track indices
972 cluster.SetLabel(Max.Row, 0);
973 cluster.SetLabel(Max.Col, 1);
974 cluster.SetLabel(Max.Time,2);
976 //needed for HLT reconstruction
977 AddClusterToArray(&cluster);
979 // Store the index of the first cluster in the current ROC
980 if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
986 //_____________________________________________________________________________
987 void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
991 while (fDigits->GetData(Max.Row, Max.Col-ii, Max.Time) >= fSigThresh) {
994 if (Max.Col < ii) break;
998 while (fDigits->GetData(Max.Row, Max.Col+ii, Max.Time) >= fSigThresh) {
1001 if (Max.Col+ii >= fColMax) break;
1004 // Store the amplitudes of the pads in the cluster for later analysis
1005 // and check whether one of these pads is masked in the database
1006 signals[2]=Max.Signals[0];
1007 signals[3]=Max.Signals[1];
1008 signals[4]=Max.Signals[2];
1009 for(Int_t i = 0; i<2; i++)
1012 signals[i] = fDigits->GetData(Max.Row, Max.Col-3+i, Max.Time);
1013 if(Max.Col+3-i < fColMax)
1014 signals[6-i] = fDigits->GetData(Max.Row, Max.Col+3-i, Max.Time);
1016 /*for (Int_t jPad = Max.Col-3; jPad <= Max.Col+3; jPad++) {
1017 if ((jPad >= 0) && (jPad < fColMax))
1018 signals[jPad-Max.Col+3] = TMath::Nint(fDigits->GetData(Max.Row,jPad,Max.Time));
1022 //_____________________________________________________________________________
1023 void AliTRDclusterizer::AddClusterToArray(AliTRDcluster* cluster)
1026 // Add a cluster to the array
1029 Int_t n = RecPoints()->GetEntriesFast();
1030 if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
1031 new((*RecPoints())[n]) AliTRDcluster(*cluster);
1034 //_____________________________________________________________________________
1035 void AliTRDclusterizer::AddTrackletsToArray()
1038 // Add the online tracklets of this chamber to the array
1041 UInt_t* trackletword;
1042 for(Int_t side=0; side<2; side++)
1045 trackletword=fTrackletContainer[side];
1046 while(trackletword[trkl]>0){
1047 Int_t n = TrackletsArray()->GetEntriesFast();
1048 AliTRDtrackletWord tmp(trackletword[trkl]);
1049 new((*TrackletsArray())[n]) AliTRDcluster(&tmp,fDet,fVolid);
1055 //_____________________________________________________________________________
1056 Bool_t AliTRDclusterizer::AddLabels()
1059 // Add the track indices to the found clusters
1062 const Int_t kNclus = 3;
1063 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1064 const Int_t kNtrack = kNdict * kNclus;
1066 Int_t iClusterROC = 0;
1073 // Temporary array to collect the track indices
1074 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1076 // Loop through the dictionary arrays one-by-one
1077 // to keep memory consumption low
1078 AliTRDarrayDictionary *tracksIn = 0; //mod
1079 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1081 // tracksIn should be expanded beforehand!
1082 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1084 // Loop though the clusters found in this ROC
1085 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1087 AliTRDcluster *cluster = (AliTRDcluster *)
1088 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1089 row = cluster->GetLabel(0);
1090 col = cluster->GetLabel(1);
1091 time = cluster->GetLabel(2);
1093 for (iPad = 0; iPad < kNclus; iPad++) {
1094 Int_t iPadCol = col - 1 + iPad;
1095 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1096 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1103 // Copy the track indices into the cluster
1104 // Loop though the clusters found in this ROC
1105 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1107 AliTRDcluster *cluster = (AliTRDcluster *)
1108 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1109 cluster->SetLabel(-9999,0);
1110 cluster->SetLabel(-9999,1);
1111 cluster->SetLabel(-9999,2);
1113 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1117 delete [] idxTracks;
1123 //_____________________________________________________________________________
1124 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, const Double_t *const padSignal) const
1127 // Method to unfold neighbouring maxima.
1128 // The charge ratio on the overlapping pad is calculated
1129 // until there is no more change within the range given by eps.
1130 // The resulting ratio is then returned to the calling method.
1133 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1135 AliError("No AliTRDcalibDB instance available\n");
1140 Int_t itStep = 0; // Count iteration steps
1142 Double_t ratio = 0.5; // Start value for ratio
1143 Double_t prevRatio = 0.0; // Store previous ratio
1145 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1146 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1147 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1149 // Start the iteration
1150 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1155 // Cluster position according to charge ratio
1156 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1157 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1158 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1159 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1161 // Set cluster charge ratio
1162 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1163 Double_t ampLeft = padSignal[1] / newSignal[1];
1164 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1165 Double_t ampRight = padSignal[3] / newSignal[1];
1167 // Apply pad response to parameters
1168 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1169 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1171 // Calculate new overlapping ratio
1172 ratio = TMath::Min((Double_t) 1.0
1173 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1181 //_____________________________________________________________________________
1182 void AliTRDclusterizer::TailCancelation()
1185 // Applies the tail cancelation and gain factors:
1186 // Transform fDigits to fDigits
1193 Double_t *inADC = new Double_t[fTimeTotal]; // ADC data before tail cancellation
1194 Double_t *outADC = new Double_t[fTimeTotal]; // ADC data after tail cancellation
1196 fIndexes->ResetCounters();
1197 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDReconstructor::kClusterizer);
1198 while(fIndexes->NextRCIndex(iRow, iCol))
1200 Float_t fCalGainFactorROCValue = fCalGainFactorROC->GetValue(iCol,iRow);
1201 Double_t gain = fCalGainFactorDetValue
1202 * fCalGainFactorROCValue;
1204 Bool_t corrupted = kFALSE;
1205 for (iTime = 0; iTime < fTimeTotal; iTime++)
1207 // Apply gain gain factor
1208 inADC[iTime] = fDigits->GetData(iRow,iCol,iTime);
1209 if (fCalPadStatusROC->GetStatus(iCol, iRow)) corrupted = kTRUE;
1210 inADC[iTime] /= gain;
1211 outADC[iTime] = inADC[iTime];
1212 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kClusterizer) > 7){
1213 (*fDebugStream) << "TailCancellation"
1217 << "inADC=" << inADC[iTime]
1219 << "outADC=" << outADC[iTime]
1220 << "corrupted=" << corrupted
1226 // Apply the tail cancelation via the digital filter
1227 // (only for non-coorupted pads)
1228 DeConvExp(&inADC[0],&outADC[0],fTimeTotal,fReconstructor->GetRecoParam() ->GetTCnexp());
1231 for(iTime = 0; iTime < fTimeTotal; iTime++)//while (fIndexes->NextTbinIndex(iTime))
1233 // Store the amplitude of the digit if above threshold
1234 if (outADC[iTime] > fADCthresh)
1235 fDigits->SetData(iRow,iCol,iTime,TMath::Nint(outADC[iTime]));
1237 fDigits->SetData(iRow,iCol,iTime,0);
1240 } // while irow icol
1249 //_____________________________________________________________________________
1250 void AliTRDclusterizer::DeConvExp(const Double_t *const source, Double_t *const target
1251 ,const Int_t n, const Int_t nexp)
1254 // Tail cancellation by deconvolution for PASA v4 TRF
1258 Double_t coefficients[2];
1260 // Initialization (coefficient = alpha, rates = lambda)
1266 if (nexp == 1) { // 1 Exponentials
1272 if (nexp == 2) { // 2 Exponentials
1274 fReconstructor->GetTCParams(par);
1275 r1 = par[0];//1.156;
1276 r2 = par[1];//0.130;
1277 c1 = par[2];//0.114;
1278 c2 = par[3];//0.624;
1281 coefficients[0] = c1;
1282 coefficients[1] = c2;
1286 rates[0] = TMath::Exp(-dt/(r1));
1287 rates[1] = TMath::Exp(-dt/(r2));
1292 Double_t reminder[2];
1293 Double_t correction = 0.0;
1294 Double_t result = 0.0;
1296 // Attention: computation order is important
1297 for (k = 0; k < nexp; k++) {
1301 for (i = 0; i < n; i++) {
1303 result = (source[i] - correction); // No rescaling
1306 for (k = 0; k < nexp; k++) {
1307 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1311 for (k = 0; k < nexp; k++) {
1312 correction += reminder[k];
1319 //_____________________________________________________________________________
1320 void AliTRDclusterizer::ResetRecPoints()
1323 // Resets the list of rec points
1327 fRecPoints->Delete();
1332 //_____________________________________________________________________________
1333 TClonesArray *AliTRDclusterizer::RecPoints()
1336 // Returns the list of rec points
1340 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1341 // determine number of clusters which has to be allocated
1342 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1344 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1346 //SetClustersOwner(kTRUE);
1347 AliTRDReconstructor::SetClusters(0x0);
1353 //_____________________________________________________________________________
1354 TClonesArray *AliTRDclusterizer::TrackletsArray()
1357 // Returns the list of rec points
1360 if (!fTracklets && fReconstructor->IsProcessingTracklets()) {
1361 fTracklets = new TClonesArray("AliTRDcluster", 2*MAX_TRACKLETS_PERHC);
1362 //SetClustersOwner(kTRUE);
1363 //AliTRDReconstructor::SetTracklets(0x0);