Coverity 19426
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRecPoint.cxx
CommitLineData
d15a28e7 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 **************************************************************************/
b2a60966 15/* $Id$ */
d15a28e7 16//_________________________________________________________________________
b2a60966 17// Base Class for PHOS Reconstructed Points
2f04ed65 18// Why should I put meaningless comments
19// just to satisfy
20// the code checker
6c8cd883 21//-- Author: Gines Martinez (SUBATECH)
d15a28e7 22
23// --- ROOT system ---
9f616d61 24#include "TPad.h"
e957fea8 25#include "TGraph.h"
26#include "TPaveText.h"
2731cd1e 27#include "TClonesArray.h"
e4517abc 28#include "TGeoMatrix.h"
d15a28e7 29
30// --- Standard library ---
31
32// --- AliRoot header files ---
1c4f25fb 33#include "AliLog.h"
c307c629 34#include "AliPHOSLoader.h"
d15a28e7 35#include "AliPHOSGeometry.h"
36#include "AliPHOSDigit.h"
37#include "AliPHOSRecPoint.h"
b48eb81e 38#include "AliGeomManager.h"
9f616d61 39
d15a28e7 40ClassImp(AliPHOSRecPoint)
41
42
43//____________________________________________________________________________
44AliPHOSRecPoint::AliPHOSRecPoint()
9ee9f78d 45 : AliCluster(),fPHOSMod(0),
85d85a6d 46 fMulTrack(0),fMaxDigit(100),fMulDigit(0),fMaxTrack(200),
9ee9f78d 47 fDigitsList(0),fTracksList(0),fAmp(0),
48 fIndexInList(-1), // to be set when the point is already stored
b7575333 49 fLocPos(0,0,0)
d15a28e7 50{
b2a60966 51 // ctor
52
d15a28e7 53}
54
55//____________________________________________________________________________
9ee9f78d 56AliPHOSRecPoint::AliPHOSRecPoint(const char * )
57 : AliCluster(),fPHOSMod(0),
58 fMulTrack(0),fMaxDigit(100),fMulDigit(0),fMaxTrack(200),
85d85a6d 59 fDigitsList(new Int_t[fMaxDigit]),fTracksList(new Int_t[fMaxTrack]),fAmp(0),
9ee9f78d 60 fIndexInList(-1), // to be set when the point is already stored
b7575333 61 fLocPos(0,0,0)
9ee9f78d 62
73a68ccb 63{
64 // ctor
65
55fe9d13 66}
9ee9f78d 67//_______________________________________________________________________
68AliPHOSRecPoint::~AliPHOSRecPoint()
69{
70 // dtor
71
9ee9f78d 72 delete [] fDigitsList ;
73 delete [] fTracksList ;
74
75}
76//____________________________________________________________________________
77AliPHOSRecPoint::AliPHOSRecPoint(const AliPHOSRecPoint &rp) :
78 AliCluster(rp),
79 fPHOSMod(rp.fPHOSMod),fMulTrack(rp.fMulTrack),fMaxDigit(rp.fMaxDigit),
25779c68 80 fMulDigit(rp.fMulDigit),fMaxTrack(rp.fMaxTrack),fDigitsList(0x0),
81 fTracksList(0x0),fAmp(rp.fAmp),fIndexInList(rp.fIndexInList),
b7575333 82 fLocPos(rp.fLocPos)
9ee9f78d 83{
84 //copy ctor
55fe9d13 85
25779c68 86 if (rp.fMulDigit>0) fDigitsList = new Int_t[rp.fMulDigit];
85d85a6d 87 for(Int_t i=0; i<fMulDigit; i++)
9ee9f78d 88 fDigitsList[i] = rp.fDigitsList[i];
89
25779c68 90 if (rp.fMulTrack>0) fTracksList = new Int_t[rp.fMulTrack];
85d85a6d 91 for(Int_t i=0; i<fMulTrack; i++)
9ee9f78d 92 fTracksList[i] = rp.fTracksList[i];
93
94}
95//____________________________________________________________________________
96AliPHOSRecPoint& AliPHOSRecPoint::operator= (const AliPHOSRecPoint &rp)
97{
98 if(&rp == this) return *this;
99
f4971b47 100 fPHOSMod = rp.fPHOSMod;
101 fMulTrack = rp.fMulTrack;
102 fMaxDigit = rp.fMaxDigit;
103 fMulDigit = rp.fMulDigit;
104 fMaxTrack = rp.fMaxTrack;
105 fAmp = rp.fAmp;
9ee9f78d 106 fIndexInList = rp.fIndexInList;
107 fLocPos = rp.fLocPos;
9ee9f78d 108
f4971b47 109 if (fDigitsList != 0) delete [] fDigitsList;
526b9af9 110 if (rp.fMulDigit>0) fDigitsList = new Int_t[rp.fMulDigit];
9ee9f78d 111 for(Int_t i=0; i<fMaxDigit; i++)
112 fDigitsList[i] = rp.fDigitsList[i];
113
f4971b47 114 if (fTracksList != 0) delete [] fTracksList;
526b9af9 115 if (rp.fMulTrack>0) fTracksList = new Int_t[rp.fMulTrack];
9ee9f78d 116 for(Int_t i=0; i<fMaxTrack; i++)
117 fTracksList[i] = rp.fTracksList[i];
118
119 return *this;
120}
55fe9d13 121//____________________________________________________________________________
9f616d61 122Int_t AliPHOSRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
123{
b2a60966 124 // Compute distance from point px,py to a AliPHOSRecPoint considered as a Tmarker
125 // Compute the closest distance of approach from point px,py to this marker.
126 // The distance is computed in pixels units.
127
128 TVector3 pos(0.,0.,0.) ;
129 GetLocalPosition( pos) ;
130 Float_t x = pos.X() ;
131 Float_t y = pos.Z() ;
132 const Int_t kMaxDiff = 10;
133 Int_t pxm = gPad->XtoAbsPixel(x);
134 Int_t pym = gPad->YtoAbsPixel(y);
135 Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
136
137 if (dist > kMaxDiff) return 9999;
138 return dist;
9f616d61 139}
6ad0bfa0 140
9f616d61 141//___________________________________________________________________________
142 void AliPHOSRecPoint::Draw(Option_t *option)
143 {
6ad0bfa0 144 // Draw this AliPHOSRecPoint with its current attributes
145
146 AppendPad(option);
9f616d61 147 }
148
149//______________________________________________________________________________
8f2a3661 150void AliPHOSRecPoint::ExecuteEvent(Int_t event, Int_t, Int_t)
9f616d61 151{
6ad0bfa0 152 // Execute action corresponding to one event
153 // This member function is called when a AliPHOSRecPoint is clicked with the locator
154 //
155 // If Left button is clicked on AliPHOSRecPoint, the digits are switched on
156 // and switched off when the mouse button is released.
9f616d61 157
158 // static Int_t pxold, pyold;
159
b2a60966 160 static TGraph * digitgraph = 0 ;
161 static TPaveText* clustertext = 0 ;
162
163 if (!gPad->IsEditable()) return;
9f616d61 164
b2a60966 165 switch (event) {
166
167
168 case kButton1Down:{
169 AliPHOSDigit * digit ;
88cb7938 170
6c8cd883 171 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance() ;
7b7c1533 172
b2a60966 173 Int_t iDigit;
174 Int_t relid[4] ;
31aa6d6c 175
88714635 176 const Int_t kMulDigit=AliPHOSRecPoint::GetDigitsMultiplicity() ;
177 Float_t * xi = new Float_t [kMulDigit] ;
178 Float_t * zi = new Float_t [kMulDigit] ;
b2a60966 179
88714635 180 for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
4696e514 181 Fatal("AliPHOSRecPoint::ExecuteEvent", "-> Something wrong with the code");
7a9d98f9 182 digit = 0 ; //dynamic_cast<AliPHOSDigit *>((fDigitsList)[iDigit]);
b2a60966 183 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
184 phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]) ;
185 }
186
187 if (!digitgraph) {
188 digitgraph = new TGraph(fMulDigit,xi,zi);
189 digitgraph-> SetMarkerStyle(5) ;
190 digitgraph-> SetMarkerSize(1.) ;
191 digitgraph-> SetMarkerColor(1) ;
192 digitgraph-> Draw("P") ;
193 }
194 if (!clustertext) {
195
196 TVector3 pos(0.,0.,0.) ;
197 GetLocalPosition(pos) ;
198 clustertext = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+50,pos.Z()+35,"") ;
199 Text_t line1[40] ;
200 Text_t line2[40] ;
3da0f212 201 snprintf(line1,40,"Energy=%1.2f GeV",GetEnergy()) ;
202 snprintf(line2,40,"%d Digits",GetDigitsMultiplicity()) ;
b2a60966 203 clustertext ->AddText(line1) ;
204 clustertext ->AddText(line2) ;
205 clustertext ->Draw("");
206 }
207 gPad->Update() ;
a8c47ab6 208 Print("dummy") ;
31aa6d6c 209 delete[] xi ;
210 delete[] zi ;
211 }
b2a60966 212
31aa6d6c 213break;
b2a60966 214
215 case kButton1Up:
216 if (digitgraph) {
217 delete digitgraph ;
218 digitgraph = 0 ;
219 }
220 if (clustertext) {
221 delete clustertext ;
222 clustertext = 0 ;
223 }
224
225 break;
226
9f616d61 227 }
9f616d61 228}
ad8cfaf4 229//____________________________________________________________________________
308fb942 230void AliPHOSRecPoint::EvalAll(TClonesArray * /* digits */)
88cb7938 231{
ad8cfaf4 232 //evaluates (if necessary) all RecPoint data members
9f616d61 233
ad8cfaf4 234}
88cb7938 235
d15a28e7 236//____________________________________________________________________________
2731cd1e 237void AliPHOSRecPoint::EvalPHOSMod(AliPHOSDigit * digit)
b2a60966 238{
239 // Returns the PHOS module in which the RecPoint is found
83974468 240
2731cd1e 241 if( fPHOSMod == 0){
ad8cfaf4 242 Int_t relid[4] ;
88cb7938 243
9a2cdbdf 244 AliPHOSGeometry * phosgeom = (AliPHOSGeometry::GetInstance());
d15a28e7 245
92862013 246 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
d15a28e7 247 fPHOSMod = relid[0];
2731cd1e 248 }
d15a28e7 249}
6ad0bfa0 250
4b45b217 251//____________________________________________________________________________
e8d02863 252void AliPHOSRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrixF & gmat) const
4b45b217 253{
254 // returns the position of the cluster in the global reference system of ALICE
255 // and the uncertainty on this position
9ee9f78d 256
c307c629 257 AliPHOSGeometry * phosgeom = (AliPHOSGeometry::GetInstance());
258 phosgeom->GetGlobalPHOS(this, gpos, gmat);
9ee9f78d 259
4b45b217 260}
261
cf239357 262//______________________________________________________________________________
9f616d61 263void AliPHOSRecPoint::Paint(Option_t *)
264{
b2a60966 265 // Paint this ALiRecPoint as a TMarker with its current attributes
266
267 TVector3 pos(0.,0.,0.) ;
268 GetLocalPosition(pos) ;
269 Coord_t x = pos.X() ;
270 Coord_t y = pos.Z() ;
271 Color_t markercolor = 1 ;
272 Size_t markersize = 1. ;
273 Style_t markerstyle = 5 ;
274
275 if (!gPad->IsBatch()) {
276 gVirtualX->SetMarkerColor(markercolor) ;
277 gVirtualX->SetMarkerSize (markersize) ;
278 gVirtualX->SetMarkerStyle(markerstyle) ;
279 }
280 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
281 gPad->PaintPolyMarker(1,&x,&y,"") ;
9f616d61 282}
88cb7938 283//______________________________________________________________________________
9ee9f78d 284void AliPHOSRecPoint::GetLocalPosition(TVector3 & pos) const
285{
286 // returns the position of the cluster in the local reference system
287 // of the sub-detector
288
289 pos = fLocPos;
290}
b48eb81e 291
292//____________________________________________________________________________
293void AliPHOSRecPoint::EvalLocal2TrackingCSTransform()
294{
295 //Evaluates local to "tracking" c.s. transformation (B.P.).
296 //All evaluations should be completed before calling for this function.
297 //See ALICE PPR Chapter 5 p.18 for "tracking" c.s. definition,
298 //or just ask Jouri Belikov. :)
299
300 if(IsEmc()) {
301 SetVolumeId(AliGeomManager::LayerToVolUID(AliGeomManager::kPHOS1,GetPHOSMod()-1));
302 }
303 else
76e42795 304 SetVolumeId(AliGeomManager::LayerToVolUID(AliGeomManager::kPHOS2,GetPHOSMod()-1));
b48eb81e 305
7af865cb 306 Double_t lxyz[3] = {fLocPos.X(),fLocPos.Y(),fLocPos.Z()};
b48eb81e 307 Double_t txyz[3] = {0,0,0};
7af865cb 308 Double_t dy;
309 Double_t crystalShift;
310
9a2cdbdf 311 AliPHOSGeometry * phosgeom = AliPHOSGeometry::GetInstance();
7af865cb 312 AliPHOSEMCAGeometry* geoEMCA = phosgeom->GetEMCAGeometry();
313
314 //Calculate offset to crystal surface.
315 //See fCrystalShift code in AliPHOSGeometry::Init()).
316
a2bb6de5 317 const Float_t * inthermo = geoEMCA->GetInnerThermoHalfSize() ;
318 const Float_t * strip = geoEMCA->GetStripHalfSize() ;
319 const Float_t * splate = geoEMCA->GetSupportPlateHalfSize();
320 const Float_t * crystal = geoEMCA->GetCrystalHalfSize() ;
321 const Float_t * pin = geoEMCA->GetAPDHalfSize() ;
322 const Float_t * preamp = geoEMCA->GetPreampHalfSize() ;
7af865cb 323 crystalShift = -inthermo[1]+strip[1]+splate[1]+crystal[1]-geoEMCA->GetAirGapLed()/2.+pin[1]+preamp[1] ;
324
325 if(IsEmc()) {
326 dy = crystalShift;
327 lxyz[2] = -lxyz[2]; //Opposite z directions in EMC matrix and local frame!!!
328 }
329 else
330 dy = phosgeom->GetCPVBoxSize(1)/2.; //center of CPV module
331
332 lxyz[1] = lxyz[1] - dy;
b48eb81e 333
334 const TGeoHMatrix* tr2loc = GetTracking2LocalMatrix();
b7575333 335 if(!tr2loc) AliFatal(Form("No Tracking2LocalMatrix found for VolumeID=%d",GetVolumeId()));
b48eb81e 336
337 tr2loc->MasterToLocal(lxyz,txyz);
7e9d90f9 338 SetX(txyz[0]); SetY(txyz[1]); SetZ(txyz[2]);
b48eb81e 339
7af865cb 340 if(AliLog::GetGlobalDebugLevel()>0) {
341 TVector3 gpos; TMatrixF gmat;
342 GetGlobalPosition(gpos,gmat);
343 Float_t gxyz[3];
344 GetGlobalXYZ(gxyz);
345 TString emc;
346 if(IsEmc())
347 emc="EMC";
348 else
349 emc="CPV";
350 AliInfo(Form("lCS-->(%.3f,%.3f,%.3f), tCS-->(%.3f,%.3f,%.3f), gCS-->(%.3f,%.3f,%.3f), gCScalc-->(%.3f,%.3f,%.3f), module %d %s",
351 fLocPos.X(),fLocPos.Y(),fLocPos.Z(),
352 GetX(),GetY(),GetZ(),
353 gpos.X(),gpos.Y(),gpos.Z(),
354 gxyz[0],gxyz[1],gxyz[2],GetPHOSMod(),emc.Data()));
355 }
356
b48eb81e 357}