]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSClusterizer.cxx
eff C++
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSClusterizer.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        * 
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Authors: Oystein Djuvsland                                     *
6  *                                                                        *
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  **************************************************************************/
15
16 /** 
17  * @file   AliHLTPHOSClusterizer.cxx
18  * @author Oystein Djuvsland
19  * @date 
20  * @brief  Clusterizer for PHOS HLT 
21  */
22
23 // see header file for class documentation
24 // or
25 // refer to README to build package
26 // or
27 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
28
29 #include "AliHLTPHOSClusterizer.h"
30 #include "AliHLTPHOSBase.h"
31 #include "AliHLTLogging.h"
32 #include "TMath.h"
33 #include "AliHLTPHOSRecPointContainerStruct.h"
34 #include "AliHLTPHOSRecPointDataStruct.h"
35 #include "AliHLTPHOSDigitDataStruct.h"
36 #include "AliHLTPHOSDigitContainerDataStruct.h"
37 #include "TClonesArray.h"
38 #include "AliPHOSGeometry.h"
39 #include "AliPHOSDigit.h"
40 #ifndef HAVE_NOT_PHOSRECOPARAMEMC // set from configure if EMC functionality not available in AliPHOSRecoParam
41 #include "AliPHOSRecoParam.h"
42 #else
43 #include "AliPHOSRecoParamEmc.h"
44 #endif
45 #include <iostream>
46
47 using namespace std;
48
49 ClassImp(AliHLTPHOSClusterizer);
50
51 AliHLTPHOSClusterizer::AliHLTPHOSClusterizer():
52   AliHLTPHOSBase(),
53   fEmcClusteringThreshold(0),
54   fEmcMinEnergyThreshold(0),
55   fEmcTimeGate(0),
56   fLogWeight(0),
57   fDigitsInCluster(0),
58   fOnlineMode(true),
59   fDigitArrayPtr(0),
60   fEmcRecPointsPtr(0),
61   fDigitPtr(0),
62   fDigitContainerPtr(0),
63   fRecPointContainerPtr(0),
64   fPHOSGeometry(0),
65   fGetterPtr(0),
66   fMaxDigitIndexDiff(2*N_ZROWS_MOD)
67   {
68   //See header file for documentation
69   fPHOSGeometry = AliPHOSGeometry::GetInstance("noCPV");
70   fEmcClusteringThreshold = 0.2;
71   fEmcMinEnergyThreshold = 0.03;
72   fEmcTimeGate = 1.e-6 ;
73   fLogWeight = 4.5;
74 }//end
75
76
77 AliHLTPHOSClusterizer::~AliHLTPHOSClusterizer()  
78 {
79   //See header file for documentation
80 }
81
82 void 
83 AliHLTPHOSClusterizer::SetRecPointContainer(AliHLTPHOSRecPointContainerStruct* recPointContainerPtr)
84   { 
85     fRecPointContainerPtr = recPointContainerPtr; 
86     fRecPointContainerPtr->fNRecPoints = 0;
87   }
88
89 void
90 AliHLTPHOSClusterizer::SetRecoParameters(AliPHOSRecoParam* /*params*/)
91 {
92   //see header file for documentation
93 #ifndef HAVE_NOT_PHOSRECOPARAMEMC // set from configure if EMC functionality not available in AliPHOSRecoParam
94   // the new AliPHOSRecoParam functions, available from revision
95   //  fEmcClusteringThreshold = params->GetEMCClusteringThreshold();
96   // fEmcMinEnergyThreshold = params->GetEMCMinE();
97   //  fLogWeight = params->GetEMCLogWeight();
98 #else
99   fEmcClusteringThreshold = params->GetClusteringThreshold();
100   fEmcMinEnergyThreshold = params->GetMinE();
101   fLogWeight = params->GetLogWeight();
102 #endif
103 }  
104
105 Int_t 
106 AliHLTPHOSClusterizer::ClusterizeEvent()
107 {
108   //see header file for documentation
109   Int_t nRecPoints = 0;
110   UInt_t i = 0;
111   AliHLTPHOSRecPointDataStruct *recPoint = 0;
112   //Clusterization starts
113   for(i = 0; i < fDigitContainerPtr->fNDigits; i++)
114     { 
115       fDigitsInCluster = 0;
116      
117       if(fDigitContainerPtr->fDigitDataStruct[i].fEnergy < fEmcClusteringThreshold)
118         {
119           continue;
120         }
121       recPoint = &(fRecPointContainerPtr->fRecPointArray[nRecPoints]);
122       recPoint->fAmp = 0;
123       recPoint->fModule = fDigitContainerPtr->fDigitDataStruct[i].fModule;
124       recPoint->fDigitsList[fDigitsInCluster] =  fDigitContainerPtr->fDigitDataStruct[i];
125       recPoint->fAmp += fDigitContainerPtr->fDigitDataStruct[i].fEnergy;
126       fDigitContainerPtr->fDigitDataStruct[i].fEnergy = 0;
127       fDigitsInCluster++;
128       nRecPoints++;
129       if(nRecPoints == 100) 
130         {
131           //      HLTWarning("Too many rec points in event. Aborting clusterisation");
132           break;
133         }
134       ScanForNeighbourDigits(i, recPoint);
135       recPoint->fMultiplicity = fDigitsInCluster;
136      
137     }//end of clusterization
138   fRecPointContainerPtr->fNRecPoints = nRecPoints;
139   return nRecPoints;
140 }
141
142 void
143 AliHLTPHOSClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTPHOSRecPointDataStruct* recPoint)
144
145 {
146   //see header file for documentation
147   UInt_t max = TMath::Min((Int_t)fDigitContainerPtr->fNDigits, (Int_t)fMaxDigitIndexDiff+index);
148   UInt_t min = TMath::Max(0, (Int_t)(index - (Int_t)fMaxDigitIndexDiff));
149   for(UInt_t j = min; j < max; j++)
150     {
151       if(fDigitContainerPtr->fDigitDataStruct[j].fEnergy > fEmcMinEnergyThreshold)
152         {
153           if(AreNeighbours(&(fDigitContainerPtr->fDigitDataStruct[index]),
154                                &(fDigitContainerPtr->fDigitDataStruct[j])))
155             {
156               recPoint->fDigitsList[fDigitsInCluster] =  fDigitContainerPtr->fDigitDataStruct[j];
157               recPoint->fAmp += fDigitContainerPtr->fDigitDataStruct[j].fEnergy;
158               fDigitContainerPtr->fDigitDataStruct[j].fEnergy = 0;            
159               fDigitsInCluster++;
160               ScanForNeighbourDigits(j, recPoint);
161             }
162         }
163     } 
164   return;
165 }
166
167 Int_t 
168 AliHLTPHOSClusterizer::AreNeighbours(AliHLTPHOSDigitDataStruct* digit1, 
169                                             AliHLTPHOSDigitDataStruct* digit2)
170 {
171   //see header file for documentation
172   if ( (digit1->fModule == digit2->fModule) /*&& (coord1[1]==coord2[1])*/ ) // inside the same PHOS module
173     { 
174       Int_t rowdiff = TMath::Abs( digit1->fZ - digit2->fZ );  
175       Int_t coldiff = TMath::Abs( digit1->fX - digit2->fX ); 
176       if (( coldiff <= 1   &&  rowdiff < 1 ) || ( coldiff < 1   &&  rowdiff <= 1 ))
177         {
178           if(TMath::Abs(digit1->fTime - digit2->fTime ) < fEmcTimeGate)
179             {
180               return 1; 
181             }
182         }
183     }
184   return 0;
185 }