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