+ AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
+ dl->WriteData("OVERWRITE");
+ //dl->Unload();
+ delete [] leaves;
+
+ return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::ReadDigits()
+{
+ //
+ // Reads the digits arrays from the input aliroot file
+ //
+
+ if (!fRunLoader) {
+ AliError("No run loader available");
+ return kFALSE;
+ }
+
+ AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
+ if (!loader->TreeD()) {
+ loader->LoadDigits();
+ }
+
+ // Read in the digit arrays
+ return (fDigitsManager->ReadDigits(loader->TreeD()));
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::ReadDigits(TTree *digitsTree)
+{
+ //
+ // Reads the digits arrays from the input tree
+ //
+
+ // Read in the digit arrays
+ return (fDigitsManager->ReadDigits(digitsTree));
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::ReadDigits(AliRawReader *rawReader)
+{
+ //
+ // Reads the digits arrays from the ddl file
+ //
+
+ AliTRDrawData raw;
+ fDigitsManager = raw.Raw2Digits(rawReader);
+
+ return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::MakeClusters()
+{
+ //
+ // Creates clusters from digits
+ //
+
+ // Propagate info from the digits manager
+ if (TestBit(kLabels)){
+ SetBit(kLabels, fDigitsManager->UsesDictionaries());
+ }
+
+ Bool_t fReturn = kTRUE;
+ for (Int_t i = 0; i < AliTRDgeometry::kNdet; i++){
+
+ AliTRDarrayADC *digitsIn = (AliTRDarrayADC*) fDigitsManager->GetDigits(i); //mod
+ // This is to take care of switched off super modules
+ if (!digitsIn->HasData()) continue;
+ digitsIn->Expand();
+ digitsIn->DeleteNegatives(); // Restore digits array to >=0 values
+ AliTRDSignalIndex* indexes = fDigitsManager->GetIndexes(i);
+ if (indexes->IsAllocated() == kFALSE){
+ fDigitsManager->BuildIndexes(i);
+ }
+
+ Bool_t fR = kFALSE;
+ if (indexes->HasEntry()){
+ if (TestBit(kLabels)){
+ for (Int_t iDict = 0; iDict < AliTRDdigitsManager::kNDict; iDict++){
+ AliTRDarrayDictionary *tracksIn = 0; //mod
+ tracksIn = (AliTRDarrayDictionary *) fDigitsManager->GetDictionary(i,iDict); //mod
+ tracksIn->Expand();
+ }
+ }
+ fR = MakeClusters(i);
+ fReturn = fR && fReturn;
+ }
+
+ //if (fR == kFALSE){
+ // if(IsWritingClusters()) WriteClusters(i);
+ // ResetRecPoints();
+ //}
+
+ // No compress just remove
+ fDigitsManager->RemoveDigits(i);
+ fDigitsManager->RemoveDictionaries(i);
+ fDigitsManager->ClearIndexes(i);
+ }
+ fReconstructor->SetDigitsParam(fDigitsManager->GetDigitsParam());
+
+ if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
+
+ AliInfo(Form("Number of found clusters : %d", RecPoints()->GetEntriesFast()));
+
+ return fReturn;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::Raw2Clusters(AliRawReader *rawReader)
+{
+ //
+ // Creates clusters from raw data
+ //
+
+ return Raw2ClustersChamber(rawReader);
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::Raw2ClustersChamber(AliRawReader *rawReader)
+{
+ //
+ // Creates clusters from raw data
+ //
+
+ // Create the digits manager
+ if (!fDigitsManager){
+ SetBit(knewDM, kTRUE);
+ fDigitsManager = new AliTRDdigitsManager(kTRUE);
+ fDigitsManager->CreateArrays();
+ }
+
+ fDigitsManager->SetUseDictionaries(TestBit(kLabels));
+
+ // tracklet container for raw tracklet writing
+ if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
+ // maximum tracklets for one HC
+ const Int_t kTrackletChmb=256;
+ fTrackletContainer = new UInt_t *[2];
+ fTrackletContainer[0] = new UInt_t[kTrackletChmb];
+ fTrackletContainer[1] = new UInt_t[kTrackletChmb];
+ }
+
+ if(!fRawStream)
+ fRawStream = AliTRDrawStreamBase::GetRawStream(rawReader);
+ else
+ fRawStream->SetReader(rawReader);
+
+ if(fReconstructor->IsHLT()){
+ fRawStream->SetSharedPadReadout(kFALSE);
+ fRawStream->SetNoErrorWarning();
+ }
+
+ AliDebug(1,Form("Stream version: %s", fRawStream->IsA()->GetName()));
+
+ Int_t det = 0;
+ while ((det = fRawStream->NextChamber(fDigitsManager,fTrackletContainer)) >= 0){
+ Bool_t iclusterBranch = kFALSE;
+ if (fDigitsManager->GetIndexes(det)->HasEntry()){
+ iclusterBranch = MakeClusters(det);
+ }
+
+ fDigitsManager->ClearArrays(det);
+
+ if (!fReconstructor->IsWritingTracklets()) continue;
+ if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
+ }
+ fReconstructor->SetDigitsParam(fDigitsManager->GetDigitsParam());
+
+ if (fTrackletContainer){
+ delete [] fTrackletContainer[0];
+ delete [] fTrackletContainer[1];
+ delete [] fTrackletContainer;
+ fTrackletContainer = NULL;
+ }
+
+ if(fReconstructor->IsWritingClusters()) WriteClusters(-1);
+
+ if(!TestBit(knewDM)){
+ delete fDigitsManager;
+ fDigitsManager = NULL;
+ delete fRawStream;
+ fRawStream = NULL;
+ }
+
+ AliInfo(Form("Number of found clusters : %d", fNoOfClusters));
+ return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+UChar_t AliTRDclusterizer::GetStatus(Short_t &signal)
+{
+ //
+ // Check if a pad is masked
+ //
+
+ UChar_t status = 0;
+
+ if(signal>0 && TESTBIT(signal, 10)){
+ CLRBIT(signal, 10);
+ for(int ibit=0; ibit<4; ibit++){
+ if(TESTBIT(signal, 11+ibit)){
+ SETBIT(status, ibit);
+ CLRBIT(signal, 11+ibit);
+ }
+ }
+ }
+ return status;
+}
+
+//_____________________________________________________________________________
+void AliTRDclusterizer::SetPadStatus(const UChar_t status, UChar_t &out) const {
+ //
+ // Set the pad status into out
+ // First three bits are needed for the position encoding
+ //
+ out |= status << 3;
+}
+
+//_____________________________________________________________________________
+UChar_t AliTRDclusterizer::GetPadStatus(UChar_t encoding) const {
+ //
+ // return the staus encoding of the corrupted pad
+ //
+ return static_cast<UChar_t>(encoding >> 3);
+}
+
+//_____________________________________________________________________________
+Int_t AliTRDclusterizer::GetCorruption(UChar_t encoding) const {
+ //
+ // Return the position of the corruption
+ //
+ return encoding & 7;
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::MakeClusters(Int_t det)
+{
+ //
+ // Generates the cluster.
+ //
+
+ // Get the digits
+ fDigits = (AliTRDarrayADC *) fDigitsManager->GetDigits(det); //mod
+ fBaseline = fDigitsManager->GetDigitsParam()->GetADCbaseline();
+
+ // This is to take care of switched off super modules
+ if (!fDigits->HasData()) return kFALSE;
+
+ fIndexes = fDigitsManager->GetIndexes(det);
+ if (fIndexes->IsAllocated() == kFALSE) {
+ AliError("Indexes do not exist!");
+ return kFALSE;
+ }
+
+ AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
+ if (!calibration) {
+ AliFatal("No AliTRDcalibDB instance available\n");
+ return kFALSE;
+ }
+
+ if (!fReconstructor){
+ AliError("Reconstructor not set\n");
+ return kFALSE;
+ }
+
+ fMaxThresh = fReconstructor->GetRecoParam()->GetClusMaxThresh();
+ fSigThresh = fReconstructor->GetRecoParam()->GetClusSigThresh();
+ fMinMaxCutSigma = fReconstructor->GetRecoParam()->GetMinMaxCutSigma();
+ fMinLeftRightCutSigma = fReconstructor->GetRecoParam()->GetMinLeftRightCutSigma();
+
+ Int_t istack = fIndexes->GetStack();
+ fLayer = fIndexes->GetLayer();
+ Int_t isector = fIndexes->GetSM();
+
+ // Start clustering in the chamber
+
+ fDet = AliTRDgeometry::GetDetector(fLayer,istack,isector);
+ if (fDet != det) {
+ AliError("Strange Detector number Missmatch!");
+ return kFALSE;
+ }
+
+ AliDebug(2, Form("Det[%d] @ Sec[%d] Stk[%d] Ly[%d]", fDet, isector, istack, fLayer));
+
+ // TRD space point transformation
+ fTransform->SetDetector(det);
+
+ Int_t iGeoLayer = AliGeomManager::kTRD1 + fLayer;
+ Int_t iGeoModule = istack + AliTRDgeometry::Nstack() * isector;
+ fVolid = AliGeomManager::LayerToVolUID(iGeoLayer,iGeoModule);
+
+ if(fReconstructor->IsProcessingTracklets() && fTrackletContainer)
+ AddTrackletsToArray();
+
+ fColMax = fDigits->GetNcol();
+ //Int_t nRowMax = fDigits->GetNrow();
+ fTimeTotal = fDigits->GetNtime();
+
+ // Check consistency between OCDB and raw data
+ Int_t nTimeOCDB = calibration->GetNumberOfTimeBinsDCS();
+ if ((nTimeOCDB > -1) &&
+ (fTimeTotal != nTimeOCDB)) {
+ AliError(Form("Number of timebins does not match OCDB value (RAW[%d] OCDB[%d])"
+ ,fTimeTotal,calibration->GetNumberOfTimeBinsDCS()));
+ }
+
+ // Detector wise calibration object for the gain factors
+ const AliTRDCalDet *calGainFactorDet = calibration->GetGainFactorDet();
+ // Calibration object with pad wise values for the gain factors
+ fCalGainFactorROC = calibration->GetGainFactorROC(fDet);
+ // Calibration value for chamber wise gain factor
+ fCalGainFactorDetValue = calGainFactorDet->GetValue(fDet);
+
+ // Detector wise calibration object for the noise
+ const AliTRDCalDet *calNoiseDet = calibration->GetNoiseDet();
+ // Calibration object with pad wise values for the noise
+ fCalNoiseROC = calibration->GetNoiseROC(fDet);
+ // Calibration value for chamber wise noise
+ fCalNoiseDetValue = calNoiseDet->GetValue(fDet);
+
+ // Calibration object with the pad status
+ fCalPadStatusROC = calibration->GetPadStatusROC(fDet);
+
+ SetBit(kLUT, fReconstructor->GetRecoParam()->UseLUT());
+ SetBit(kGAUS, fReconstructor->GetRecoParam()->UseGAUS());
+ SetBit(kHLT, fReconstructor->IsHLT());
+
+ firstClusterROC = -1;
+ fClusterROC = 0;
+
+ // Apply the gain and the tail cancelation via digital filter
+ if(fReconstructor->GetRecoParam()->UseTailCancelation()) TailCancelation();
+
+ MaxStruct curr, last;
+ Int_t nMaximas = 0, nCorrupted = 0;
+
+ // Here the clusterfining is happening
+
+ for(curr.time = 0; curr.time < fTimeTotal; curr.time++){
+ while(fIndexes->NextRCIndex(curr.row, curr.col)){
+ if(IsMaximum(curr, curr.padStatus, &curr.signals[0])){
+ if(last.row>-1){
+ if(curr.time==last.time && curr.row==last.row && curr.col==last.col+2) FivePadCluster(last, curr);
+ CreateCluster(last);
+ }
+ last=curr; curr.fivePad=kFALSE;