]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSClusterAnalyser.cxx
adding Copy and Clone methods inherited from TObject for abstract access and
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSClusterAnalyser.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * All rights reserved.                                                   *
6  *                                                                        *
7  * Primary Authors: Oystein Djuvsland                                     *
8  *                                                                        *
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  **************************************************************************/
17
18 /** 
19  * @file   AliHLTPHOSClusterAnalyser.cxx
20  * @author Oystein Djuvsland
21  * @date 
22  * @brief  Cluster analyser for PHOS HLT 
23  */
24
25 // see header file for class documentation
26 // or
27 // refer to README to build package
28 // or
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31 #include "AliHLTPHOSClusterAnalyser.h"
32 #include "AliHLTPHOSRecPointHeaderStruct.h"
33 #include "AliHLTPHOSRecPointDataStruct.h"
34 #include "AliHLTPHOSCaloClusterHeaderStruct.h"
35 #include "AliHLTPHOSCaloClusterDataStruct.h"
36 #include "AliHLTPHOSPhysicsAnalyzer.h"
37 #include "AliPHOSGeometry.h"
38 #include "TMath.h"
39
40 ClassImp(AliHLTPHOSClusterAnalyser);
41
42 AliHLTPHOSClusterAnalyser::AliHLTPHOSClusterAnalyser() :
43   AliHLTPHOSBase(),
44   fLogWeight(0),
45   fRecPointDataPtr(0),
46   fNRecPoints(0),
47   fCaloClusterDataPtr(0),
48   fCaloClusterHeaderPtr(0),
49   fPHOSGeometry(0),
50   fAnalyzerPtr(0),
51   fDoClusterFit(false),
52   fHaveCPVInfo(false),
53   fDoPID(false),
54   fHaveDistanceToBadChannel(false)
55 {
56   //See header file for documentation
57   fLogWeight = 4.5;
58
59   fAnalyzerPtr = new AliHLTPHOSPhysicsAnalyzer();
60   fPHOSGeometry = AliPHOSGeometry::GetInstance("noCPV");
61 }
62
63 AliHLTPHOSClusterAnalyser::~AliHLTPHOSClusterAnalyser() 
64 {
65 }
66
67 void 
68 AliHLTPHOSClusterAnalyser::SetCaloClusterDataPtr(AliHLTPHOSCaloClusterDataStruct *caloClusterDataPtr)
69
70   //see header file for documentation
71   fCaloClusterDataPtr = caloClusterDataPtr; 
72 }
73 void
74 AliHLTPHOSClusterAnalyser::SetRecPointDataPtr(AliHLTPHOSRecPointHeaderStruct *recPointDataPtr)
75
76   fNRecPoints = recPointDataPtr->fNRecPoints;
77   fRecPointDataPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(reinterpret_cast<Char_t*>(recPointDataPtr)+sizeof(AliHLTPHOSRecPointHeaderStruct)); 
78 }
79
80 Int_t
81 AliHLTPHOSClusterAnalyser::CalculateCenterOfGravity()
82 {
83   //see header file for documentation
84   Float_t wtot = 0.;
85   Float_t x = 0.;
86   Float_t z = 0.;
87   Float_t xi = 0.;
88   Float_t zi = 0.;
89
90   AliHLTPHOSDigitDataStruct *digit = 0;
91   //AliPHOSGeometry * phosgeom =  AliPHOSGeometry::GetInstance() ;
92
93   AliHLTPHOSRecPointDataStruct *recPoint = fRecPointDataPtr;
94
95   UInt_t iDigit = 0;
96
97   for(Int_t iRecPoint=0; iRecPoint < fNRecPoints; iRecPoint++) 
98     {
99       digit = &(recPoint->fDigits);
100       for(iDigit = 0; iDigit < recPoint->fMultiplicity; iDigit++)
101         {
102           
103           xi = digit->fX;
104           zi = digit->fZ;
105           //cout << "COG digits (x:z:amp:time): " << xi << " : " << zi << " : " << digit->fEnergy << " : " << digit->fTime << endl;
106           if (recPoint->fAmp > 0 && digit->fEnergy > 0) 
107             {
108               Float_t w = TMath::Max( 0., fLogWeight + TMath::Log( digit->fEnergy / recPoint->fAmp ) ) ;
109               x    += xi * w ;
110               z    += zi * w ;
111               wtot += w ;
112             }
113           digit++;
114         }
115       //cout << endl;
116       if (wtot>0) 
117         {
118           recPoint->fX = x/wtot ;
119           recPoint->fZ = z/wtot ;
120         }
121       else
122         {
123           recPoint->fAmp = 0;
124         }
125       recPoint = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(digit);
126     }
127   return 0;
128 }
129
130
131 Int_t 
132 AliHLTPHOSClusterAnalyser::CalculateRecPointMoments()
133 {
134   //See header file for documentation
135   return 0;
136 }
137
138 Int_t 
139 AliHLTPHOSClusterAnalyser::CalculateClusterMoments(AliHLTPHOSRecPointDataStruct */*recPointPtr*/, AliHLTPHOSCaloClusterDataStruct* /*clusterPtr*/)
140 {
141   //See header file for documentation
142   return 0;
143 }
144
145
146 Int_t 
147 AliHLTPHOSClusterAnalyser::DeconvoluteClusters()
148 {
149   //See header file for documentation
150   return 0;
151 }
152
153 Int_t 
154 AliHLTPHOSClusterAnalyser::CreateClusters(UInt_t availableSize, UInt_t& totSize)
155 {
156   //See header file for documentation
157
158   UInt_t maxClusterSize = sizeof(AliHLTPHOSCaloClusterDataStruct) + (6 << 7); //Reasonable estimate... (6 = sizeof(Short_t) + sizeof(Float_t)
159
160   AliHLTPHOSRecPointDataStruct* recPointPtr = fRecPointDataPtr;
161   AliHLTPHOSDigitDataStruct* digitPtr = &(recPointPtr->fDigits);  
162  
163   AliHLTPHOSCaloClusterDataStruct* caloClusterPtr = fCaloClusterDataPtr;
164   UShort_t* cellIDPtr = &(caloClusterPtr->fCellsAbsId);
165   Float_t* cellAmpFracPtr = &(caloClusterPtr->fCellsAmpFraction);
166   
167   Float_t localPos[2];
168
169   Float_t globalPos[3];
170   Int_t id = -1;
171   
172   //fPHOSGeometry = AliPHOSGeometry::GetInstance("noCPV");
173
174   for(Int_t i = 0; i < fNRecPoints; i++) //FIXME needs fix when we start unfolding (number of clusters not necessarily same as number of recpoints gotten from the clusterizer
175     {
176       
177       if(availableSize < (totSize + maxClusterSize)) 
178         {
179           return -1; //Might get out of buffer, exiting
180         }
181       localPos[0] = recPointPtr->fX;
182       localPos[1] = recPointPtr->fZ;
183       
184       fAnalyzerPtr->GlobalPosition( localPos, globalPos, recPointPtr->fModule);
185
186       caloClusterPtr->fGlobalPos[0] = globalPos[0];
187       caloClusterPtr->fGlobalPos[1] = globalPos[1];
188       caloClusterPtr->fGlobalPos[2] = globalPos[2];
189
190       //cout << "Local Position (x:z:module): " << localPos[0] << " : "<< localPos[1] << " : " << recPointPtr->fModule << endl;
191
192       //cout << "Global Position (x:y:z): " << globalPos[0] << " : "<< globalPos[1] << " : " << globalPos[2] << endl << endl;
193
194       caloClusterPtr->fNCells = recPointPtr->fMultiplicity;
195   
196       cellIDPtr = &(caloClusterPtr->fCellsAbsId);
197       cellAmpFracPtr = &(caloClusterPtr->fCellsAmpFraction);
198      
199       for(UInt_t j = 0; j < caloClusterPtr->fNCells; j++)
200         {
201           // fPHOSGeometry->RelPosToAbsId((Int_t)(recPointPtr->fModule + 1), (double)(digitPtr->fX), (double)(digitPtr->fZ), id);
202           *cellIDPtr = id;
203           *cellAmpFracPtr = digitPtr->fEnergy/recPointPtr->fAmp;
204           digitPtr++;
205           cellIDPtr = reinterpret_cast<UShort_t*>(reinterpret_cast<char*>(cellAmpFracPtr) + sizeof(Float_t)); 
206           cellAmpFracPtr = reinterpret_cast<Float_t*>(reinterpret_cast<char*>(cellIDPtr) + sizeof(Short_t)); 
207         }
208
209       caloClusterPtr->fEnergy = recPointPtr->fAmp;
210       
211       if(fDoClusterFit)
212         {
213           FitCluster(recPointPtr);
214         }
215       else
216         {
217           caloClusterPtr->fDispersion = 0;
218           caloClusterPtr->fFitQuality = 0;
219           caloClusterPtr->fM20 = 0;
220           caloClusterPtr->fM02 = 0;
221           //      caloClusterPtr->fM11 = 0;
222         }
223       if(fHaveCPVInfo)
224         {
225           caloClusterPtr->fEmcCpvDistance = GetCPVDistance(recPointPtr);
226         }
227       else
228         {
229           caloClusterPtr->fEmcCpvDistance = -1;
230         }
231       if(fDoPID)
232         {
233           DoParticleIdentification(caloClusterPtr);
234         }
235       else
236         {
237           for(Int_t k = 0; k < AliPID::kSPECIESN; k++)
238             {
239               caloClusterPtr->fPID[k] = 0;
240             }
241         }
242       if(fHaveDistanceToBadChannel)
243         {
244           caloClusterPtr->fDistanceToBadChannel = GetDistanceToBadChannel(caloClusterPtr);
245         }
246       else
247         {
248           caloClusterPtr->fDistanceToBadChannel = -1;
249         }
250
251       caloClusterPtr->fClusterType = '\0';
252       totSize += sizeof(AliHLTPHOSCaloClusterDataStruct) + (caloClusterPtr->fNCells)*(sizeof(Short_t) +sizeof(Float_t)-1);   
253
254       caloClusterPtr = reinterpret_cast<AliHLTPHOSCaloClusterDataStruct*>(cellAmpFracPtr);
255       recPointPtr = reinterpret_cast<AliHLTPHOSRecPointDataStruct*>(digitPtr);
256       digitPtr = &(recPointPtr->fDigits);  
257     }
258  
259   return fNRecPoints;
260
261 }
262