3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * All rights reserved. *
7 * Primary Authors: Oystein Djuvsland *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
19 * @file AliHLTPHOSClusterizer.cxx
20 * @author Oystein Djuvsland
22 * @brief Clusterizer for PHOS HLT
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
31 #include "AliHLTPHOSClusterizer.h"
32 //#include "AliHLTPHOSBase.h"
33 #include "AliHLTLogging.h"
35 #include "AliHLTPHOSRecPointContainerStruct.h"
36 #include "AliHLTPHOSRecPointDataStruct.h"
37 #include "AliHLTPHOSDigitDataStruct.h"
38 #include "AliHLTPHOSDigitContainerDataStruct.h"
39 #include "AliHLTPHOSDigitReader.h"
40 #include "TClonesArray.h"
41 #include "AliPHOSDigit.h"
42 #ifndef HAVENOT__PHOSRECOPARAMEMC // set from configure if EMC functionality not available in AliPHOSRecoParam
43 #include "AliPHOSRecoParam.h"
45 #include "AliPHOSRecoParamEmc.h"
51 ClassImp(AliHLTPHOSClusterizer);
53 AliHLTPHOSClusterizer::AliHLTPHOSClusterizer():
60 fEmcClusteringThreshold(0),
61 fEmcMinEnergyThreshold(0),
64 fDigitContainerPtr(0),
65 fMaxDigitIndexDiff(2*NZROWSMOD),
69 //See header file for documentation
70 fEmcClusteringThreshold = 0.2;
71 fEmcMinEnergyThreshold = 0.03;
72 fEmcTimeGate = 1.e-6 ;
74 fDigitReader = new AliHLTPHOSDigitReader();
78 AliHLTPHOSClusterizer::~AliHLTPHOSClusterizer()
80 //See header file for documentation
84 AliHLTPHOSClusterizer::SetRecPointDataPtr(AliHLTPHOSRecPointDataStruct* recPointDataPtr)
86 // See header file for documentation
87 fRecPointDataPtr = recPointDataPtr;
91 AliHLTPHOSClusterizer::ClusterizeEvent(AliHLTPHOSDigitHeaderStruct *digitHeader, UInt_t availableSize, UInt_t& totSize)
93 //see header file for documentation
96 fAvailableSize = availableSize;
98 fDigitReader->SetDigitHeader(digitHeader);
100 // UInt_t maxRecPointSize = sizeof(AliHLTPHOSRecPointDataStruct) + (sizeof(AliHLTPHOSDigitDataStruct) << 7); //Reasonable estimate...
102 // HLTError("Starting clusterisation");
104 //Clusterization starts
105 while((fCurrentDigit = fDigitReader->NextDigit()) != 0)
107 // HLTError("Digit with energy: %f", fCurrentDigit->fEnergy);
108 fDigitsInCluster = 0;
110 if(fCurrentDigit->fEnergy < fEmcClusteringThreshold)
115 // HLTError("Have cluster candidate (x,z): %d, %d, with energy: %f", fCurrentDigit->fX, fCurrentDigit->fZ, fCurrentDigit->fEnergy);
117 if(fAvailableSize < (sizeof(AliHLTPHOSRecPointDataStruct)))
119 HLTError("Out of buffer, stopping clusterisation");
123 // Save the starting digit
124 fStartDigit = fCurrentDigit;
125 fPreviousDigit = fStartDigit;
126 // Get the offset of the digit starting the cluster relative to the start of the digit block
127 fRecPointDataPtr->fStartDigitOffset = fDigitReader->GetCurrentDigitOffset();
128 // HLTError("Start digit offset: %d", fRecPointDataPtr->fStartDigitOffset);
129 // cout << "Start digit offset: " << fRecPointDataPtr->fStartDigitOffset << endl;
130 fDigitReader->DropDigit();
132 fRecPointDataPtr->fAmp = 0;
133 fRecPointDataPtr->fModule = fCurrentDigit->fModule;
135 fRecPointDataPtr->fAmp += fCurrentDigit->fEnergy;
140 // Scanning for the neighbours
141 if(ScanForNeighbourDigits(fRecPointDataPtr, fCurrentDigit) < 0)
146 fPreviousDigit->fMemOffsetNext = 0;
148 totSize += sizeof(AliHLTPHOSRecPointDataStruct) + (fDigitsInCluster-1)*sizeof(AliHLTPHOSDigitDataStruct);
149 HLTDebug("Initial available size: %d, used size: %d, remaining available size: %d, should be: %d", availableSize, totSize, fAvailableSize, availableSize-totSize);
151 fRecPointDataPtr->fMultiplicity = fDigitsInCluster;
152 HLTDebug("Number of digits in cluster: %d", fDigitsInCluster);
155 fDigitReader->Rewind(); // TODO: jump to the next instead of rewind
156 }//end of clusterization
162 AliHLTPHOSClusterizer::ScanForNeighbourDigits(AliHLTPHOSRecPointDataStruct* recPoint, AliHLTPHOSDigitDataStruct *digit)
164 //see header file for documentation
166 //Int_t max = TMath::Min((Int_t)fDigitContainerPtr->fNDigits, (Int_t)fMaxDigitIndexDiff+index);
167 // Int_t min = TMath::Max(0, (Int_t)(index - (Int_t)fMaxDigitIndexDiff));
169 // Int_t max = fDigitContainerPtr->fNDigits;
172 AliHLTPHOSDigitDataStruct *tmpDigit = 0;
174 fDigitReader->Rewind();
176 while((tmpDigit = fDigitReader->NextDigit()))
178 //HLTError("Checking digit (x,z): %d, %d, with energy: %f", tmpDigit->fX, tmpDigit->fZ, tmpDigit->fEnergy);
179 // HLTError("Checking digit (x,z): %d, %d, with energy: %f for neighbourship of digit (x,z): %d, %d", tmpDigit->fX, tmpDigit->fZ, tmpDigit->fEnergy, digit->fX, digit->fZ);
180 // if(tmpDigit->fEnergy > fEmcMinEnergyThreshold)
181 if(tmpDigit->fEnergy > 0.2)
183 //HLTError("Checking digit (x,z): %d, %d, with energy: %f for neighbourship of digit (x,z): %d, %d", tmpDigit->fX, tmpDigit->fZ, tmpDigit->fEnergy, digit->fX, digit->fZ);
185 // if(AreNeighbours(fStartDigit, tmpDigit))
186 if(AreNeighbours(digit, tmpDigit))
188 // HLTError("Adding digit (x,z): %d, %d, with energy: %f", tmpDigit->fX, tmpDigit->fZ, tmpDigit->fEnergy);
189 fDigitReader->DropDigit();
190 fPreviousDigit->fMemOffsetNext = reinterpret_cast<Long_t>(tmpDigit) - reinterpret_cast<Long_t>(fPreviousDigit);
191 // cout << "Digit offset: " << fPreviousDigit->fMemOffsetNext << endl;
192 // fPreviousDigit->fMemOffsetNext += tmpDigit->fMemOffsetNext;
193 recPoint->fAmp += tmpDigit->fEnergy;
194 fPreviousDigit = tmpDigit;
196 ScanForNeighbourDigits(recPoint, tmpDigit);
197 fDigitReader->SetCurrentDigit(tmpDigit);
205 AliHLTPHOSClusterizer::AreNeighbours(AliHLTPHOSDigitDataStruct* digit1,
206 AliHLTPHOSDigitDataStruct* digit2)
208 //see header file for documentation
209 if ( (digit1->fModule == digit2->fModule) /*&& (coord1[1]==coord2[1])*/ ) // inside the same PHOS module
211 Int_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ );
212 Int_t coldiff = TMath::Abs( digit1->fX - digit2->fX );
213 // HLTError("coldiff: %d, rowdiff: %d, timediff: %f", coldiff, rowdiff, TMath::Abs(digit1->fTime - digit2->fTime ));
214 if (( coldiff <= 1 && rowdiff == 0 ) || ( coldiff == 0 && rowdiff <= 1 ))
216 // cout << "Are neighbours: digit (E = " << digit1->fEnergy << ") with x = " << digit1->fX << " and z = " << digit1->fZ <<
217 // " is neighbour with digit (E = " << digit2->fEnergy << ") with x = " << digit2->fX << " and z = " << digit2->fZ << endl;
219 // if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)