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"
47 #include "AliTRDtrackletMCM.h"
48 #include "AliTRDtrackGTU.h"
49 #include "AliESDTrdTrack.h"
51 #include "TTreeStream.h"
53 #include "Cal/AliTRDCalROC.h"
54 #include "Cal/AliTRDCalDet.h"
55 #include "Cal/AliTRDCalSingleChamberStatus.h"
56 #include "Cal/AliTRDCalOnlineGainTableROC.h"
58 ClassImp(AliTRDclusterizer)
60 //_____________________________________________________________________________
61 AliTRDclusterizer::AliTRDclusterizer(const AliTRDReconstructor *const rec)
70 ,fDigitsManager(new AliTRDdigitsManager())
71 ,fTrackletContainer(NULL)
73 ,fTransform(new AliTRDtransform(0))
80 ,fMinLeftRightCutSigma(0)
86 ,fCalGainFactorROC(NULL)
87 ,fCalGainFactorDetValue(0)
90 ,fCalPadStatusROC(NULL)
100 // AliTRDclusterizer default constructor
103 SetBit(kLabels, kTRUE);
104 SetBit(knewDM, kFALSE);
106 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
108 // Initialize debug stream
110 if(fReconstructor->GetRecoParam()->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 1){
111 TDirectory *savedir = gDirectory;
112 //fgGetDebugStream = new TTreeSRedirector("TRD.ClusterizerDebug.root");
119 //_____________________________________________________________________________
120 AliTRDclusterizer::AliTRDclusterizer(const Text_t *name
121 , const Text_t *title
122 , const AliTRDReconstructor *const rec)
131 ,fDigitsManager(new AliTRDdigitsManager())
132 ,fTrackletContainer(NULL)
134 ,fTransform(new AliTRDtransform(0))
141 ,fMinLeftRightCutSigma(0)
147 ,fCalGainFactorROC(NULL)
148 ,fCalGainFactorDetValue(0)
150 ,fCalNoiseDetValue(0)
151 ,fCalPadStatusROC(NULL)
161 // AliTRDclusterizer constructor
164 SetBit(kLabels, kTRUE);
165 SetBit(knewDM, kFALSE);
167 fDigitsManager->CreateArrays();
169 fRawVersion = AliTRDfeeParam::Instance()->GetRAWversion();
175 //_____________________________________________________________________________
176 AliTRDclusterizer::AliTRDclusterizer(const AliTRDclusterizer &c)
178 ,fReconstructor(c.fReconstructor)
185 ,fDigitsManager(NULL)
186 ,fTrackletContainer(NULL)
195 ,fMinLeftRightCutSigma(0)
201 ,fCalGainFactorROC(NULL)
202 ,fCalGainFactorDetValue(0)
204 ,fCalNoiseDetValue(0)
205 ,fCalPadStatusROC(NULL)
215 // AliTRDclusterizer copy constructor
218 SetBit(kLabels, kTRUE);
219 SetBit(knewDM, kFALSE);
225 //_____________________________________________________________________________
226 AliTRDclusterizer::~AliTRDclusterizer()
229 // AliTRDclusterizer destructor
232 if (fRecPoints/* && IsClustersOwner()*/){
233 fRecPoints->Delete();
238 fTracklets->Delete();
247 if (fDigitsManager) {
248 delete fDigitsManager;
249 fDigitsManager = NULL;
264 //_____________________________________________________________________________
265 AliTRDclusterizer &AliTRDclusterizer::operator=(const AliTRDclusterizer &c)
268 // Assignment operator
273 ((AliTRDclusterizer &) c).Copy(*this);
280 //_____________________________________________________________________________
281 void AliTRDclusterizer::Copy(TObject &c) const
287 ((AliTRDclusterizer &) c).fClusterTree = NULL;
288 ((AliTRDclusterizer &) c).fRecPoints = NULL;
289 ((AliTRDclusterizer &) c).fTrackletTree = NULL;
290 ((AliTRDclusterizer &) c).fDigitsManager = NULL;
291 ((AliTRDclusterizer &) c).fRawVersion = fRawVersion;
292 ((AliTRDclusterizer &) c).fTransform = NULL;
293 ((AliTRDclusterizer &) c).fDigits = NULL;
294 ((AliTRDclusterizer &) c).fIndexes = NULL;
295 ((AliTRDclusterizer &) c).fMaxThresh = 0;
296 ((AliTRDclusterizer &) c).fMaxThreshTest = 0;
297 ((AliTRDclusterizer &) c).fSigThresh = 0;
298 ((AliTRDclusterizer &) c).fMinMaxCutSigma= 0;
299 ((AliTRDclusterizer &) c).fMinLeftRightCutSigma = 0;
300 ((AliTRDclusterizer &) c).fLayer = 0;
301 ((AliTRDclusterizer &) c).fDet = 0;
302 ((AliTRDclusterizer &) c).fVolid = 0;
303 ((AliTRDclusterizer &) c).fColMax = 0;
304 ((AliTRDclusterizer &) c).fTimeTotal = 0;
305 ((AliTRDclusterizer &) c).fCalGainFactorROC = NULL;
306 ((AliTRDclusterizer &) c).fCalGainFactorDetValue = 0;
307 ((AliTRDclusterizer &) c).fCalNoiseROC = NULL;
308 ((AliTRDclusterizer &) c).fCalNoiseDetValue = 0;
309 ((AliTRDclusterizer &) c).fCalPadStatusROC = NULL;
310 ((AliTRDclusterizer &) c).fClusterROC = 0;
311 ((AliTRDclusterizer &) c).firstClusterROC= 0;
312 ((AliTRDclusterizer &) c).fNoOfClusters = 0;
313 ((AliTRDclusterizer &) c).fBaseline = 0;
314 ((AliTRDclusterizer &) c).fRawStream = NULL;
318 //_____________________________________________________________________________
319 Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
322 // Opens the AliROOT file. Output and input are in the same file
325 TString evfoldname = AliConfig::GetDefaultEventFolderName();
326 fRunLoader = AliRunLoader::GetRunLoader(evfoldname);
329 fRunLoader = AliRunLoader::Open(name);
333 AliError(Form("Can not open session for file %s.",name));
344 //_____________________________________________________________________________
345 Bool_t AliTRDclusterizer::OpenOutput()
348 // Open the output file
351 if (!fReconstructor->IsWritingClusters()) return kTRUE;
353 TObjArray *ioArray = 0x0;
355 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
356 loader->MakeTree("R");
358 fClusterTree = loader->TreeR();
359 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
365 //_____________________________________________________________________________
366 Bool_t AliTRDclusterizer::OpenOutput(TTree *const clusterTree)
369 // Connect the output tree
373 if (fReconstructor->IsWritingClusters()){
374 TObjArray *ioArray = 0x0;
375 fClusterTree = clusterTree;
376 fClusterTree->Branch("TRDcluster", "TObjArray", &ioArray, 32000, 0);
381 //_____________________________________________________________________________
382 Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
385 // Opens a ROOT-file with TRD-hits and reads in the digits-tree
388 // Import the Trees for the event nEvent in the file
389 fRunLoader->GetEvent(nEvent);
395 //_____________________________________________________________________________
396 Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
399 // Fills TRDcluster branch in the tree with the clusters
400 // found in detector = det. For det=-1 writes the tree.
404 (det >= AliTRDgeometry::Ndet())) {
405 AliError(Form("Unexpected detector index %d.\n",det));
409 TObjArray *ioArray = new TObjArray(400);
410 TBranch *branch = fClusterTree->GetBranch("TRDcluster");
412 fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
413 } else branch->SetAddress(&ioArray);
415 Int_t nRecPoints = RecPoints()->GetEntriesFast();
417 for (Int_t i = 0; i < nRecPoints; i++) {
418 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
419 if(det != c->GetDetector()) continue;
422 fClusterTree->Fill();
425 Int_t detOld = -1, nw(0);
426 for (Int_t i = 0; i < nRecPoints; i++) {
427 AliTRDcluster *c = (AliTRDcluster *) RecPoints()->UncheckedAt(i);
428 if(c->GetDetector() != detOld){
429 nw += ioArray->GetEntriesFast();
430 fClusterTree->Fill();
432 detOld = c->GetDetector();
436 if(ioArray->GetEntriesFast()){
437 nw += ioArray->GetEntriesFast();
438 fClusterTree->Fill();
441 AliDebug(2, Form("Clusters FOUND[%d] WRITTEN[%d] STATUS[%s]", nRecPoints, nw, nw==nRecPoints?"OK":"FAILED"));
448 //_____________________________________________________________________________
449 Bool_t AliTRDclusterizer::ReadDigits()
452 // Reads the digits arrays from the input aliroot file
456 AliError("No run loader available");
460 AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
461 if (!loader->TreeD()) {
462 loader->LoadDigits();
465 // Read in the digit arrays
466 return (fDigitsManager->ReadDigits(loader->TreeD()));
470 //_____________________________________________________________________________
471 Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
474 // Reads the digits arrays from the input tree
477 // Read in the digit arrays
478 return (fDigitsManager->ReadDigits(digitsTree));
482 //_____________________________________________________________________________
483 Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
486 // Reads the digits arrays from the ddl file
490 fDigitsManager = raw.Raw2Digits(rawReader);
496 Bool_t AliTRDclusterizer::ReadTracklets()
499 // Reads simulated tracklets from the input aliroot file
502 AliRunLoader *runLoader = AliRunLoader::Instance();
504 AliError("No run loader available");
508 AliLoader* loader = runLoader->GetLoader("TRDLoader");
510 AliDataLoader *trackletLoader = loader->GetDataLoader("tracklets");
511 if (!trackletLoader) {
515 // simulated tracklets
516 trackletLoader->Load();
517 TTree *trackletTree = trackletLoader->Tree();
520 TBranch *trklbranch = trackletTree->GetBranch("mcmtrklbranch");
521 TClonesArray *trklArray = TrackletsArray("AliTRDtrackletMCM");
522 if (trklbranch && trklArray) {
523 AliTRDtrackletMCM *trkl = 0x0;
524 trklbranch->SetAddress(&trkl);
525 for (Int_t iTracklet = 0; iTracklet < trklbranch->GetEntries(); iTracklet++) {
526 trklbranch->GetEntry(iTracklet);
527 new ((*trklArray)[trklArray->GetEntries()]) AliTRDtrackletMCM(*trkl);
535 Bool_t AliTRDclusterizer::ReadTracks()
538 // Reads simulated GTU tracks from the input aliroot file
541 AliRunLoader *runLoader = AliRunLoader::Instance();
544 AliError("No run loader available");
548 AliLoader* loader = runLoader->GetLoader("TRDLoader");
553 AliDataLoader *trackLoader = loader->GetDataLoader("gtutracks");
560 TTree *trackTree = trackLoader->Tree();
565 TClonesArray *trackArray = TracksArray();
566 AliTRDtrackGTU *trk = 0x0;
567 trackTree->SetBranchAddress("TRDtrackGTU", &trk);
568 for (Int_t iTrack = 0; iTrack < trackTree->GetEntries(); iTrack++) {
569 trackTree->GetEntry(iTrack);
570 new ((*trackArray)[trackArray->GetEntries()]) AliESDTrdTrack(*(trk->CreateTrdTrack()));
576 //_____________________________________________________________________________
577 Bool_t AliTRDclusterizer::MakeClusters()
580 // Creates clusters from digits
583 // Propagate info from the digits manager
584 if (TestBit(kLabels)){
585 SetBit(kLabels, fDigitsManager->UsesDictionaries());
588 Bool_t fReturn = kTRUE;
589 for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++){
591 AliTRDarrayADC *digitsIn = (AliTRDarrayADC*) fDigitsManager->GetDigits(i); //mod
592 // This is to take care of switched off super modules
593 if (!digitsIn->HasData()) continue;
595 digitsIn->DeleteNegatives(); // Restore digits array to >=0 values
596 AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
597 if (indexes->IsAllocated() == kFALSE){
598 fDigitsManager->BuildIndexes(i);
602 if (indexes->HasEntry()){
603 if (TestBit(kLabels)){
604 for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++){
605 AliTRDarrayDictionary *tracksIn = 0; //mod
606 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(i,iDict); //mod
610 fR = MakeClusters(i);
611 fReturn = fR && fReturn;
615 // if(IsWritingClusters()) WriteClusters(i);
619 // Clear arrays of this chamber, to prepare for next event
620 fDigitsManager->ClearArrays(i);
623 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
625 AliInfo(Form("Number of found clusters : %d", RecPoints()->GetEntriesFast()));
631 //_____________________________________________________________________________
632 Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
635 // Creates clusters from raw data
638 return Raw2ClustersChamber(rawReader);
642 //_____________________________________________________________________________
643 Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
646 // Creates clusters from raw data
649 // Create the digits manager
650 if (!fDigitsManager){
651 SetBit(knewDM, kTRUE);
652 fDigitsManager = new AliTRDdigitsManager(kTRUE);
653 fDigitsManager->CreateArrays();
656 fDigitsManager->SetUseDictionaries(TestBit(kLabels));
658 // ----- preparing tracklet output -----
659 if (fReconstructor->IsWritingTracklets()) {
660 AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets");
662 //AliInfo("Could not get the tracklets data loader, adding it now!");
663 trklLoader = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
664 AliRunLoader::Instance()->GetLoader("TRDLoader")->AddDataLoader(trklLoader);
666 AliTreeLoader *trklTreeLoader = dynamic_cast<AliTreeLoader*> (trklLoader->GetBaseLoader("tracklets-raw"));
667 if (!trklTreeLoader) {
668 trklTreeLoader = new AliTreeLoader("tracklets-raw", trklLoader);
669 trklLoader->AddBaseLoader(trklTreeLoader);
671 if (!trklTreeLoader->Tree())
672 trklTreeLoader->MakeTree();
676 fRawStream = new AliTRDrawStream(rawReader);
678 fRawStream->SetReader(rawReader);
680 //if(fReconstructor->IsHLT()){
681 fRawStream->DisableErrorStorage();
684 // register tracklet array for output
685 fRawStream->SetTrackletArray(TrackletsArray("AliTRDtrackletMCM"));
686 fRawStream->SetTrackArray(TracksArray());
689 while ((det = fRawStream->NextChamber(fDigitsManager)) < AliTRDgeometry::kNdet){
690 if (fDigitsManager->GetIndexes(det)->HasEntry()){
692 fDigitsManager->ClearArrays(det);
696 if (fReconstructor->IsWritingTracklets()) {
697 if (AliDataLoader *trklLoader = AliRunLoader::Instance()->GetLoader("TRDLoader")->GetDataLoader("tracklets")) {
699 if (AliTreeLoader *trklTreeLoader = (AliTreeLoader*) trklLoader->GetBaseLoader("tracklets-raw"))
700 trklTreeLoader->WriteData("OVERWRITE");
701 trklLoader->UnloadAll();
706 for (Int_t iSector = 0; iSector < AliTRDgeometry::kNsector; iSector++) {
707 fTrgFlags[iSector] = fRawStream->GetTriggerFlags(iSector);
710 if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
712 if(!TestBit(knewDM)){
713 delete fDigitsManager;
714 fDigitsManager = NULL;
719 AliInfo(Form("Number of found clusters : %d", fNoOfClusters));
724 //_____________________________________________________________________________
725 UChar_t AliTRDclusterizer::GetStatus(Short_t &signal)
728 // Check if a pad is masked
733 if(signal>0 && TESTBIT(signal, 10)){
735 for(int ibit=0; ibit<4; ibit++){
736 if(TESTBIT(signal, 11+ibit)){
737 SETBIT(status, ibit);
738 CLRBIT(signal, 11+ibit);
745 //_____________________________________________________________________________
746 void AliTRDclusterizer::SetPadStatus(const UChar_t status, UChar_t &out) const {
748 // Set the pad status into out
749 // First three bits are needed for the position encoding
754 //_____________________________________________________________________________
755 UChar_t AliTRDclusterizer::GetPadStatus(UChar_t encoding) const {
757 // return the staus encoding of the corrupted pad
759 return static_cast<UChar_t>(encoding >> 3);
762 //_____________________________________________________________________________
763 Int_t AliTRDclusterizer::GetCorruption(UChar_t encoding) const {
765 // Return the position of the corruption
770 //_____________________________________________________________________________
771 Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
774 // Generates the cluster.
778 fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
779 fBaseline = fDigitsManager->GetDigitsParam()->GetADCbaseline(det);
781 // This is to take care of switched off super modules
782 if (!fDigits->HasData()) return kFALSE;
784 fIndexes = fDigitsManager->GetIndexes(det);
785 if (fIndexes->IsAllocated() == kFALSE) {
786 AliError("Indexes do not exist!");
790 AliTRDcalibDB* const calibration = AliTRDcalibDB::Instance();
792 AliFatal("No AliTRDcalibDB instance available\n");
796 if (!fReconstructor){
797 AliError("Reconstructor not set\n");
801 const AliTRDrecoParam *const recoParam = fReconstructor->GetRecoParam();
803 fMaxThresh = (Short_t)recoParam->GetClusMaxThresh();
804 fMaxThreshTest = (Short_t)(recoParam->GetClusMaxThresh()/2+fBaseline);
805 fSigThresh = (Short_t)recoParam->GetClusSigThresh();
806 fMinMaxCutSigma = recoParam->GetMinMaxCutSigma();
807 fMinLeftRightCutSigma = recoParam->GetMinLeftRightCutSigma();
808 const Int_t iEveryNTB = recoParam->GetRecEveryNTB();
810 Int_t istack = fIndexes->GetStack();
811 fLayer = fIndexes->GetLayer();
812 Int_t isector = fIndexes->GetSM();
814 // Start clustering in the chamber
816 fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
818 AliError(Form("Detector number missmatch! Request[%03d] RAW[%03d]", det, fDet));
822 AliDebug(2, Form("Det[%d] @ Sec[%d] Stk[%d] Ly[%d]", fDet, isector, istack, fLayer));
824 // TRD space point transformation
825 fTransform->SetDetector(det);
827 Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
828 Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
829 fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
831 fColMax = fDigits->GetNcol();
832 fTimeTotal = fDigitsManager->GetDigitsParam()->GetNTimeBins(det);
834 // Check consistency between Geometry and raw data
835 AliTRDpadPlane *pp(fTransform->GetPadPlane());
836 Int_t ncols(pp->GetNcols()), nrows(pp->GetNrows());
837 if(ncols != fColMax) AliDebug(1, Form("N cols missmatch in Digits for Det[%3d] :: Geom[%3d] RAW[%3d]", fDet, ncols, fColMax));
838 if(nrows != fDigits->GetNrow()) AliDebug(1, Form("N rows missmatch in Digits for Det[%3d] :: Geom[%3d] RAW[%3d]", fDet, nrows, fDigits->GetNrow()));
839 if(ncols != fIndexes->GetNcol()) AliDebug(1, Form("N cols missmatch in Digits for Det[%3d] :: Geom[%3d] RAW[%3d]", fDet, ncols, fIndexes->GetNcol()));
840 if(nrows != fIndexes->GetNrow()) AliDebug(1, Form("N rows missmatch in Digits for Det[%3d] :: Geom[%3d] RAW[%3d]", fDet, nrows, fIndexes->GetNrow()));
842 // Check consistency between OCDB and raw data
843 Int_t nTimeOCDB = calibration->GetNumberOfTimeBinsDCS();
844 if(fReconstructor->IsHLT()){
845 if((nTimeOCDB > -1) && (fTimeTotal != nTimeOCDB)){
846 AliWarning(Form("Number of timebins does not match OCDB value (RAW[%d] OCDB[%d]), using raw value"
847 ,fTimeTotal,nTimeOCDB));
851 AliDebug(1, "Undefined number of timebins in OCDB, using value from raw data.");
853 AliError(Form("Number of timebins in raw data is negative, skipping chamber[%3d]!", fDet));
856 }else if(nTimeOCDB == -2){
857 AliError("Mixed number of timebins in OCDB, no reconstruction of TRD data!");
859 }else if(fTimeTotal != nTimeOCDB){
860 AliError(Form("Number of timebins in raw data does not match OCDB value (RAW[%d] OCDB[%d]), skipping chamber[%3d]!"
861 ,fTimeTotal,nTimeOCDB, fDet));
865 AliDebug(1, Form("Using %2d number of timebins for Det[%03d].", fTimeTotal, fDet));
867 // Detector wise calibration object for the gain factors
868 const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
869 // Calibration object with pad wise values for the gain factors
870 fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
871 // Calibration value for chamber wise gain factor
872 fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
874 // Detector wise calibration object for the noise
875 const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
876 // Calibration object with pad wise values for the noise
877 fCalNoiseROC = calibration->GetNoiseROC(fDet);
878 // Calibration value for chamber wise noise
879 fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
881 // Calibration object with the pad status
882 fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
883 // Calibration object of the online gain
884 fCalOnGainROC = calibration->GetOnlineGainTableROC(fDet);
886 firstClusterROC = -1;
889 SetBit(kLUT, recoParam->UseLUT());
890 SetBit(kGAUS, recoParam->UseGAUS());
892 // Apply the gain and the tail cancelation via digital filter
893 // Use the configuration from the DCS to find out whether online
894 // tail cancellation was applied
895 if(!calibration->HasOnlineTailCancellation()) TailCancelation(recoParam);
897 MaxStruct curr, last;
898 Int_t nMaximas = 0, nCorrupted = 0;
900 // Here the clusterfining is happening
902 for(curr.time = 0; curr.time < fTimeTotal; curr.time+=iEveryNTB){
903 while(fIndexes->NextRCIndex(curr.row, curr.col)){
904 if(fDigits->GetData(curr.row, curr.col, curr.time) > fMaxThreshTest && IsMaximum(curr, curr.padStatus, &curr.signals[0])){
906 if(curr.col==last.col+2 && curr.row==last.row && curr.time==last.time) FivePadCluster(last, curr);
909 last=curr; curr.fivePad=kFALSE;
913 if(last.row>-1) CreateCluster(last);
915 if(recoParam->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 2 && fReconstructor->IsDebugStreaming()){
916 TTreeSRedirector* fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
917 (*fDebugStream) << "MakeClusters"
918 << "Detector=" << det
919 << "NMaxima=" << nMaximas
920 << "NClusters=" << fClusterROC
921 << "NCorrupted=" << nCorrupted
924 // if (TestBit(kLabels)) AddLabels();
930 //_____________________________________________________________________________
931 Bool_t AliTRDclusterizer::IsMaximum(const MaxStruct &Max, UChar_t &padStatus, Short_t *const Signals)
934 // Returns true if this row,col,time combination is a maximum.
935 // Gives back the padStatus and the signals of the center pad and the two neighbouring pads.
938 Float_t gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col,Max.row);
939 Float_t ongain = fCalOnGainROC ? fCalOnGainROC->GetGainCorrectionFactor(Max.row,Max.col) : 1;
940 Signals[1] = (Short_t)((fDigits->GetData(Max.row, Max.col, Max.time) - fBaseline) * ongain / gain + 0.5f);
941 if(Signals[1] <= fMaxThresh) return kFALSE;
943 if(Max.col < 1 || Max.col + 1 >= fColMax) return kFALSE;
945 Short_t noiseMiddleThresh = (Short_t)(fMinMaxCutSigma*fCalNoiseDetValue*fCalNoiseROC->GetValue(Max.col, Max.row));
946 if (Signals[1] <= noiseMiddleThresh) return kFALSE;
949 fCalPadStatusROC->GetStatus(Max.col-1, Max.row)
950 ,fCalPadStatusROC->GetStatus(Max.col, Max.row)
951 ,fCalPadStatusROC->GetStatus(Max.col+1, Max.row)
955 if((signal = fDigits->GetData(Max.row, Max.col-1, Max.time))){
956 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col-1,Max.row);
957 ongain = fCalOnGainROC ? fCalOnGainROC->GetGainCorrectionFactor(Max.row,Max.col-1) : 1;
958 Signals[0] = (Short_t)((signal - fBaseline) * ongain / gain + 0.5f);
959 } else Signals[0] = 0;
960 if((signal = fDigits->GetData(Max.row, Max.col+1, Max.time))){
961 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(Max.col+1,Max.row);
962 ongain = fCalOnGainROC ? fCalOnGainROC->GetGainCorrectionFactor(Max.row,Max.col+1) : 1;
963 Signals[2] = (Short_t)((signal - fBaseline) * ongain / gain + 0.5f);
964 } else Signals[2] = 0;
966 if(!(status[0] | status[1] | status[2])) {//all pads are good
967 if ((Signals[2] <= Signals[1]) && (Signals[0] < Signals[1])) {
968 if ((Signals[2] > fSigThresh) || (Signals[0] > fSigThresh)) {
969 if(Signals[0]<0)Signals[0]=0;
970 if(Signals[2]<0)Signals[2]=0;
971 Short_t noiseSumThresh = (Short_t)(fMinLeftRightCutSigma * fCalNoiseDetValue
972 * fCalNoiseROC->GetValue(Max.col, Max.row));
973 if ((Signals[2]+Signals[0]+Signals[1]) <= noiseSumThresh) return kFALSE;
978 } else { // at least one of the pads is bad, and reject candidates with more than 1 problematic pad
979 if(Signals[0]<0)Signals[0]=0;
980 if(Signals[2]<0)Signals[2]=0;
981 if (status[2] && (!(status[0] || status[1])) && Signals[1] > Signals[0] && Signals[0] > fSigThresh) {
983 SetPadStatus(status[2], padStatus);
986 else if (status[0] && (!(status[1] || status[2])) && Signals[1] >= Signals[2] && Signals[2] > fSigThresh) {
988 SetPadStatus(status[0], padStatus);
991 else if (status[1] && (!(status[0] || status[2])) && ((Signals[2] > fSigThresh) || (Signals[0] > fSigThresh))) {
992 Signals[1] = fMaxThresh;
993 SetPadStatus(status[1], padStatus);
1000 //_____________________________________________________________________________
1001 Bool_t AliTRDclusterizer::FivePadCluster(MaxStruct &ThisMax, MaxStruct &NeighbourMax)
1004 // Look for 5 pad cluster with minimum in the middle
1005 // Gives back the ratio
1008 if (ThisMax.col >= fColMax - 3) return kFALSE;
1010 if (ThisMax.col < fColMax - 5){
1011 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col+4,ThisMax.row);
1012 if (fDigits->GetData(ThisMax.row, ThisMax.col+4, ThisMax.time) - fBaseline >= fSigThresh * gain)
1015 if (ThisMax.col > 1) {
1016 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(ThisMax.col-2,ThisMax.row);
1017 if (fDigits->GetData(ThisMax.row, ThisMax.col-2, ThisMax.time) - fBaseline >= fSigThresh * gain)
1021 const Float_t kEpsilon = 0.01;
1022 Double_t padSignal[5] = {ThisMax.signals[0], ThisMax.signals[1], ThisMax.signals[2],
1023 NeighbourMax.signals[1], NeighbourMax.signals[2]};
1025 // Unfold the two maxima and set the signal on
1026 // the overlapping pad to the ratio
1027 Float_t ratio = Unfold(kEpsilon,fLayer,padSignal);
1028 ThisMax.signals[2] = (Short_t)(ThisMax.signals[2]*ratio + 0.5f);
1029 NeighbourMax.signals[0] = (Short_t)(NeighbourMax.signals[0]*(1-ratio) + 0.5f);
1030 ThisMax.fivePad=kTRUE;
1031 NeighbourMax.fivePad=kTRUE;
1036 //_____________________________________________________________________________
1037 void AliTRDclusterizer::CreateCluster(const MaxStruct &Max)
1040 // Creates a cluster at the given position and saves it in fRecPoints
1043 Int_t nPadCount = 1;
1044 Short_t signals[7] = { 0, 0, Max.signals[0], Max.signals[1], Max.signals[2], 0, 0 };
1045 if(!fReconstructor->IsHLT()) CalcAdditionalInfo(Max, signals, nPadCount);
1047 AliTRDcluster cluster(fDet, ((UChar_t) Max.col), ((UChar_t) Max.row), ((UChar_t) Max.time), signals, fVolid);
1048 cluster.SetNPads(nPadCount);
1049 if(TestBit(kLUT)) cluster.SetRPhiMethod(AliTRDcluster::kLUT);
1050 else if(TestBit(kGAUS)) cluster.SetRPhiMethod(AliTRDcluster::kGAUS);
1051 else cluster.SetRPhiMethod(AliTRDcluster::kCOG);
1053 cluster.SetFivePad(Max.fivePad);
1054 // set pads status for the cluster
1055 UChar_t maskPosition = GetCorruption(Max.padStatus);
1057 cluster.SetPadMaskedPosition(maskPosition);
1058 cluster.SetPadMaskedStatus(GetPadStatus(Max.padStatus));
1060 cluster.SetXcorr(fReconstructor->UseClusterRadialCorrection());
1062 // Transform the local cluster coordinates into calibrated
1063 // space point positions defined in the local tracking system.
1064 // Here the calibration for T0, Vdrift and ExB is applied as well.
1065 if(!TestBit(kSkipTrafo)) if(!fTransform->Transform(&cluster)) return;
1067 // Temporarily store the Max.Row, column and time bin of the center pad
1068 // Used to later on assign the track indices
1069 cluster.SetLabel(Max.row, 0);
1070 cluster.SetLabel(Max.col, 1);
1071 cluster.SetLabel(Max.time,2);
1073 //needed for HLT reconstruction
1074 AddClusterToArray(&cluster);
1076 // Store the index of the first cluster in the current ROC
1077 if (firstClusterROC < 0) firstClusterROC = fNoOfClusters;
1083 //_____________________________________________________________________________
1084 void AliTRDclusterizer::CalcAdditionalInfo(const MaxStruct &Max, Short_t *const signals, Int_t &nPadCount)
1086 // Calculate number of pads/cluster and
1087 // ADC signals at position 0, 1, 5 and 6
1089 Float_t tmp(0.), kMaxShortVal(32767.); // protect against data overflow due to wrong gain calibration
1090 Float_t gain(1.); Short_t signal(0);
1091 // Store the amplitudes of the pads in the cluster for later analysis
1092 // and check whether one of these pads is masked in the database
1093 signals[3]=Max.signals[1];
1094 Int_t ipad(1), jpad(0);
1095 // Look to the right
1096 while((jpad = Max.col-ipad)){
1097 if(!(signal = fDigits->GetData(Max.row, jpad, Max.time))) break; // empty digit !
1098 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(jpad, Max.row);
1099 tmp = (signal - fBaseline) / gain + 0.5f;
1100 signal = (Short_t)TMath::Min(tmp, kMaxShortVal);
1101 if(signal<fSigThresh) break; // signal under threshold
1103 if(ipad<=3) signals[3 - ipad] = signal;
1108 while((jpad = Max.col+ipad)<fColMax){
1109 if(!(signal = fDigits->GetData(Max.row, jpad, Max.time))) break; // empty digit !
1110 gain = fCalGainFactorDetValue * fCalGainFactorROC->GetValue(jpad, Max.row);
1111 tmp = (signal - fBaseline) / gain + 0.5f;
1112 signal = (Short_t)TMath::Min(tmp, kMaxShortVal);
1113 if(signal<fSigThresh) break; // signal under threshold
1115 if(ipad<=3) signals[3 + ipad] = signal;
1119 AliDebug(4, Form("Signals[%3d %3d %3d %3d %3d %3d %3d] Npads[%d]."
1120 , signals[0], signals[1], signals[2], signals[3], signals[4], signals[5], signals[6], nPadCount));
1123 //_____________________________________________________________________________
1124 void AliTRDclusterizer::AddClusterToArray(AliTRDcluster* cluster)
1127 // Add a cluster to the array
1130 Int_t n = RecPoints()->GetEntriesFast();
1131 if(n!=fNoOfClusters)AliError(Form("fNoOfClusters != RecPoints()->GetEntriesFast %i != %i \n", fNoOfClusters, n));
1132 new((*RecPoints())[n]) AliTRDcluster(*cluster);
1135 //_____________________________________________________________________________
1136 Bool_t AliTRDclusterizer::AddLabels()
1139 // Add the track indices to the found clusters
1142 const Int_t kNclus = 3;
1143 const Int_t kNdict = AliTRDdigitsManager::kNDict;
1144 const Int_t kNtrack = kNdict * kNclus;
1146 Int_t iClusterROC = 0;
1153 // Temporary array to collect the track indices
1154 Int_t *idxTracks = new Int_t[kNtrack*fClusterROC];
1156 // Loop through the dictionary arrays one-by-one
1157 // to keep memory consumption low
1158 AliTRDarrayDictionary *tracksIn = 0; //mod
1159 for (Int_t iDict = 0; iDict < kNdict; iDict++) {
1161 // tracksIn should be expanded beforehand!
1162 tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(fDet,iDict);
1164 // Loop though the clusters found in this ROC
1165 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1167 AliTRDcluster *cluster = (AliTRDcluster *)
1168 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1169 row = cluster->GetLabel(0);
1170 col = cluster->GetLabel(1);
1171 time = cluster->GetLabel(2);
1173 for (iPad = 0; iPad < kNclus; iPad++) {
1174 Int_t iPadCol = col - 1 + iPad;
1175 Int_t index = tracksIn->GetData(row,iPadCol,time); //Modification of -1 in Track
1176 idxTracks[3*iPad+iDict + iClusterROC*kNtrack] = index;
1183 // Copy the track indices into the cluster
1184 // Loop though the clusters found in this ROC
1185 for (iClusterROC = 0; iClusterROC < fClusterROC; iClusterROC++) {
1187 AliTRDcluster *cluster = (AliTRDcluster *)
1188 RecPoints()->UncheckedAt(firstClusterROC+iClusterROC);
1189 cluster->SetLabel(-9999,0);
1190 cluster->SetLabel(-9999,1);
1191 cluster->SetLabel(-9999,2);
1193 cluster->AddTrackIndex(&idxTracks[iClusterROC*kNtrack]);
1197 delete [] idxTracks;
1203 //_____________________________________________________________________________
1204 Float_t AliTRDclusterizer::Unfold(Double_t eps, Int_t layer, const Double_t *const padSignal) const
1207 // Method to unfold neighbouring maxima.
1208 // The charge ratio on the overlapping pad is calculated
1209 // until there is no more change within the range given by eps.
1210 // The resulting ratio is then returned to the calling method.
1213 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
1215 AliError("No AliTRDcalibDB instance available\n");
1220 Int_t itStep = 0; // Count iteration steps
1222 Double_t ratio = 0.5; // Start value for ratio
1223 Double_t prevRatio = 0.0; // Store previous ratio
1225 Double_t newLeftSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store left cluster signal
1226 Double_t newRightSignal[3] = { 0.0, 0.0, 0.0 }; // Array to store right cluster signal
1227 Double_t newSignal[3] = { 0.0, 0.0, 0.0 };
1229 // Start the iteration
1230 while ((TMath::Abs(prevRatio - ratio) > eps) && (itStep < 10)) {
1235 // Cluster position according to charge ratio
1236 Double_t maxLeft = (ratio*padSignal[2] - padSignal[0])
1237 / (padSignal[0] + padSignal[1] + ratio * padSignal[2]);
1238 Double_t maxRight = (padSignal[4] - (1-ratio)*padSignal[2])
1239 / ((1.0 - ratio)*padSignal[2] + padSignal[3] + padSignal[4]);
1241 // Set cluster charge ratio
1242 irc = calibration->PadResponse(1.0, maxLeft, layer, newSignal);
1243 Double_t ampLeft = padSignal[1] / newSignal[1];
1244 irc = calibration->PadResponse(1.0, maxRight, layer, newSignal);
1245 Double_t ampRight = padSignal[3] / newSignal[1];
1247 // Apply pad response to parameters
1248 irc = calibration->PadResponse(ampLeft ,maxLeft ,layer,newLeftSignal );
1249 irc = calibration->PadResponse(ampRight,maxRight,layer,newRightSignal);
1251 // Calculate new overlapping ratio
1252 ratio = TMath::Min((Double_t) 1.0
1253 ,newLeftSignal[2] / (newLeftSignal[2] + newRightSignal[0]));
1261 //_____________________________________________________________________________
1262 void AliTRDclusterizer::TailCancelation(const AliTRDrecoParam* const recoParam)
1265 // Applies the tail cancelation
1268 Int_t nexp = recoParam->GetTCnexp();
1275 TTreeSRedirector *fDebugStream = fReconstructor->GetDebugStream(AliTRDrecoParam::kClusterizer);
1276 Bool_t debugStreaming = recoParam->GetStreamLevel(AliTRDrecoParam::kClusterizer) > 7 && fReconstructor->IsDebugStreaming();
1277 while(fIndexes->NextRCIndex(iRow, iCol))
1279 // if corrupted then don't make the tail cancallation
1280 if (fCalPadStatusROC->GetStatus(iCol, iRow)) continue;
1283 for (iTime = 0; iTime < fTimeTotal; iTime++)
1284 (*fDebugStream) << "TailCancellation"
1290 // Apply the tail cancelation via the digital filter
1291 //DeConvExp(fDigits->GetDataAddress(iRow,iCol),fTimeTotal,nexp);
1292 ApplyTCTM(fDigits->GetDataAddress(iRow,iCol),fTimeTotal,nexp);
1293 } // while irow icol
1300 //_____________________________________________________________________________
1301 void AliTRDclusterizer::ApplyTCTM(Short_t *const arr, const Int_t nTime, const Int_t nexp)
1304 // Steer tail cancellation
1311 DeConvExp(arr,nTime,nexp);
1317 DeConvExp(arr,nTime,1);
1326 //_____________________________________________________________________________
1327 void AliTRDclusterizer::ConvExp(Short_t *const arr, const Int_t nTime)
1333 // Initialization (coefficient = alpha, rates = lambda)
1334 Float_t slope = 1.0;
1335 Float_t coeff = 0.5;
1339 fReconstructor->GetRecoParam()->GetTCParams(par);
1345 rate = TMath::Exp(-dt/(slope));
1347 Float_t reminder = .0;
1348 Float_t correction = 0.0;
1349 Float_t result = 0.0;
1351 for (int i = nTime-1; i >= 0; i--) {
1353 result = arr[i] + correction - fBaseline; // No rescaling
1354 arr[i] = (Short_t)(result + fBaseline + 0.5f);
1358 correction += reminder = rate * (reminder + coeff * result);
1363 //_____________________________________________________________________________
1364 void AliTRDclusterizer::DeConvExp(Short_t *const arr, const Int_t nTime, const Int_t nexp)
1367 // Tail cancellation by deconvolution for PASA v4 TRF
1371 Float_t coefficients[2];
1373 // Initialization (coefficient = alpha, rates = lambda)
1379 if (nexp == 1) { // 1 Exponentials
1385 if (nexp == 2) { // 2 Exponentials
1387 fReconstructor->GetRecoParam()->GetTCParams(par);
1388 r1 = par[0];//1.156;
1389 r2 = par[1];//0.130;
1390 c1 = par[2];//0.114;
1391 c2 = par[3];//0.624;
1394 coefficients[0] = c1;
1395 coefficients[1] = c2;
1399 rates[0] = TMath::Exp(-dt/(r1));
1400 rates[1] = (nexp == 1) ? .0 : TMath::Exp(-dt/(r2));
1402 Float_t reminder[2] = { .0, .0 };
1403 Float_t correction = 0.0;
1404 Float_t result = 0.0;
1406 for (int i = 0; i < nTime; i++) {
1408 result = arr[i] - correction - fBaseline; // No rescaling
1409 arr[i] = (Short_t)(result + fBaseline + 0.5f);
1412 for (int k = 0; k < 2; k++) {
1413 correction += reminder[k] = rates[k] * (reminder[k] + coefficients[k] * result);
1420 //_____________________________________________________________________________
1421 void AliTRDclusterizer::ResetRecPoints()
1424 // Resets the list of rec points
1428 fRecPoints->Clear();
1430 // delete fRecPoints;
1434 //_____________________________________________________________________________
1435 TClonesArray *AliTRDclusterizer::RecPoints()
1438 // Returns the list of rec points
1442 if(!(fRecPoints = AliTRDReconstructor::GetClusters())){
1443 // determine number of clusters which has to be allocated
1444 Float_t nclusters = fReconstructor->GetRecoParam()->GetNClusters();
1446 fRecPoints = new TClonesArray("AliTRDcluster", Int_t(nclusters));
1448 //SetClustersOwner(kTRUE);
1449 AliTRDReconstructor::SetClusters(0x0);
1455 //_____________________________________________________________________________
1456 TClonesArray *AliTRDclusterizer::TrackletsArray(const TString &trkltype)
1459 // Returns the array of on-line tracklets
1462 if (trkltype.Length() != 0) {
1464 fTracklets = new TClonesArray(trkltype, 200);
1466 else if (TClass::GetClass(trkltype.Data()) != fTracklets->GetClass()){
1467 fTracklets->Delete();
1469 fTracklets = new TClonesArray(trkltype, 200);
1475 //_____________________________________________________________________________
1476 TClonesArray* AliTRDclusterizer::TracksArray()
1478 // return array of GTU tracks (create TClonesArray if necessary)
1481 fTracks = new TClonesArray("AliESDTrdTrack",100);