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