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