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 "AliTreeLoader.h"
30 #include "AliAlignObj.h"
32 #include "AliTRDclusterizer.h"
33 #include "AliTRDcluster.h"
34 #include "AliTRDReconstructor.h"
35 #include "AliTRDgeometry.h"
36 #include "AliTRDarrayDictionary.h"
37 #include "AliTRDarrayADC.h"
38 #include "AliTRDdigitsManager.h"
39 #include "AliTRDdigitsParam.h"
40 #include "AliTRDrawData.h"
41 #include "AliTRDcalibDB.h"
42 #include "AliTRDtransform.h"
43 #include "AliTRDSignalIndex.h"
44 #include "AliTRDrawStream.h"
45 #include "AliTRDfeeParam.h"
46 #include "AliTRDtrackletWord.h"
48 #include "TTreeStream.h"
50 #include "Cal/AliTRDCalROC.h"
51 #include "Cal/AliTRDCalDet.h"
52 #include "Cal/AliTRDCalSingleChamberStatus.h"
54 ClassImp(AliTRDclusterizer)
56 //_____________________________________________________________________________
57 AliTRDclusterizer::AliTRDclusterizer(const AliTRDReconstructor *const rec)
65 ,fDigitsManager(new AliTRDdigitsManager())
66 ,fTrackletContainer(NULL)
68 ,fTransform(new AliTRDtransform(0))
75 ,fMinLeftRightCutSigma(0)
81 ,fCalGainFactorROC(NULL)
82 ,fCalGainFactorDetValue(0)
85 ,fCalPadStatusROC(NULL)
93 // AliTRDclusterizer default constructor
96 SetBit(kLabels, kTRUE);
97 SetBit(knewDM, kFALSE);
99 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
101 // Initialize debug stream
103 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 1){
104 TDirectory *savedir = gDirectory;
105 //fgGetDebugStream = new TTreeSRedirector("TRD.ClusterizerDebug.root");
112 //_____________________________________________________________________________
113 AliTRDclusterizer::AliTRDclusterizer(const Text_t *name
114 , const Text_t *title
115 , const AliTRDReconstructor *const rec)
123 ,fDigitsManager(new AliTRDdigitsManager())
124 ,fTrackletContainer(NULL)
126 ,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 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)
202 // AliTRDclusterizer copy constructor
205 SetBit(kLabels, kTRUE);
206 SetBit(knewDM, kFALSE);
212 //_____________________________________________________________________________
213 AliTRDclusterizer::~AliTRDclusterizer()
216 // AliTRDclusterizer destructor
219 if (fRecPoints/* && IsClustersOwner()*/){
220 fRecPoints->Delete();
225 fTracklets->Delete();
229 if (fDigitsManager) {
230 delete fDigitsManager;
231 fDigitsManager = NULL;
234 if (fTrackletContainer){
235 delete [] fTrackletContainer[0];
236 delete [] fTrackletContainer[1];
237 delete [] fTrackletContainer;
238 fTrackletContainer = NULL;
253 //_____________________________________________________________________________
254 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
257 // Assignment operator
262 ((AliTRDclusterizer &) c).Copy(*this);
269 //_____________________________________________________________________________
270 void AliTRDclusterizer::Copy(TObject &c) const
276 ((AliTRDclusterizer &) c).fClusterTree = NULL;
277 ((AliTRDclusterizer &) c).fRecPoints = NULL;
278 ((AliTRDclusterizer &) c).fTrackletTree = NULL;
279 ((AliTRDclusterizer &) c).fDigitsManager = NULL;
280 ((AliTRDclusterizer &) c).fTrackletContainer = NULL;
281 ((AliTRDclusterizer &) c).fRawVersion = fRawVersion;
282 ((AliTRDclusterizer &) c).fTransform = NULL;
283 ((AliTRDclusterizer &) c).fDigits = NULL;
284 ((AliTRDclusterizer &) c).fIndexes = NULL;
285 ((AliTRDclusterizer &) c).fMaxThresh = 0;
286 ((AliTRDclusterizer &) c).fMaxThreshTest = 0;
287 ((AliTRDclusterizer &) c).fSigThresh = 0;
288 ((AliTRDclusterizer &) c).fMinMaxCutSigma= 0;
289 ((AliTRDclusterizer &) c).fMinLeftRightCutSigma = 0;
290 ((AliTRDclusterizer &) c).fLayer = 0;
291 ((AliTRDclusterizer &) c).fDet = 0;
292 ((AliTRDclusterizer &) c).fVolid = 0;
293 ((AliTRDclusterizer &) c).fColMax = 0;
294 ((AliTRDclusterizer &) c).fTimeTotal = 0;
295 ((AliTRDclusterizer &) c).fCalGainFactorROC = NULL;
296 ((AliTRDclusterizer &) c).fCalGainFactorDetValue = 0;
297 ((AliTRDclusterizer &) c).fCalNoiseROC = NULL;
298 ((AliTRDclusterizer &) c).fCalNoiseDetValue = 0;
299 ((AliTRDclusterizer &) c).fCalPadStatusROC = NULL;
300 ((AliTRDclusterizer &) c).fClusterROC = 0;
301 ((AliTRDclusterizer &) c).firstClusterROC= 0;
302 ((AliTRDclusterizer &) c).fNoOfClusters = 0;
303 ((AliTRDclusterizer &) c).fBaseline = 0;
304 ((AliTRDclusterizer &) c).fRawStream = NULL;
308 //_____________________________________________________________________________
309 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
312 // Opens the AliROOT file. Output and input are in the same file
315 TString evfoldname = AliConfig::GetDefaultEventFolderName();
316 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
319 fRunLoader = AliRunLoader::Open(name);
323 AliError(Form("Can not open session for file %s.",name));
334 //_____________________________________________________________________________
335 Bool_t AliTRDclusterizer::OpenOutput()
338 // Open the output file
341 if (!fReconstructor->IsWritingClusters()) return kTRUE;
343 TObjArray *ioArray = 0x0;
345 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
346 loader->MakeTree("R");
348 fClusterTree = loader->TreeR();
349 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
355 //_____________________________________________________________________________
356 Bool_t AliTRDclusterizer::OpenOutput(TTree *const clusterTree)
359 // Connect the output tree
363 if (fReconstructor->IsWritingClusters()){
364 TObjArray *ioArray = 0x0;
365 fClusterTree = clusterTree;
366 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
371 //_____________________________________________________________________________
372 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
375 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
378 // Import the Trees for the event nEvent in the file
379 fRunLoader->GetEvent(nEvent);
385 //_____________________________________________________________________________
386 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
389 // Fills TRDcluster branch in the tree with the clusters
390 // found in detector = det. For det=-1 writes the tree.
394 (det >= AliTRDgeometry::Ndet())) {
395 AliError(Form("Unexpected detector index %d.\n",det));
399 TObjArray *ioArray = new TObjArray(400);
400 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
402 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
403 } else branch->SetAddress(&ioArray);
405 Int_t nRecPoints = RecPoints()->GetEntriesFast();
407 for (Int_t i = 0; i < nRecPoints; i++) {
408 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
409 if(det != c->GetDetector()) continue;
412 fClusterTree->Fill();
415 Int_t detOld = -1, nw(0);
416 for (Int_t i = 0; i < nRecPoints; i++) {
417 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
418 if(c->GetDetector() != detOld){
419 nw += ioArray->GetEntriesFast();
420 fClusterTree->Fill();
422 detOld = c->GetDetector();
426 if(ioArray->GetEntriesFast()){
427 nw += ioArray->GetEntriesFast();
428 fClusterTree->Fill();
431 AliDebug(2, Form("Clusters FOUND[%d] WRITTEN[%d] STATUS[%s]", nRecPoints, nw, nw==nRecPoints?"OK":"FAILED"));
438 //_____________________________________________________________________________
439 Bool_t AliTRDclusterizer::WriteTracklets(Int_t det)
442 // Write the raw data tracklets into seperate file
445 UInt_t **leaves = new UInt_t *[2];
446 for (Int_t i=0; i<2 ;i++){
447 leaves[i] = new UInt_t[258];
448 leaves[i][0] = det; // det
449 leaves[i][1] = i; // side
450 memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
454 AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
456 fTrackletTree = dl->Tree();
459 TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
461 trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
464 for (Int_t i=0; i<2; i++){
465 if (leaves[i][2]>0) {
466 trkbranch->SetAddress(leaves[i]);
467 fTrackletTree->Fill();
471 // AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets"); //jkl: wrong here
472 // dl->WriteData("OVERWRITE"); //jkl: wrong here
480 //_____________________________________________________________________________
481 Bool_t AliTRDclusterizer::ReadDigits()
484 // Reads the digits arrays from the input aliroot file
488 AliError("No run loader available");
492 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
493 if (!loader->TreeD()) {
494 loader->LoadDigits();
497 // Read in the digit arrays
498 return (fDigitsManager->ReadDigits(loader->TreeD()));
502 //_____________________________________________________________________________
503 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
506 // Reads the digits arrays from the input tree
509 // Read in the digit arrays
510 return (fDigitsManager->ReadDigits(digitsTree));
514 //_____________________________________________________________________________
515 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
518 // Reads the digits arrays from the ddl file
522 fDigitsManager = raw.Raw2Digits(rawReader);
528 //_____________________________________________________________________________
529 Bool_t AliTRDclusterizer::MakeClusters()
532 // Creates clusters from digits
535 // Propagate info from the digits manager
536 if (TestBit(kLabels)){
537 SetBit(kLabels, fDigitsManager->UsesDictionaries());
540 Bool_t fReturn = kTRUE;
541 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++){
543 AliTRDarrayADC *digitsIn = (AliTRDarrayADC*) fDigitsManager->GetDigits(i); //mod
544 // This is to take care of switched off super modules
545 if (!digitsIn->HasData()) continue;
547 digitsIn->DeleteNegatives(); // Restore digits array to >=0 values
548 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
549 if (indexes->IsAllocated() == kFALSE){
550 fDigitsManager->BuildIndexes(i);
554 if (indexes->HasEntry()){
555 if (TestBit(kLabels)){
556 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++){
557 AliTRDarrayDictionary *tracksIn = 0; //mod
558 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(i,iDict); //mod
562 fR = MakeClusters(i);
563 fReturn = fR && fReturn;
567 // if(IsWritingClusters()) WriteClusters(i);
571 // Clear arrays of this chamber, to prepare for next event
572 fDigitsManager->ClearArrays(i);
575 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
577 AliInfo(Form("Number of found clusters : %d", RecPoints()->GetEntriesFast()));
583 //_____________________________________________________________________________
584 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
587 // Creates clusters from raw data
590 return Raw2ClustersChamber(rawReader);
594 //_____________________________________________________________________________
595 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
598 // Creates clusters from raw data
601 // Create the digits manager
602 if (!fDigitsManager){
603 SetBit(knewDM, kTRUE);
604 fDigitsManager = new AliTRDdigitsManager(kTRUE);
605 fDigitsManager->CreateArrays();
608 fDigitsManager->SetUseDictionaries(TestBit(kLabels));
610 // ----- preparing tracklet output -----
611 if (fReconstructor->IsWritingTracklets()) {
612 AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets");
614 //AliInfo("Could not get the tracklets data loader, adding it now!");
615 trklLoader = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
616 AliRunLoader::Instance()->GetLoader("TRDLoader")->AddDataLoader(trklLoader);
618 AliTreeLoader *trklTreeLoader = dynamic_cast<AliTreeLoader*> (trklLoader->GetBaseLoader("tracklets-raw"));
619 if (!trklTreeLoader) {
620 trklTreeLoader = new AliTreeLoader("tracklets-raw", trklLoader);
621 trklLoader->AddBaseLoader(trklTreeLoader);
623 if (!trklTreeLoader->Tree())
624 trklTreeLoader->MakeTree();
627 // tracklet container for raw tracklet writing
628 if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
629 // maximum tracklets for one HC
630 const Int_t kTrackletChmb=256;
631 fTrackletContainer = new UInt_t *[2];
632 fTrackletContainer[0] = new UInt_t[kTrackletChmb];
633 fTrackletContainer[1] = new UInt_t[kTrackletChmb];
634 memset(fTrackletContainer[0], 0, kTrackletChmb*sizeof(UInt_t)); //jkl
635 memset(fTrackletContainer[1], 0, kTrackletChmb*sizeof(UInt_t)); //jkl
639 fRawStream = new AliTRDrawStream(rawReader);
641 fRawStream->SetReader(rawReader);
643 if(fReconstructor->IsHLT()){
644 if(fRawStream->InheritsFrom(AliTRDrawStream::Class()))
645 ((AliTRDrawStream*)fRawStream)->DisableErrorStorage();
647 fRawStream->SetSharedPadReadout(kFALSE);
648 fRawStream->SetNoErrorWarning();
652 AliDebug(1,Form("Stream version: %s", fRawStream->IsA()->GetName()));
655 while ((det = fRawStream->NextChamber(fDigitsManager,fTrackletContainer)) < AliTRDgeometry::kNdet){
656 if (fDigitsManager->GetIndexes(det)->HasEntry()){
658 fDigitsManager->ClearArrays(det);
661 if (!fReconstructor->IsWritingTracklets()) continue;
662 if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
665 if (fReconstructor->IsWritingTracklets()) {
666 if (AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
668 if (AliTreeLoader *trklTreeLoader = (AliTreeLoader*) trklLoader->GetBaseLoader("tracklets-raw"))
669 trklTreeLoader->WriteData("OVERWRITE");
670 trklLoader->UnloadAll();
675 if (fTrackletContainer){
676 delete [] fTrackletContainer[0];
677 delete [] fTrackletContainer[1];
678 delete [] fTrackletContainer;
679 fTrackletContainer = NULL;
682 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
684 if(!TestBit(knewDM)){
685 delete fDigitsManager;
686 fDigitsManager = NULL;
691 AliInfo(Form("Number of found clusters : %d", fNoOfClusters));
696 //_____________________________________________________________________________
697 UChar_t AliTRDclusterizer::GetStatus(Short_t &signal)
700 // Check if a pad is masked
705 if(signal>0 && TESTBIT(signal, 10)){
707 for(int ibit=0; ibit<4; ibit++){
708 if(TESTBIT(signal, 11+ibit)){
709 SETBIT(status, ibit);
710 CLRBIT(signal, 11+ibit);
717 //_____________________________________________________________________________
718 void AliTRDclusterizer::SetPadStatus(const UChar_t status, UChar_t &out) const {
720 // Set the pad status into out
721 // First three bits are needed for the position encoding
726 //_____________________________________________________________________________
727 UChar_t AliTRDclusterizer::GetPadStatus(UChar_t encoding) const {
729 // return the staus encoding of the corrupted pad
731 return static_cast<UChar_t>(encoding >> 3);
734 //_____________________________________________________________________________
735 Int_t AliTRDclusterizer::GetCorruption(UChar_t encoding) const {
737 // Return the position of the corruption
742 //_____________________________________________________________________________
743 Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
746 // Generates the cluster.
750 fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
751 fBaseline = fDigitsManager->GetDigitsParam()->GetADCbaseline(det);
753 // This is to take care of switched off super modules
754 if (!fDigits->HasData()) return kFALSE;
756 fIndexes = fDigitsManager->GetIndexes(det);
757 if (fIndexes->IsAllocated() == kFALSE) {
758 AliError("Indexes do not exist!");
762 AliTRDcalibDB* const calibration = AliTRDcalibDB::Instance();
764 AliFatal("No AliTRDcalibDB instance available\n");
768 if (!fReconstructor){
769 AliError("Reconstructor not set\n");
773 const AliTRDrecoParam *const recoParam = fReconstructor->GetRecoParam();
775 fMaxThresh = (Short_t)recoParam->GetClusMaxThresh();
776 fMaxThreshTest = (Short_t)(recoParam->GetClusMaxThresh()/2+fBaseline);
777 fSigThresh = (Short_t)recoParam->GetClusSigThresh();
778 fMinMaxCutSigma = recoParam->GetMinMaxCutSigma();
779 fMinLeftRightCutSigma = recoParam->GetMinLeftRightCutSigma();
780 const Int_t iEveryNTB = recoParam->GetRecEveryNTB();
782 Int_t istack = fIndexes->GetStack();
783 fLayer = fIndexes->GetLayer();
784 Int_t isector = fIndexes->GetSM();
786 // Start clustering in the chamber
788 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
790 AliError("Strange Detector number Missmatch!");
794 AliDebug(2, Form("Det[%d] @ Sec[%d] Stk[%d] Ly[%d]", fDet, isector, istack, fLayer));
796 // TRD space point transformation
797 fTransform->SetDetector(det);
799 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
800 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
801 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
803 if(fReconstructor->IsProcessingTracklets() && fTrackletContainer)
804 AddTrackletsToArray();
806 fColMax = fDigits->GetNcol();
807 fTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
809 // Check consistency between OCDB and raw data
810 Int_t nTimeOCDB = calibration->GetNumberOfTimeBinsDCS();
811 if(fReconstructor->IsHLT()){
812 if((nTimeOCDB > -1) && (fTimeTotal != nTimeOCDB)){
813 AliWarning(Form("Number of timebins does not match OCDB value (RAW[%d] OCDB[%d]), using raw value"
814 ,fTimeTotal,nTimeOCDB));
818 AliWarning("Undefined number of timebins in OCDB, using value from raw data.");
820 AliError("Number of timebins in raw data is negative, skipping chamber!");
823 }else if(nTimeOCDB == -2){
824 AliError("Mixed number of timebins in OCDB, no reconstruction of TRD data!");
826 }else if(fTimeTotal != nTimeOCDB){
827 AliError(Form("Number of timebins in raw data does not match OCDB value (RAW[%d] OCDB[%d]), skipping chamber!"
828 ,fTimeTotal,nTimeOCDB));
833 // Detector wise calibration object for the gain factors
834 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
835 // Calibration object with pad wise values for the gain factors
836 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
837 // Calibration value for chamber wise gain factor
838 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
840 // Detector wise calibration object for the noise
841 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
842 // Calibration object with pad wise values for the noise
843 fCalNoiseROC = calibration->GetNoiseROC(fDet);
844 // Calibration value for chamber wise noise
845 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
847 // Calibration object with the pad status
848 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
850 firstClusterROC = -1;
853 SetBit(kLUT, recoParam->UseLUT());
854 SetBit(kGAUS, recoParam->UseGAUS());
856 // Apply the gain and the tail cancelation via digital filter
857 // Use the configuration from the DCS to find out whether online
858 // tail cancellation was applied
859 if(!calibration->HasOnlineTailCancellation()) TailCancelation(recoParam);
861 MaxStruct curr, last;
862 Int_t nMaximas = 0, nCorrupted = 0;
864 // Here the clusterfining is happening
866 for(curr.time = 0; curr.time < fTimeTotal; curr.time+=iEveryNTB){
867 while(fIndexes->NextRCIndex(curr.row, curr.col)){
868 if(fDigits->GetData(curr.row, curr.col, curr.time) > fMaxThreshTest && IsMaximum(curr, curr.padStatus, &curr.signals[0])){
870 if(curr.col==last.col+2 && curr.row==last.row && curr.time==last.time) FivePadCluster(last, curr);
873 last=curr; curr.fivePad=kFALSE;
877 if(last.row>-1) CreateCluster(last);
879 if(recoParam->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 2 && fReconstructor->IsDebugStreaming()){
880 TTreeSRedirector* fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
881 (*fDebugStream) << "MakeClusters"
882 << "Detector=" << det
883 << "NMaxima=" << nMaximas
884 << "NClusters=" << fClusterROC
885 << "NCorrupted=" << nCorrupted
888 if (TestBit(kLabels)) AddLabels();
894 //_____________________________________________________________________________
895 Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Short_t *const Signals)
898 // Returns true if this row,col,time combination is a maximum.
899 // Gives back the padStatus and the signals of the center pad and the two neighbouring pads.
902 Float_t gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col,Max.row);
903 Signals[1] = (Short_t)((fDigits->GetData(Max.row, Max.col, Max.time) - fBaseline) / gain + 0.5f);
904 if(Signals[1] <= fMaxThresh) return kFALSE;
906 if(Max.col < 1 || Max.col + 1 >= fColMax) return kFALSE;
908 Short_t noiseMiddleThresh = (Short_t)(fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.col, Max.row));
909 if (Signals[1] <= noiseMiddleThresh) return kFALSE;
912 fCalPadStatusROC->GetStatus(Max.col-1, Max.row)
913 ,fCalPadStatusROC->GetStatus(Max.col, Max.row)
914 ,fCalPadStatusROC->GetStatus(Max.col+1, Max.row)
918 if((signal = fDigits->GetData(Max.row, Max.col-1, Max.time))){
919 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col-1,Max.row);
920 Signals[0] = (Short_t)((signal - fBaseline) / gain + 0.5f);
921 } else Signals[0] = 0;
922 if((signal = fDigits->GetData(Max.row, Max.col+1, Max.time))){
923 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col+1,Max.row);
924 Signals[2] = (Short_t)((signal - fBaseline) / gain + 0.5f);
925 } else Signals[2] = 0;
927 if(!(status[0] | status[1] | status[2])) {//all pads are good
928 if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) {
929 if ((Signals[2] > fSigThresh) || (Signals[0] > fSigThresh)) {
930 if(Signals[0]<0)Signals[0]=0;
931 if(Signals[2]<0)Signals[2]=0;
932 Short_t noiseSumThresh = (Short_t)(fMinLeftRightCutSigma * fCalNoiseDetValue
933 * fCalNoiseROC->GetValue(Max.col, Max.row));
934 if ((Signals[2]+Signals[0]+Signals[1]) <= noiseSumThresh) return kFALSE;
939 } else { // at least one of the pads is bad, and reject candidates with more than 1 problematic pad
940 if(Signals[0]<0)Signals[0]=0;
941 if(Signals[2]<0)Signals[2]=0;
942 if (status[2] && (!(status[0] || status[1])) && Signals[1] > Signals[0] && Signals[0] > fSigThresh) {
944 SetPadStatus(status[2], padStatus);
947 else if (status[0] && (!(status[1] || status[2])) && Signals[1] >= Signals[2] && Signals[2] > fSigThresh) {
949 SetPadStatus(status[0], padStatus);
952 else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] > fSigThresh) || (Signals[0] > fSigThresh))) {
953 Signals[1] = fMaxThresh;
954 SetPadStatus(status[1], padStatus);
961 //_____________________________________________________________________________
962 Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
965 // Look for 5 pad cluster with minimum in the middle
966 // Gives back the ratio
969 if (ThisMax.col >= fColMax - 3) return kFALSE;
971 if (ThisMax.col < fColMax - 5){
972 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col+4,ThisMax.row);
973 if (fDigits->GetData(ThisMax.row, ThisMax.col+4, ThisMax.time) - fBaseline >= fSigThresh * gain)
976 if (ThisMax.col > 1) {
977 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col-2,ThisMax.row);
978 if (fDigits->GetData(ThisMax.row, ThisMax.col-2, ThisMax.time) - fBaseline >= fSigThresh * gain)
982 const Float_t kEpsilon = 0.01;
983 Double_t padSignal[5] = {ThisMax.signals[0], ThisMax.signals[1], ThisMax.signals[2],
984 NeighbourMax.signals[1], NeighbourMax.signals[2]};
986 // Unfold the two maxima and set the signal on
987 // the overlapping pad to the ratio
988 Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
989 ThisMax.signals[2] = (Short_t)(ThisMax.signals[2]*ratio + 0.5f);
990 NeighbourMax.signals[0] = (Short_t)(NeighbourMax.signals[0]*(1-ratio) + 0.5f);
991 ThisMax.fivePad=kTRUE;
992 NeighbourMax.fivePad=kTRUE;
997 //_____________________________________________________________________________
998 void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
1001 // Creates a cluster at the given position and saves it in fRecPoints
1004 Int_t nPadCount = 1;
1005 Short_t signals[7] = { 0, 0, Max.signals[0], Max.signals[1], Max.signals[2], 0, 0 };
1006 if(!fReconstructor->IsHLT()) CalcAdditionalInfo(Max, signals, nPadCount);
1008 AliTRDcluster cluster(fDet, ((UChar_t) Max.col), ((UChar_t) Max.row), ((UChar_t) Max.time), signals, fVolid);
1009 cluster.SetNPads(nPadCount);
1010 if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
1011 else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
1012 else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
1014 cluster.SetFivePad(Max.fivePad);
1015 // set pads status for the cluster
1016 UChar_t maskPosition = GetCorruption(Max.padStatus);
1018 cluster.SetPadMaskedPosition(maskPosition);
1019 cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
1021 cluster.SetXcorr(fReconstructor->UseClusterRadialCorrection());
1023 // Transform the local cluster coordinates into calibrated
1024 // space point positions defined in the local tracking system.
1025 // Here the calibration for T0, Vdrift and ExB is applied as well.
1026 if(!TestBit(kSkipTrafo)) if(!fTransform->Transform(&cluster)) return;
1028 // Temporarily store the Max.Row, column and time bin of the center pad
1029 // Used to later on assign the track indices
1030 cluster.SetLabel(Max.row, 0);
1031 cluster.SetLabel(Max.col, 1);
1032 cluster.SetLabel(Max.time,2);
1034 //needed for HLT reconstruction
1035 AddClusterToArray(&cluster);
1037 // Store the index of the first cluster in the current ROC
1038 if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
1044 //_____________________________________________________________________________
1045 void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
1047 // Calculate number of pads/cluster and
1048 // ADC signals at position 0, 1, 5 and 6
1050 Float_t gain(1.); Short_t signal(0.);
1051 // Store the amplitudes of the pads in the cluster for later analysis
1052 // and check whether one of these pads is masked in the database
1053 signals[3]=Max.signals[1];
1054 Int_t ipad(1), jpad(0);
1055 // Look to the right
1056 while((jpad = Max.col-ipad)){
1057 if(!(signal = fDigits->GetData(Max.row, jpad, Max.time))) break; // empty digit !
1058 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(jpad, Max.row);
1059 signal = (Short_t)((signal - fBaseline) / gain + 0.5f);
1060 if(signal<fSigThresh) break; // signal under threshold
1062 if(ipad<=3) signals[3 - ipad] = signal;
1067 while((jpad = Max.col+ipad)<fColMax){
1068 if(!(signal = fDigits->GetData(Max.row, jpad, Max.time))) break; // empty digit !
1069 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(jpad, Max.row);
1070 signal = (Short_t)((signal - fBaseline) / gain + 0.5f);
1071 if(signal<fSigThresh) break; // signal under threshold
1073 if(ipad<=3) signals[3 + ipad] = signal;
1077 AliDebug(4, Form("Signals[%3d %3d %3d %3d %3d %3d %3d] Npads[%d]."
1078 , signals[0], signals[1], signals[2], signals[3], signals[4], signals[5], signals[6], nPadCount));
1081 //_____________________________________________________________________________
1082 void AliTRDclusterizer::AddClusterToArray(AliTRDcluster* cluster)
1085 // Add a cluster to the array
1088 Int_t n = RecPoints()->GetEntriesFast();
1089 if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
1090 new((*RecPoints())[n]) AliTRDcluster(*cluster);
1093 //_____________________________________________________________________________
1094 void AliTRDclusterizer::AddTrackletsToArray()
1097 // Add the online tracklets of this chamber to the array
1100 UInt_t* trackletword;
1101 for(Int_t side=0; side<2; side++)
1104 trackletword=fTrackletContainer[side];
1105 while(trackletword[trkl]>0){
1106 Int_t n = TrackletsArray()->GetEntriesFast();
1107 AliTRDtrackletWord tmp(trackletword[trkl]);
1108 new((*TrackletsArray())[n]) AliTRDcluster(&tmp,fDet,fVolid);
1114 //_____________________________________________________________________________
1115 Bool_t AliTRDclusterizer::AddLabels()
1118 // Add the track indices to the found clusters
1121 const Int_t kNclus = 3;
1122 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1123 const Int_t kNtrack = kNdict * kNclus;
1125 Int_t iClusterROC = 0;
1132 // Temporary array to collect the track indices
1133 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1135 // Loop through the dictionary arrays one-by-one
1136 // to keep memory consumption low
1137 AliTRDarrayDictionary *tracksIn = 0; //mod
1138 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1140 // tracksIn should be expanded beforehand!
1141 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1143 // Loop though the clusters found in this ROC
1144 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1146 AliTRDcluster *cluster = (AliTRDcluster *)
1147 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1148 row = cluster->GetLabel(0);
1149 col = cluster->GetLabel(1);
1150 time = cluster->GetLabel(2);
1152 for (iPad = 0; iPad < kNclus; iPad++) {
1153 Int_t iPadCol = col - 1 + iPad;
1154 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1155 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1162 // Copy the track indices into the cluster
1163 // Loop though the clusters found in this ROC
1164 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1166 AliTRDcluster *cluster = (AliTRDcluster *)
1167 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1168 cluster->SetLabel(-9999,0);
1169 cluster->SetLabel(-9999,1);
1170 cluster->SetLabel(-9999,2);
1172 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1176 delete [] idxTracks;
1182 //_____________________________________________________________________________
1183 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, const Double_t *const padSignal) const
1186 // Method to unfold neighbouring maxima.
1187 // The charge ratio on the overlapping pad is calculated
1188 // until there is no more change within the range given by eps.
1189 // The resulting ratio is then returned to the calling method.
1192 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1194 AliError("No AliTRDcalibDB instance available\n");
1199 Int_t itStep = 0; // Count iteration steps
1201 Double_t ratio = 0.5; // Start value for ratio
1202 Double_t prevRatio = 0.0; // Store previous ratio
1204 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1205 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1206 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1208 // Start the iteration
1209 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1214 // Cluster position according to charge ratio
1215 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1216 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1217 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1218 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1220 // Set cluster charge ratio
1221 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1222 Double_t ampLeft = padSignal[1] / newSignal[1];
1223 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1224 Double_t ampRight = padSignal[3] / newSignal[1];
1226 // Apply pad response to parameters
1227 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1228 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1230 // Calculate new overlapping ratio
1231 ratio = TMath::Min((Double_t) 1.0
1232 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1240 //_____________________________________________________________________________
1241 void AliTRDclusterizer::TailCancelation(const AliTRDrecoParam* const recoParam)
1244 // Applies the tail cancelation
1251 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
1252 Bool_t debugStreaming = recoParam->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 7 && fReconstructor->IsDebugStreaming();
1253 Int_t nexp = recoParam->GetTCnexp();
1254 while(fIndexes->NextRCIndex(iRow, iCol))
1256 // if corrupted then don't make the tail cancallation
1257 if (fCalPadStatusROC->GetStatus(iCol, iRow)) continue;
1260 for (iTime = 0; iTime < fTimeTotal; iTime++)
1261 (*fDebugStream) << "TailCancellation"
1267 // Apply the tail cancelation via the digital filter
1268 DeConvExp(fDigits->GetDataAddress(iRow,iCol),fTimeTotal,nexp);
1270 } // while irow icol
1276 //_____________________________________________________________________________
1277 void AliTRDclusterizer::DeConvExp(Short_t *const arr, const Int_t nTime, const Int_t nexp)
1280 // Tail cancellation by deconvolution for PASA v4 TRF
1284 Float_t coefficients[2];
1286 // Initialization (coefficient = alpha, rates = lambda)
1292 if (nexp == 1) { // 1 Exponentials
1298 if (nexp == 2) { // 2 Exponentials
1300 fReconstructor->GetRecoParam()->GetTCParams(par);
1301 r1 = par[0];//1.156;
1302 r2 = par[1];//0.130;
1303 c1 = par[2];//0.114;
1304 c2 = par[3];//0.624;
1307 coefficients[0] = c1;
1308 coefficients[1] = c2;
1312 rates[0] = TMath::Exp(-dt/(r1));
1313 rates[1] = (nexp == 1) ? .0 : TMath::Exp(-dt/(r2));
1315 Float_t reminder[2] = { .0, .0 };
1316 Float_t correction = 0.0;
1317 Float_t result = 0.0;
1319 for (int i = 0; i < nTime; i++) {
1321 result = arr[i] - correction - fBaseline; // No rescaling
1322 arr[i] = (Short_t)(result + fBaseline + 0.5f);
1325 for (int k = 0; k < 2; k++) {
1326 correction += reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1333 //_____________________________________________________________________________
1334 void AliTRDclusterizer::ResetRecPoints()
1337 // Resets the list of rec points
1341 fRecPoints->Clear();
1343 // delete fRecPoints;
1347 //_____________________________________________________________________________
1348 TClonesArray *AliTRDclusterizer::RecPoints()
1351 // Returns the list of rec points
1355 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1356 // determine number of clusters which has to be allocated
1357 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1359 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1361 //SetClustersOwner(kTRUE);
1362 AliTRDReconstructor::SetClusters(0x0);
1368 //_____________________________________________________________________________
1369 TClonesArray *AliTRDclusterizer::TrackletsArray()
1372 // Returns the list of rec points
1375 if (!fTracklets && fReconstructor->IsProcessingTracklets()) {
1376 fTracklets = new TClonesArray("AliTRDcluster", 2*MAXTRACKLETSPERHC);
1377 //SetClustersOwner(kTRUE);
1378 //AliTRDReconstructor::SetTracklets(0x0);