1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // TRD cluster finder //
22 ///////////////////////////////////////////////////////////////////////////////
28 #include <TClonesArray.h>
29 #include <TObjArray.h>
31 #include "AliRunLoader.h"
32 #include "AliLoader.h"
33 #include "AliRawReader.h"
35 #include "AliAlignObj.h"
37 #include "AliTRDclusterizer.h"
38 #include "AliTRDcluster.h"
39 #include "AliTRDReconstructor.h"
40 #include "AliTRDgeometry.h"
41 #include "AliTRDarrayDictionary.h"
42 #include "AliTRDarrayADC.h"
43 #include "AliTRDdigitsManager.h"
44 #include "AliTRDrawData.h"
45 #include "AliTRDcalibDB.h"
46 #include "AliTRDrecoParam.h"
47 #include "AliTRDCommonParam.h"
48 #include "AliTRDtransform.h"
49 #include "AliTRDSignalIndex.h"
50 #include "AliTRDrawStreamBase.h"
51 #include "AliTRDfeeParam.h"
52 #include "AliTRDtrackletWord.h"
54 #include "TTreeStream.h"
56 #include "Cal/AliTRDCalROC.h"
57 #include "Cal/AliTRDCalDet.h"
58 #include "Cal/AliTRDCalSingleChamberStatus.h"
60 ClassImp(AliTRDclusterizer)
62 //_____________________________________________________________________________
63 AliTRDclusterizer::AliTRDclusterizer(const AliTRDReconstructor *const rec)
71 ,fDigitsManager(new AliTRDdigitsManager())
72 ,fTrackletContainer(NULL)
74 ,fTransform(new AliTRDtransform(0))
81 ,fMinLeftRightCutSigma(0)
87 ,fCalGainFactorROC(NULL)
88 ,fCalGainFactorDetValue(0)
91 ,fCalPadStatusROC(NULL)
97 // AliTRDclusterizer default constructor
100 SetBit(kLabels, kTRUE);
102 AliTRDcalibDB *trd = 0x0;
103 if (!(trd = AliTRDcalibDB::Instance())) {
104 AliFatal("Could not get calibration object");
107 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
109 // Initialize debug stream
111 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kClusterizer) > 1){
112 TDirectory *savedir = gDirectory;
113 //fgGetDebugStream = new TTreeSRedirector("TRD.ClusterizerDebug.root");
120 //_____________________________________________________________________________
121 AliTRDclusterizer::AliTRDclusterizer(const Text_t *name, const Text_t *title, const AliTRDReconstructor *const rec)
129 ,fDigitsManager(new AliTRDdigitsManager())
130 ,fTrackletContainer(NULL)
132 ,fTransform(new AliTRDtransform(0))
139 ,fMinLeftRightCutSigma(0)
145 ,fCalGainFactorROC(NULL)
146 ,fCalGainFactorDetValue(0)
148 ,fCalNoiseDetValue(0)
149 ,fCalPadStatusROC(NULL)
155 // AliTRDclusterizer constructor
158 SetBit(kLabels, kTRUE);
160 AliTRDcalibDB *trd = 0x0;
161 if (!(trd = AliTRDcalibDB::Instance())) {
162 AliFatal("Could not get calibration object");
165 fDigitsManager->CreateArrays();
167 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
173 //_____________________________________________________________________________
174 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
176 ,fReconstructor(c.fReconstructor)
182 ,fDigitsManager(NULL)
183 ,fTrackletContainer(NULL)
192 ,fMinLeftRightCutSigma(0)
198 ,fCalGainFactorROC(NULL)
199 ,fCalGainFactorDetValue(0)
201 ,fCalNoiseDetValue(0)
202 ,fCalPadStatusROC(NULL)
208 // AliTRDclusterizer copy constructor
211 SetBit(kLabels, kTRUE);
217 //_____________________________________________________________________________
218 AliTRDclusterizer::~AliTRDclusterizer()
221 // AliTRDclusterizer destructor
224 if (fRecPoints/* && IsClustersOwner()*/){
225 fRecPoints->Delete();
230 fTracklets->Delete();
234 if (fDigitsManager) {
235 delete fDigitsManager;
236 fDigitsManager = NULL;
239 if (fTrackletContainer){
240 delete fTrackletContainer;
241 fTrackletContainer = NULL;
251 //_____________________________________________________________________________
252 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
255 // Assignment operator
260 ((AliTRDclusterizer &) c).Copy(*this);
267 //_____________________________________________________________________________
268 void AliTRDclusterizer::Copy(TObject &c) const
274 ((AliTRDclusterizer &) c).fClusterTree = NULL;
275 ((AliTRDclusterizer &) c).fRecPoints = NULL;
276 ((AliTRDclusterizer &) c).fTrackletTree = NULL;
277 ((AliTRDclusterizer &) c).fDigitsManager = NULL;
278 ((AliTRDclusterizer &) c).fTrackletContainer = NULL;
279 ((AliTRDclusterizer &) c).fRawVersion = fRawVersion;
280 ((AliTRDclusterizer &) c).fTransform = NULL;
281 ((AliTRDclusterizer &) c).fDigits = NULL;
282 ((AliTRDclusterizer &) c).fIndexes = NULL;
283 ((AliTRDclusterizer &) c).fADCthresh = 0;
284 ((AliTRDclusterizer &) c).fMaxThresh = 0;
285 ((AliTRDclusterizer &) c).fSigThresh = 0;
286 ((AliTRDclusterizer &) c).fMinMaxCutSigma= 0;
287 ((AliTRDclusterizer &) c).fMinLeftRightCutSigma = 0;
288 ((AliTRDclusterizer &) c).fLayer = 0;
289 ((AliTRDclusterizer &) c).fDet = 0;
290 ((AliTRDclusterizer &) c).fVolid = 0;
291 ((AliTRDclusterizer &) c).fColMax = 0;
292 ((AliTRDclusterizer &) c).fTimeTotal = 0;
293 ((AliTRDclusterizer &) c).fCalGainFactorROC = NULL;
294 ((AliTRDclusterizer &) c).fCalGainFactorDetValue = 0;
295 ((AliTRDclusterizer &) c).fCalNoiseROC = NULL;
296 ((AliTRDclusterizer &) c).fCalNoiseDetValue = 0;
297 ((AliTRDclusterizer &) c).fCalPadStatusROC = NULL;
298 ((AliTRDclusterizer &) c).fClusterROC = 0;
299 ((AliTRDclusterizer &) c).firstClusterROC= 0;
300 ((AliTRDclusterizer &) c).fNoOfClusters = 0;
303 //_____________________________________________________________________________
304 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
307 // Opens the AliROOT file. Output and input are in the same file
310 TString evfoldname = AliConfig::GetDefaultEventFolderName();
311 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
314 fRunLoader = AliRunLoader::Open(name);
318 AliError(Form("Can not open session for file %s.",name));
329 //_____________________________________________________________________________
330 Bool_t AliTRDclusterizer::OpenOutput()
333 // Open the output file
336 if (!fReconstructor->IsWritingClusters()) return kTRUE;
338 TObjArray *ioArray = 0x0;
340 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
341 loader->MakeTree("R");
343 fClusterTree = loader->TreeR();
344 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
350 //_____________________________________________________________________________
351 Bool_t AliTRDclusterizer::OpenOutput(TTree *clusterTree)
354 // Connect the output tree
358 if (fReconstructor->IsWritingClusters()){
359 TObjArray *ioArray = 0x0;
360 fClusterTree = clusterTree;
361 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
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);
385 fTrackletTree = dl->Tree();
389 fTrackletTree = dl->Tree();
391 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
393 fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
401 //_____________________________________________________________________________
402 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
405 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
408 // Import the Trees for the event nEvent in the file
409 fRunLoader->GetEvent(nEvent);
415 //_____________________________________________________________________________
416 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
419 // Fills TRDcluster branch in the tree with the clusters
420 // found in detector = det. For det=-1 writes the tree.
424 (det >= AliTRDgeometry::Ndet())) {
425 AliError(Form("Unexpected detector index %d.\n",det));
429 TObjArray *ioArray = new TObjArray(400);
430 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
432 branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
433 } else branch->SetAddress(&ioArray);
435 Int_t nRecPoints = RecPoints()->GetEntriesFast();
437 for (Int_t i = 0; i < nRecPoints; i++) {
438 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
439 if(det != c->GetDetector()) continue;
442 fClusterTree->Fill();
446 for (Int_t i = 0; i < nRecPoints; i++) {
447 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
448 if(c->GetDetector() != detOld){
449 fClusterTree->Fill();
451 detOld = c->GetDetector();
462 //_____________________________________________________________________________
463 Bool_t AliTRDclusterizer::WriteTracklets(Int_t det)
466 // Write the raw data tracklets into seperate file
469 UInt_t **leaves = new UInt_t *[2];
470 for (Int_t i=0; i<2 ;i++){
471 leaves[i] = new UInt_t[258];
472 leaves[i][0] = det; // det
473 leaves[i][1] = i; // side
474 memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
478 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
480 fTrackletTree = dl->Tree();
483 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
485 trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
488 for (Int_t i=0; i<2; i++){
489 if (leaves[i][2]>0) {
490 trkbranch->SetAddress(leaves[i]);
491 fTrackletTree->Fill();
495 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
496 dl->WriteData("OVERWRITE");
504 //_____________________________________________________________________________
505 Bool_t AliTRDclusterizer::ReadDigits()
508 // Reads the digits arrays from the input aliroot file
512 AliError("No run loader available");
516 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
517 if (!loader->TreeD()) {
518 loader->LoadDigits();
521 // Read in the digit arrays
522 return (fDigitsManager->ReadDigits(loader->TreeD()));
526 //_____________________________________________________________________________
527 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
530 // Reads the digits arrays from the input tree
533 // Read in the digit arrays
534 return (fDigitsManager->ReadDigits(digitsTree));
538 //_____________________________________________________________________________
539 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
542 // Reads the digits arrays from the ddl file
546 fDigitsManager = raw.Raw2Digits(rawReader);
552 //_____________________________________________________________________________
553 Bool_t AliTRDclusterizer::MakeClusters()
556 // Creates clusters from digits
559 // Propagate info from the digits manager
560 if (TestBit(kLabels)){
561 SetBit(kLabels, fDigitsManager->UsesDictionaries());
564 Bool_t fReturn = kTRUE;
565 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++){
567 AliTRDarrayADC *digitsIn = (AliTRDarrayADC*) fDigitsManager->GetDigits(i); //mod
568 // This is to take care of switched off super modules
569 if (!digitsIn->HasData()) continue;
571 digitsIn->DeleteNegatives(); // Restore digits array to >=0 values
572 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
573 if (indexes->IsAllocated() == kFALSE){
574 fDigitsManager->BuildIndexes(i);
578 if (indexes->HasEntry()){
579 if (TestBit(kLabels)){
580 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++){
581 AliTRDarrayDictionary *tracksIn = 0; //mod
582 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(i,iDict); //mod
586 fR = MakeClusters(i);
587 fReturn = fR && fReturn;
591 // if(IsWritingClusters()) WriteClusters(i);
595 // No compress just remove
596 fDigitsManager->RemoveDigits(i);
597 fDigitsManager->RemoveDictionaries(i);
598 fDigitsManager->ClearIndexes(i);
601 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
603 AliInfo(Form("Number of found clusters : %d", RecPoints()->GetEntriesFast()));
609 //_____________________________________________________________________________
610 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
613 // Creates clusters from raw data
616 return Raw2ClustersChamber(rawReader);
620 //_____________________________________________________________________________
621 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
624 // Creates clusters from raw data
627 // Create the digits manager
628 if (!fDigitsManager){
629 fDigitsManager = new AliTRDdigitsManager(kTRUE);
630 fDigitsManager->CreateArrays();
633 fDigitsManager->SetUseDictionaries(TestBit(kLabels));
635 // tracklet container for raw tracklet writing
636 if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
637 // maximum tracklets for one HC
638 const Int_t kTrackletChmb=256;
639 fTrackletContainer = new UInt_t *[2];
640 fTrackletContainer[0] = new UInt_t[kTrackletChmb];
641 fTrackletContainer[1] = new UInt_t[kTrackletChmb];
644 AliTRDrawStreamBase *input = AliTRDrawStreamBase::GetRawStream(rawReader);
646 AliInfo(Form("Stream version: %s", input->IsA()->GetName()));
649 while ((det = input->NextChamber(fDigitsManager,fTrackletContainer)) >= 0){
650 Bool_t iclusterBranch = kFALSE;
651 if (fDigitsManager->GetIndexes(det)->HasEntry()){
652 iclusterBranch = MakeClusters(det);
655 fDigitsManager->ResetArrays(det);
657 if (!fReconstructor->IsWritingTracklets()) continue;
658 if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
661 if (fTrackletContainer){
662 delete [] fTrackletContainer[0];
663 delete [] fTrackletContainer[1];
664 delete [] fTrackletContainer;
665 fTrackletContainer = NULL;
668 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
670 delete fDigitsManager;
671 fDigitsManager = NULL;
676 AliInfo(Form("Number of found clusters : %d", fNoOfClusters));
681 //_____________________________________________________________________________
682 UChar_t AliTRDclusterizer::GetStatus(Short_t &signal)
685 // Check if a pad is masked
690 if(signal>0 && TESTBIT(signal, 10)){
692 for(int ibit=0; ibit<4; ibit++){
693 if(TESTBIT(signal, 11+ibit)){
694 SETBIT(status, ibit);
695 CLRBIT(signal, 11+ibit);
702 //_____________________________________________________________________________
703 void AliTRDclusterizer::SetPadStatus(const UChar_t status, UChar_t &out){
705 // Set the pad status into out
706 // First three bits are needed for the position encoding
711 //_____________________________________________________________________________
712 UChar_t AliTRDclusterizer::GetPadStatus(UChar_t encoding) const {
714 // return the staus encoding of the corrupted pad
716 return static_cast<UChar_t>(encoding >> 3);
719 //_____________________________________________________________________________
720 Int_t AliTRDclusterizer::GetCorruption(UChar_t encoding) const {
722 // Return the position of the corruption
727 //_____________________________________________________________________________
728 Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
731 // Generates the cluster.
735 // digits should be expanded beforehand!
736 // digitsIn->Expand();
737 fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
739 // This is to take care of switched off super modules
740 if (!fDigits->HasData()) return kFALSE;
742 fIndexes = fDigitsManager->GetIndexes(det);
743 if (fIndexes->IsAllocated() == kFALSE) {
744 AliError("Indexes do not exist!");
748 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
750 AliFatal("No AliTRDcalibDB instance available\n");
756 if (!fReconstructor){
757 AliError("Reconstructor not set\n");
761 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDReconstructor::kClusterizer);
763 fMaxThresh = fReconstructor->GetRecoParam()->GetClusMaxThresh();
764 fSigThresh = fReconstructor->GetRecoParam()->GetClusSigThresh();
765 fMinMaxCutSigma = fReconstructor->GetRecoParam()->GetMinMaxCutSigma();
766 fMinLeftRightCutSigma = fReconstructor->GetRecoParam()->GetMinLeftRightCutSigma();
768 Int_t istack = fIndexes->GetStack();
769 fLayer = fIndexes->GetLayer();
770 Int_t isector = fIndexes->GetSM();
772 // Start clustering in the chamber
774 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
776 AliError("Strange Detector number Missmatch!");
780 // TRD space point transformation
781 fTransform->SetDetector(det);
783 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
784 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
785 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
787 if(fReconstructor->IsProcessingTracklets() && fTrackletContainer)
788 AddTrackletsToArray();
790 fColMax = fDigits->GetNcol();
791 //Int_t nRowMax = fDigits->GetNrow();
792 fTimeTotal = fDigits->GetNtime();
794 // Detector wise calibration object for the gain factors
795 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
796 // Calibration object with pad wise values for the gain factors
797 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
798 // Calibration value for chamber wise gain factor
799 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
801 // Detector wise calibration object for the noise
802 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
803 // Calibration object with pad wise values for the noise
804 fCalNoiseROC = calibration->GetNoiseROC(fDet);
805 // Calibration value for chamber wise noise
806 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
808 // Calibration object with the pad status
809 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
811 SetBit(kLUT, fReconstructor->UseLUT());
812 SetBit(kGAUS, fReconstructor->UseGAUS());
813 SetBit(kHLT, fReconstructor->IsHLT());
815 firstClusterROC = -1;
818 // Apply the gain and the tail cancelation via digital filter
819 if(fReconstructor->UseTailCancelation()) TailCancelation();
821 MaxStruct curr, last;
822 Int_t nMaximas = 0, nCorrupted = 0;
824 // Here the clusterfining is happening
826 for(curr.Time = 0; curr.Time < fTimeTotal; curr.Time++){
827 while(fIndexes->NextRCIndex(curr.Row, curr.Col)){
828 //printf("\nCHECK r[%2d] c[%3d] t[%d]\n", curr.Row, curr.Col, curr.Time);
829 if(IsMaximum(curr, curr.padStatus, &curr.Signals[0])){
830 //printf("\tMAX s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
832 if(curr.Time==last.Time && curr.Row==last.Row && curr.Col==last.Col+2) FivePadCluster(last, curr);
835 last=curr; curr.FivePad=kFALSE;
837 //printf("\t--- s[%d %d %d]\n", curr.Signals[0], curr.Signals[1], curr.Signals[2]);
840 if(last.Row>-1) CreateCluster(last);
842 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kClusterizer) > 2){
843 (*fDebugStream) << "MakeClusters"
844 << "Detector=" << det
845 << "NMaxima=" << nMaximas
846 << "NClusters=" << fClusterROC
847 << "NCorrupted=" << nCorrupted
850 if (TestBit(kLabels)) AddLabels();
856 //_____________________________________________________________________________
857 Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Short_t *const Signals)
860 // Returns true if this row,col,time combination is a maximum.
861 // Gives back the padStatus and the signals of the center pad and the two neighbouring pads.
864 Signals[1] = fDigits->GetData(Max.Row, Max.Col, Max.Time);
865 if(Signals[1] < fMaxThresh) return kFALSE;
867 Float_t noiseMiddleThresh = fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.Col, Max.Row);
868 if (Signals[1] < noiseMiddleThresh) return kFALSE;
870 if (Max.Col + 1 >= fColMax || Max.Col < 1) return kFALSE;
873 fCalPadStatusROC->GetStatus(Max.Col-1, Max.Row)
874 ,fCalPadStatusROC->GetStatus(Max.Col, Max.Row)
875 ,fCalPadStatusROC->GetStatus(Max.Col+1, Max.Row)
878 Signals[0] = fDigits->GetData(Max.Row, Max.Col-1, Max.Time);
879 Signals[2] = fDigits->GetData(Max.Row, Max.Col+1, Max.Time);
881 if(!(status[0] | status[1] | status[2])) {//all pads are good
882 if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) {
883 if ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh)) {
884 Float_t noiseSumThresh = fMinLeftRightCutSigma
886 * fCalNoiseROC->GetValue(Max.Col, Max.Row);
887 if ((Signals[2]+Signals[0]+Signals[1]) < noiseSumThresh) return kFALSE;
892 } else { // at least one of the pads is bad, and reject candidates with more than 1 problematic pad
893 if (status[2] && (!(status[0] || status[1])) && Signals[1] > Signals[0] && Signals[0] >= fSigThresh) {
895 SetPadStatus(status[2], padStatus);
898 else if (status[0] && (!(status[1] || status[2])) && Signals[1] >= Signals[2] && Signals[2] >= fSigThresh) {
900 SetPadStatus(status[0], padStatus);
903 else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] >= fSigThresh) || (Signals[0] >= fSigThresh))) {
904 Signals[1]=TMath::Nint(fMaxThresh);
905 SetPadStatus(status[1], padStatus);
912 //_____________________________________________________________________________
913 Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
916 // Look for 5 pad cluster with minimum in the middle
917 // Gives back the ratio
919 if (ThisMax.Col >= fColMax - 3) return kFALSE;
920 if (ThisMax.Col < fColMax - 5){
921 if (fDigits->GetData(ThisMax.Row, ThisMax.Col+4, ThisMax.Time) >= fSigThresh)
924 if (ThisMax.Col > 1) {
925 if (fDigits->GetData(ThisMax.Row, ThisMax.Col-2, ThisMax.Time) >= fSigThresh)
929 const Float_t kEpsilon = 0.01;
930 Double_t padSignal[5] = {ThisMax.Signals[0], ThisMax.Signals[1], ThisMax.Signals[2],
931 NeighbourMax.Signals[1], NeighbourMax.Signals[2]};
933 // Unfold the two maxima and set the signal on
934 // the overlapping pad to the ratio
935 Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
936 ThisMax.Signals[2] = TMath::Nint(ThisMax.Signals[2]*ratio);
937 NeighbourMax.Signals[0] = TMath::Nint(NeighbourMax.Signals[0]*(1-ratio));
938 ThisMax.FivePad=kTRUE;
939 NeighbourMax.FivePad=kTRUE;
944 //_____________________________________________________________________________
945 void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
948 // Creates a cluster at the given position and saves it in fRecPoints
952 Short_t signals[7] = { 0, 0, Max.Signals[0], Max.Signals[1], Max.Signals[2], 0, 0 };
953 if(!TestBit(kHLT)) CalcAdditionalInfo(Max, signals, nPadCount);
955 AliTRDcluster cluster(fDet, ((UChar_t) Max.Col), ((UChar_t) Max.Row), ((UChar_t) Max.Time), signals, fVolid);
956 cluster.SetNPads(nPadCount);
957 if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
958 else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
959 else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
961 cluster.SetFivePad(Max.FivePad);
962 // set pads status for the cluster
963 UChar_t maskPosition = GetCorruption(Max.padStatus);
965 cluster.SetPadMaskedPosition(maskPosition);
966 cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
969 // Transform the local cluster coordinates into calibrated
970 // space point positions defined in the local tracking system.
971 // Here the calibration for T0, Vdrift and ExB is applied as well.
972 if(!fTransform->Transform(&cluster)) return;
973 // Temporarily store the Max.Row, column and time bin of the center pad
974 // Used to later on assign the track indices
975 cluster.SetLabel(Max.Row, 0);
976 cluster.SetLabel(Max.Col, 1);
977 cluster.SetLabel(Max.Time,2);
979 //needed for HLT reconstruction
980 AddClusterToArray(&cluster);
982 // Store the index of the first cluster in the current ROC
983 if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
989 //_____________________________________________________________________________
990 void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
994 while (fDigits->GetData(Max.Row, Max.Col-ii, Max.Time) >= fSigThresh) {
997 if (Max.Col < ii) break;
1001 while (fDigits->GetData(Max.Row, Max.Col+ii, Max.Time) >= fSigThresh) {
1004 if (Max.Col+ii >= fColMax) break;
1007 // Store the amplitudes of the pads in the cluster for later analysis
1008 // and check whether one of these pads is masked in the database
1009 signals[2]=Max.Signals[0];
1010 signals[3]=Max.Signals[1];
1011 signals[4]=Max.Signals[2];
1012 for(Int_t i = 0; i<2; i++)
1015 signals[i] = fDigits->GetData(Max.Row, Max.Col-3+i, Max.Time);
1016 if(Max.Col+3-i < fColMax)
1017 signals[6-i] = fDigits->GetData(Max.Row, Max.Col+3-i, Max.Time);
1019 /*for (Int_t jPad = Max.Col-3; jPad <= Max.Col+3; jPad++) {
1020 if ((jPad >= 0) && (jPad < fColMax))
1021 signals[jPad-Max.Col+3] = TMath::Nint(fDigits->GetData(Max.Row,jPad,Max.Time));
1025 //_____________________________________________________________________________
1026 void AliTRDclusterizer::AddClusterToArray(AliTRDcluster *cluster)
1029 // Add a cluster to the array
1032 Int_t n = RecPoints()->GetEntriesFast();
1033 if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
1034 new((*RecPoints())[n]) AliTRDcluster(*cluster);
1037 //_____________________________________________________________________________
1038 void AliTRDclusterizer::AddTrackletsToArray()
1041 // Add the online tracklets of this chamber to the array
1044 UInt_t* trackletword;
1045 for(Int_t side=0; side<2; side++)
1048 trackletword=fTrackletContainer[side];
1050 Int_t n = TrackletsArray()->GetEntriesFast();
1051 AliTRDtrackletWord tmp(trackletword[trkl]);
1052 new((*TrackletsArray())[n]) AliTRDcluster(&tmp,fDet,fVolid);
1054 }while(trackletword[trkl]>0);
1058 //_____________________________________________________________________________
1059 Bool_t AliTRDclusterizer::AddLabels()
1062 // Add the track indices to the found clusters
1065 const Int_t kNclus = 3;
1066 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1067 const Int_t kNtrack = kNdict * kNclus;
1069 Int_t iClusterROC = 0;
1076 // Temporary array to collect the track indices
1077 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1079 // Loop through the dictionary arrays one-by-one
1080 // to keep memory consumption low
1081 AliTRDarrayDictionary *tracksIn = 0; //mod
1082 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1084 // tracksIn should be expanded beforehand!
1085 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1087 // Loop though the clusters found in this ROC
1088 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1090 AliTRDcluster *cluster = (AliTRDcluster *)
1091 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1092 row = cluster->GetLabel(0);
1093 col = cluster->GetLabel(1);
1094 time = cluster->GetLabel(2);
1096 for (iPad = 0; iPad < kNclus; iPad++) {
1097 Int_t iPadCol = col - 1 + iPad;
1098 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1099 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1106 // Copy the track indices into the cluster
1107 // Loop though the clusters found in this ROC
1108 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1110 AliTRDcluster *cluster = (AliTRDcluster *)
1111 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1112 cluster->SetLabel(-9999,0);
1113 cluster->SetLabel(-9999,1);
1114 cluster->SetLabel(-9999,2);
1116 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1120 delete [] idxTracks;
1126 //_____________________________________________________________________________
1127 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, Double_t *padSignal) const
1130 // Method to unfold neighbouring maxima.
1131 // The charge ratio on the overlapping pad is calculated
1132 // until there is no more change within the range given by eps.
1133 // The resulting ratio is then returned to the calling method.
1136 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1138 AliError("No AliTRDcalibDB instance available\n");
1143 Int_t itStep = 0; // Count iteration steps
1145 Double_t ratio = 0.5; // Start value for ratio
1146 Double_t prevRatio = 0.0; // Store previous ratio
1148 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1149 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1150 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1152 // Start the iteration
1153 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1158 // Cluster position according to charge ratio
1159 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1160 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1161 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1162 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1164 // Set cluster charge ratio
1165 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1166 Double_t ampLeft = padSignal[1] / newSignal[1];
1167 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1168 Double_t ampRight = padSignal[3] / newSignal[1];
1170 // Apply pad response to parameters
1171 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1172 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1174 // Calculate new overlapping ratio
1175 ratio = TMath::Min((Double_t) 1.0
1176 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1184 //_____________________________________________________________________________
1185 void AliTRDclusterizer::TailCancelation()
1188 // Applies the tail cancelation and gain factors:
1189 // Transform fDigits to fDigits
1196 Double_t *inADC = new Double_t[fTimeTotal]; // ADC data before tail cancellation
1197 Double_t *outADC = new Double_t[fTimeTotal]; // ADC data after tail cancellation
1199 fIndexes->ResetCounters();
1200 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDReconstructor::kClusterizer);
1201 while(fIndexes->NextRCIndex(iRow, iCol))
1203 Float_t fCalGainFactorROCValue = fCalGainFactorROC->GetValue(iCol,iRow);
1204 Double_t gain = fCalGainFactorDetValue
1205 * fCalGainFactorROCValue;
1207 Bool_t corrupted = kFALSE;
1208 for (iTime = 0; iTime < fTimeTotal; iTime++)
1210 // Apply gain gain factor
1211 inADC[iTime] = fDigits->GetData(iRow,iCol,iTime);
1212 if (fCalPadStatusROC->GetStatus(iCol, iRow)) corrupted = kTRUE;
1213 inADC[iTime] /= gain;
1214 outADC[iTime] = inADC[iTime];
1215 if(fReconstructor->GetStreamLevel(AliTRDReconstructor::kClusterizer) > 7){
1216 (*fDebugStream) << "TailCancellation"
1220 << "inADC=" << inADC[iTime]
1222 << "outADC=" << outADC[iTime]
1223 << "corrupted=" << corrupted
1229 // Apply the tail cancelation via the digital filter
1230 // (only for non-coorupted pads)
1231 DeConvExp(&inADC[0],&outADC[0],fTimeTotal,fReconstructor->GetRecoParam() ->GetTCnexp());
1234 for(iTime = 0; iTime < fTimeTotal; iTime++)//while (fIndexes->NextTbinIndex(iTime))
1236 // Store the amplitude of the digit if above threshold
1237 if (outADC[iTime] > fADCthresh)
1238 fDigits->SetData(iRow,iCol,iTime,TMath::Nint(outADC[iTime]));
1240 fDigits->SetData(iRow,iCol,iTime,0);
1243 } // while irow icol
1252 //_____________________________________________________________________________
1253 void AliTRDclusterizer::DeConvExp(const Double_t *const source, Double_t *const target
1254 ,const Int_t n, const Int_t nexp)
1257 // Tail cancellation by deconvolution for PASA v4 TRF
1261 Double_t coefficients[2];
1263 // Initialization (coefficient = alpha, rates = lambda)
1269 if (nexp == 1) { // 1 Exponentials
1275 if (nexp == 2) { // 2 Exponentials
1277 fReconstructor->GetTCParams(par);
1278 r1 = par[0];//1.156;
1279 r2 = par[1];//0.130;
1280 c1 = par[2];//0.114;
1281 c2 = par[3];//0.624;
1284 coefficients[0] = c1;
1285 coefficients[1] = c2;
1289 rates[0] = TMath::Exp(-dt/(r1));
1290 rates[1] = TMath::Exp(-dt/(r2));
1295 Double_t reminder[2];
1296 Double_t correction = 0.0;
1297 Double_t result = 0.0;
1299 // Attention: computation order is important
1300 for (k = 0; k < nexp; k++) {
1304 for (i = 0; i < n; i++) {
1306 result = (source[i] - correction); // No rescaling
1309 for (k = 0; k < nexp; k++) {
1310 reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1314 for (k = 0; k < nexp; k++) {
1315 correction += reminder[k];
1322 //_____________________________________________________________________________
1323 void AliTRDclusterizer::ResetRecPoints()
1326 // Resets the list of rec points
1330 fRecPoints->Delete();
1335 //_____________________________________________________________________________
1336 TClonesArray *AliTRDclusterizer::RecPoints()
1339 // Returns the list of rec points
1343 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1344 // determine number of clusters which has to be allocated
1345 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1347 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1349 //SetClustersOwner(kTRUE);
1350 AliTRDReconstructor::SetClusters(0x0);
1356 //_____________________________________________________________________________
1357 TClonesArray *AliTRDclusterizer::TrackletsArray()
1360 // Returns the list of rec points
1363 if (!fTracklets && fReconstructor->IsProcessingTracklets()) {
1364 fTracklets = new TClonesArray("AliTRDcluster", 2*MAX_TRACKLETS_PERHC);
1365 //SetClustersOwner(kTRUE);
1366 //AliTRDReconstructor::SetTracklets(0x0);