Coverity fix.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCpvRecPoint.cxx
CommitLineData
458282ff 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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/* $Id$ */
17
702ab87e 18/* History of cvs commits:
19 *
20 * $Log$
78881c42 21 * Revision 1.26 2007/06/18 07:02:44 kharlov
22 * Change the signature of EvalLocalPosition() to obey the method virtuality from the parent class
23 *
2163a649 24 * Revision 1.25 2007/03/06 06:47:28 kharlov
25 * DP:Possibility to use actual vertex position added
702ab87e 26 */
27
458282ff 28//_________________________________________________________________________
29// RecPoint implementation for PHOS-CPV
30// An CpvRecPoint is a cluster of digits
6c8cd883 31//-- Author: Yuri Kharlov
a3dfe79c 32// (after Dmitri Peressounko (RRC KI & SUBATECH))
33// 30 October 2000
458282ff 34
35// --- ROOT system ---
e957fea8 36
458282ff 37#include "TMath.h"
b5241d61 38#include "TClonesArray.h"
458282ff 39
40// --- Standard library ---
41
458282ff 42// --- AliRoot header files ---
351dd634 43#include "AliLog.h"
e957fea8 44#include "AliPHOSGeometry.h"
45#include "AliPHOSDigit.h"
458282ff 46#include "AliPHOSCpvRecPoint.h"
88cb7938 47#include "AliPHOSLoader.h"
e957fea8 48
458282ff 49ClassImp(AliPHOSCpvRecPoint)
50
51//____________________________________________________________________________
3663622c 52AliPHOSCpvRecPoint::AliPHOSCpvRecPoint() :
53 AliPHOSEmcRecPoint(),
54 fLengX(-1),
55 fLengZ(-1)
458282ff 56{
57 // ctor
458282ff 58}
59
60//____________________________________________________________________________
3663622c 61AliPHOSCpvRecPoint::AliPHOSCpvRecPoint(const char * opt) :
62 AliPHOSEmcRecPoint(opt),
63 fLengX(-1),
64 fLengZ(-1)
73a68ccb 65{
66 // ctor
3663622c 67}
73a68ccb 68
69//____________________________________________________________________________
458282ff 70AliPHOSCpvRecPoint::~AliPHOSCpvRecPoint()
71{
72 // dtor
458282ff 73}
74
458282ff 75//____________________________________________________________________________
ad8cfaf4 76Bool_t AliPHOSCpvRecPoint::AreNeighbours(AliPHOSDigit * digit1, AliPHOSDigit * digit2 ) const
458282ff 77{
78 // Tells if (true) or not (false) two digits are neighbors)
79
80 Bool_t aren = kFALSE ;
81
6c8cd883 82 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
ed652fe0 83
458282ff 84 Int_t relid1[4] ;
85 phosgeom->AbsToRelNumbering(digit1->GetId(), relid1) ;
86
87 Int_t relid2[4] ;
88 phosgeom->AbsToRelNumbering(digit2->GetId(), relid2) ;
89
90 Int_t rowdiff = TMath::Abs( relid1[2] - relid2[2] ) ;
91 Int_t coldiff = TMath::Abs( relid1[3] - relid2[3] ) ;
92
93 if (( coldiff <= 1 ) && ( rowdiff <= 1 ) && (coldiff + rowdiff > 0))
94 aren = kTRUE ;
95
96 return aren ;
97}
98
99//____________________________________________________________________________
2a941f4e 100Int_t AliPHOSCpvRecPoint::Compare(const TObject * obj) const
458282ff 101{
102 // Compares two RecPoints according to their position in the PHOS modules
103
b5241d61 104 Float_t delta = 1 ; //Width of "Sorting row". If you changibg this
105 //value (what is senseless) change as vell delta in
106 //AliPHOSTrackSegmentMakerv* and other RecPoints...
107
458282ff 108 Int_t rv ;
109
9688c1dd 110 AliPHOSCpvRecPoint * clu = (AliPHOSCpvRecPoint *) obj ;
111
112 Int_t phosmod1 = GetPHOSMod() ;
113 Int_t phosmod2 = clu->GetPHOSMod() ;
114
115 TVector3 locpos1;
116 GetLocalPosition(locpos1) ;
117 TVector3 locpos2;
118 clu->GetLocalPosition(locpos2) ;
119
120 if(phosmod1 == phosmod2 ) {
121 Int_t rowdif = (Int_t)TMath::Ceil(locpos1.X()/delta)-(Int_t)TMath::Ceil(locpos2.X()/delta) ;
122 if (rowdif> 0)
123 rv = 1 ;
124 else if(rowdif < 0)
125 rv = -1 ;
126 else if(locpos1.Z()>locpos2.Z())
127 rv = -1 ;
128 else
129 rv = 1 ;
130 }
131
132 else {
133 if(phosmod1 < phosmod2 )
134 rv = -1 ;
135 else
136 rv = 1 ;
137 }
138
139 return rv ;
140
458282ff 141}
142
143//______________________________________________________________________________
702ab87e 144void AliPHOSCpvRecPoint::ExecuteEvent(Int_t, Int_t, Int_t ) /*const*/
458282ff 145{
b5241d61 146// // Execute action corresponding to one event
147// // This member function is called when a AliPHOSRecPoint is clicked with the locator
148// //
149// // If Left button is clicked on AliPHOSRecPoint, the digits are switched on
150// // and switched off when the mouse button is released.
151// //
458282ff 152
b5241d61 153// // static Int_t pxold, pyold;
458282ff 154
88cb7938 155// AliPHOSLoader * gime = AliPHOSLoader::GetInstance() ;
458282ff 156
b5241d61 157// static TGraph * digitgraph = 0 ;
458282ff 158
b5241d61 159// if (!gPad->IsEditable()) return;
458282ff 160
b5241d61 161// TH2F * histo = 0 ;
162// TCanvas * histocanvas ;
458282ff 163
b5241d61 164// switch (event) {
458282ff 165
b5241d61 166// case kButton1Down: {
167// AliPHOSDigit * digit ;
168// AliPHOSGeometry * phosgeom = (AliPHOSGeometry *) fGeom ;
169// Int_t iDigit;
170// Int_t relid[4] ;
458282ff 171
b5241d61 172// const Int_t kMulDigit = AliPHOSCpvRecPoint::GetDigitsMultiplicity() ;
173// Float_t * xi = new Float_t[kMulDigit] ;
174// Float_t * zi = new Float_t[kMulDigit] ;
458282ff 175
b5241d61 176// // create the histogram for the single cluster
177// // 1. gets histogram boundaries
178// Float_t ximax = -999. ;
179// Float_t zimax = -999. ;
180// Float_t ximin = 999. ;
181// Float_t zimin = 999. ;
458282ff 182
b5241d61 183// for(iDigit=0; iDigit<kMulDigit; iDigit++) {
7b7c1533 184// digit = (AliPHOSDigit *) ( gime->Digit(fDigitsList[iDigit]) ) ;
b5241d61 185// phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
186// phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]);
187// if ( xi[iDigit] > ximax )
188// ximax = xi[iDigit] ;
189// if ( xi[iDigit] < ximin )
190// ximin = xi[iDigit] ;
191// if ( zi[iDigit] > zimax )
192// zimax = zi[iDigit] ;
193// if ( zi[iDigit] < zimin )
194// zimin = zi[iDigit] ;
195// }
196// ximax += phosgeom->GetCrystalSize(0) / 2. ;
197// zimax += phosgeom->GetCrystalSize(2) / 2. ;
198// ximin -= phosgeom->GetCrystalSize(0) / 2. ;
199// zimin -= phosgeom->GetCrystalSize(2) / 2. ;
200// Int_t xdim = (int)( (ximax - ximin ) / phosgeom->GetCrystalSize(0) + 0.5 ) ;
201// Int_t zdim = (int)( (zimax - zimin ) / phosgeom->GetCrystalSize(2) + 0.5 ) ;
458282ff 202
b5241d61 203// // 2. gets the histogram title
458282ff 204
b5241d61 205// Text_t title[100] ;
206// sprintf(title,"Energy=%1.2f GeV ; Digits ; %d ", GetEnergy(), GetDigitsMultiplicity()) ;
458282ff 207
b5241d61 208// if (!histo) {
209// delete histo ;
210// histo = 0 ;
211// }
212// histo = new TH2F("cluster3D", title, xdim, ximin, ximax, zdim, zimin, zimax) ;
458282ff 213
b5241d61 214// Float_t x, z ;
215// for(iDigit=0; iDigit<kMulDigit; iDigit++) {
7b7c1533 216// digit = (AliPHOSDigit *) ( gime->Digit(fDigitsList[iDigit]) ) ;
b5241d61 217// phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
218// phosgeom->RelPosInModule(relid, x, z);
219// histo->Fill(x, z, fEnergyList[iDigit] ) ;
220// }
458282ff 221
b5241d61 222// if (!digitgraph) {
223// digitgraph = new TGraph(kMulDigit,xi,zi);
224// digitgraph-> SetMarkerStyle(5) ;
225// digitgraph-> SetMarkerSize(1.) ;
226// digitgraph-> SetMarkerColor(1) ;
227// digitgraph-> Paint("P") ;
228// }
458282ff 229
b5241d61 230// Print() ;
231// histocanvas = new TCanvas("cluser", "a single cluster", 600, 500) ;
232// histocanvas->Draw() ;
233// histo->Draw("lego1") ;
458282ff 234
b5241d61 235// delete[] xi ;
236// delete[] zi ;
458282ff 237
b5241d61 238// break;
239// }
458282ff 240
b5241d61 241// case kButton1Up:
242// if (digitgraph) {
243// delete digitgraph ;
244// digitgraph = 0 ;
245// }
246// break;
458282ff 247
b5241d61 248// }
458282ff 249}
250
251//____________________________________________________________________________
e347da7b 252void AliPHOSCpvRecPoint::EvalAll(TClonesArray * digits)
a4e98857 253{
78881c42 254 // Evaluate local coordinate assuming the vertex in (000) and no inclination
e347da7b 255 AliPHOSEmcRecPoint::EvalAll(digits) ;
ad8cfaf4 256}
257//____________________________________________________________________________
91daaf24 258void AliPHOSCpvRecPoint::EvalAll(Float_t logWeight, TVector3 &vtx, TClonesArray * digits)
259{
260 // wraps other methods
e347da7b 261 TVector3 vInc(0,1,0);
91daaf24 262 AliPHOSEmcRecPoint::EvalAll(logWeight,vtx,digits) ;
e347da7b 263 EvalLocalPosition(logWeight, vtx, digits,vInc) ;
264 EvalClusterLengths(digits) ;
91daaf24 265}
266//____________________________________________________________________________
2163a649 267void AliPHOSCpvRecPoint::EvalLocalPosition(Float_t logWeight, TVector3 & /*vtx */, TClonesArray * digits, TVector3 &/* vInc */)
ad8cfaf4 268{
269 // Calculates the center of gravity in the local PHOS-module coordinates
270
ad8cfaf4 271 Float_t wtot = 0. ;
272
273 Int_t relid[4] ;
274
275 Float_t x = 0. ;
276 Float_t z = 0. ;
277
278 AliPHOSDigit * digit ;
279
6c8cd883 280 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
88cb7938 281
ad8cfaf4 282 Int_t iDigit;
283
284 for(iDigit=0; iDigit<fMulDigit; iDigit++) {
b5241d61 285 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]);
ad8cfaf4 286
287 Float_t xi ;
288 Float_t zi ;
289 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
290 phosgeom->RelPosInModule(relid, xi, zi);
f33a3764 291 if (fAmp>0 && fEnergyList[iDigit]>0) {
292 Float_t w = TMath::Max( 0., logWeight + TMath::Log( fEnergyList[iDigit] / fAmp ) ) ;
293 x += xi * w ;
294 z += zi * w ;
295 wtot += w ;
296 }
297 else
298 AliError(Form("Wrong energy %f and/or amplitude %f\n", fEnergyList[iDigit], fAmp));
ad8cfaf4 299 }
300
301 if (wtot != 0) {
302 x /= wtot ;
303 z /= wtot ;
304 } else {
305 x = -1e6 ;
306 z = -1e6 ;
21cd0c07 307 if (fMulDigit != 0)
351dd634 308 AliWarning(Form("Too low log weight factor to evaluate cluster's center" )) ;
ad8cfaf4 309 }
310 fLocPos.SetX(x) ;
311 fLocPos.SetY(0.) ;
312 fLocPos.SetZ(z) ;
313
314}
315
316//____________________________________________________________________________
b5241d61 317void AliPHOSCpvRecPoint::EvalClusterLengths(TClonesArray * digits)
458282ff 318{
b5241d61 319 //Modified 15.03.2001 by Dmitri Peressounko
458282ff 320
458282ff 321 // Calculates the cluster lengths along X and Z axes
322 // These characteristics are needed for CPV to tune
323 // digitization+reconstruction to experimental data
324 // Yuri Kharlov. 24 October 2000
325
458282ff 326 Int_t relid[4] ;
327
328 AliPHOSDigit * digit ;
329
6c8cd883 330 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
458282ff 331
a3dfe79c 332 const Int_t kMaxLeng=20;
333 Int_t idX[kMaxLeng], idZ[kMaxLeng];
b5241d61 334 fLengX = 0;
335 fLengZ = 0;
458282ff 336 Bool_t dejavu;
337
338 for(Int_t iDigit=0; iDigit<fMulDigit; iDigit++) {
b5241d61 339 digit = (AliPHOSDigit *) digits->At(fDigitsList[iDigit]) ;
458282ff 340 Int_t absId = digit->GetId();
341 phosgeom->AbsToRelNumbering(absId, relid) ;
342
cd461ab8 343 Int_t i;
458282ff 344 dejavu=kFALSE;
b5241d61 345 for (i=0; i<fLengX; i++) if (relid[2]==idX[i]) { dejavu=kTRUE; break; }
458282ff 346 if (!dejavu) {
b5241d61 347 idX[fLengX]=relid[2];
348 fLengX++;
349 fLengX = TMath::Min(fLengX,kMaxLeng);
458282ff 350 }
351
352 dejavu=kFALSE;
b5241d61 353 for (i=0; i<fLengZ; i++) if (relid[3]==idZ[i]) { dejavu=kTRUE; break; }
458282ff 354 if (!dejavu) {
b5241d61 355 idZ[fLengZ]=relid[3];
356 fLengZ++;
357 fLengZ = TMath::Min(fLengZ,kMaxLeng);
458282ff 358 }
359 }
458282ff 360}
361
458282ff 362//____________________________________________________________________________
702ab87e 363void AliPHOSCpvRecPoint::Print(const Option_t *) const
458282ff 364{
365 // Print the list of digits belonging to the cluster
366
21cd0c07 367 TString message ;
368 message = "AliPHOSCpvRecPoint: " ;
369 message += "Digits # " ;
a7307087 370 AliInfo(message.Data()) ;
21cd0c07 371
458282ff 372 Int_t iDigit;
458282ff 373
b5241d61 374 for(iDigit=0; iDigit<fMulDigit; iDigit++)
351dd634 375 printf(" %d \n", fDigitsList[iDigit]) ;
458282ff 376
351dd634 377 printf("Energies: \n") ;
b5241d61 378 for(iDigit=0; iDigit<fMulDigit; iDigit++)
351dd634 379 printf(" %f ", fEnergyList[iDigit]) ;
b5241d61 380
21cd0c07 381 message = " Multiplicity = %d\n" ;
382 message += " Cluster Energy = %f\n" ;
383 message += " Stored at position %d\n" ;
458282ff 384
351dd634 385 printf(message.Data(), fMulDigit, fAmp, GetIndexInList() ) ;
21cd0c07 386
458282ff 387}