]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSRecPoint.cxx
AliPHOSRecPoint inheritance from AliCluster
[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
29 // --- Standard library ---
30
31 // --- AliRoot header files ---
32
33 #include "AliPHOSGeometry.h"
34 #include "AliPHOSDigit.h"
35 #include "AliPHOSRecPoint.h"
36 #include "AliPHOSGetter.h"
37
38 ClassImp(AliPHOSRecPoint)
39
40
41 //____________________________________________________________________________
42 AliPHOSRecPoint::AliPHOSRecPoint()
43   : AliCluster(),fPHOSMod(0),
44     fMulTrack(0),fMaxDigit(100),fMulDigit(0),fMaxTrack(0),
45     fDigitsList(0),fTracksList(0),fAmp(0),
46     fIndexInList(-1), // to be set when the point is already stored
47     fLocPos(0,0,0),fLocPosM(0)
48 {
49   // ctor
50
51 }
52
53 //____________________________________________________________________________
54 AliPHOSRecPoint::AliPHOSRecPoint(const char * ) 
55   : AliCluster(),fPHOSMod(0),
56     fMulTrack(0),fMaxDigit(100),fMulDigit(0),fMaxTrack(200),
57     fDigitsList(new int[fMaxDigit]),fTracksList(new int[fMaxTrack]),fAmp(0),
58     fIndexInList(-1), // to be set when the point is already stored
59     fLocPos(0,0,0),fLocPosM(new TMatrixF(3,3))
60
61 {
62   // ctor
63   
64 }
65 //_______________________________________________________________________
66 AliPHOSRecPoint::~AliPHOSRecPoint()
67 {
68   // dtor
69   
70   delete fLocPosM ; 
71   delete [] fDigitsList ; 
72   delete [] fTracksList ;  
73   
74 }
75 //____________________________________________________________________________
76 AliPHOSRecPoint::AliPHOSRecPoint(const AliPHOSRecPoint &rp) : 
77   AliCluster(rp),
78   fPHOSMod(rp.fPHOSMod),fMulTrack(rp.fMulTrack),fMaxDigit(rp.fMaxDigit),
79   fMulDigit(rp.fMulDigit),fMaxTrack(rp.fMaxTrack),fDigitsList(new int[rp.fMaxDigit]),
80   fTracksList(new int[rp.fMaxTrack]),fAmp(rp.fAmp),fIndexInList(rp.fIndexInList), 
81   fLocPos(rp.fLocPos),fLocPosM(rp.fLocPosM)
82 {
83   //copy ctor
84
85   for(Int_t i=0; i<fMaxDigit; i++)
86     fDigitsList[i] = rp.fDigitsList[i];
87
88   for(Int_t i=0; i<fMaxTrack; i++)
89     fTracksList[i] = rp.fTracksList[i];
90   
91 }
92 //____________________________________________________________________________
93 AliPHOSRecPoint& AliPHOSRecPoint::operator= (const AliPHOSRecPoint &rp)
94 {
95   if(&rp == this) return *this;
96
97   fPHOSMod = rp.fPHOSMod;
98   fMulTrack = rp.fMulTrack;
99   fMaxDigit = rp.fMaxDigit;
100   fMulDigit = rp.fMulDigit;
101   fMaxTrack = rp.fMaxTrack;
102   fAmp = rp.fAmp;
103   fIndexInList = rp.fIndexInList; 
104   fLocPos = rp.fLocPos;
105   fLocPosM = rp.fLocPosM;
106
107   for(Int_t i=0; i<fMaxDigit; i++)
108     fDigitsList[i] = rp.fDigitsList[i];
109
110   for(Int_t i=0; i<fMaxTrack; i++)
111     fTracksList[i] = rp.fTracksList[i];
112
113   return *this;
114 }
115 //____________________________________________________________________________
116 Int_t AliPHOSRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
117 {
118   // Compute distance from point px,py to  a AliPHOSRecPoint considered as a Tmarker
119   // Compute the closest distance of approach from point px,py to this marker.
120   // The distance is computed in pixels units.
121
122   TVector3 pos(0.,0.,0.) ;
123   GetLocalPosition( pos) ;
124   Float_t x =  pos.X() ;
125   Float_t y =  pos.Z() ;
126   const Int_t kMaxDiff = 10;
127   Int_t pxm  = gPad->XtoAbsPixel(x);
128   Int_t pym  = gPad->YtoAbsPixel(y);
129   Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
130   
131   if (dist > kMaxDiff) return 9999;
132   return dist;
133 }
134
135 //___________________________________________________________________________
136  void AliPHOSRecPoint::Draw(Option_t *option)
137  {
138    // Draw this AliPHOSRecPoint with its current attributes
139    
140    AppendPad(option);
141  }
142
143 //______________________________________________________________________________
144 void AliPHOSRecPoint::ExecuteEvent(Int_t event, Int_t, Int_t)
145 {
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
152   //  static Int_t pxold, pyold;
153
154   static TGraph *  digitgraph = 0 ;
155   static TPaveText* clustertext = 0 ;
156   
157   if (!gPad->IsEditable()) return;
158   
159   switch (event) {
160     
161     
162   case kButton1Down:{
163     AliPHOSDigit * digit ;
164   
165 //  Accessing geometry this way is equivalent to getting from gAlice
166 // to have Detector in Folder one have to load gAlice anyway
167 //    AliPHOSLoader * gime = AliPHOSLoader::GetInstance();
168 //    AliPHOSGeometry * phosgeom =  const_cast<AliPHOSGeometry*>(gime->PHOSGeometry());
169
170     AliPHOSGeometry * phosgeom = AliPHOSLoader::GetPHOSGeometry();
171
172     Int_t iDigit;
173     Int_t relid[4] ;
174   
175     const Int_t kMulDigit=AliPHOSRecPoint::GetDigitsMultiplicity() ;
176     Float_t * xi = new Float_t [kMulDigit] ; 
177     Float_t * zi = new Float_t [kMulDigit] ;
178     
179     for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
180       Fatal("AliPHOSRecPoint::ExecuteEvent", "-> Something wrong with the code"); 
181       digit = 0 ; //dynamic_cast<AliPHOSDigit *>((fDigitsList)[iDigit]);
182       phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
183       phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]) ;
184     }
185     
186     if (!digitgraph) {
187       digitgraph = new TGraph(fMulDigit,xi,zi);
188       digitgraph-> SetMarkerStyle(5) ; 
189       digitgraph-> SetMarkerSize(1.) ;
190       digitgraph-> SetMarkerColor(1) ;
191       digitgraph-> Draw("P") ;
192     }
193     if (!clustertext) {
194       
195       TVector3 pos(0.,0.,0.) ;
196       GetLocalPosition(pos) ;
197       clustertext = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+50,pos.Z()+35,"") ;
198       Text_t  line1[40] ;
199       Text_t  line2[40] ;
200       sprintf(line1,"Energy=%1.2f GeV",GetEnergy()) ;
201       sprintf(line2,"%d Digits",GetDigitsMultiplicity()) ;
202       clustertext ->AddText(line1) ;
203       clustertext ->AddText(line2) ;
204       clustertext ->Draw("");
205     }
206     gPad->Update() ; 
207     Print("dummy") ;
208     delete[] xi ; 
209     delete[] zi ; 
210    }
211   
212 break;
213   
214   case kButton1Up:
215     if (digitgraph) {
216       delete digitgraph  ;
217       digitgraph = 0 ;
218     }
219     if (clustertext) {
220       delete clustertext ;
221       clustertext = 0 ;
222     }
223     
224     break;
225     
226   }
227 }
228 //____________________________________________________________________________
229 void AliPHOSRecPoint::EvalAll(TClonesArray * digits) 
230 {
231   //evaluates (if necessary) all RecPoint data members 
232
233   EvalPrimaries(digits) ;
234 }
235
236 //____________________________________________________________________________
237 void AliPHOSRecPoint::EvalPHOSMod(AliPHOSDigit * digit) 
238 {
239   // Returns the PHOS module in which the RecPoint is found
240
241   if( fPHOSMod == 0){
242   Int_t relid[4] ; 
243  
244   AliPHOSGeometry * phosgeom = (AliPHOSGetter::Instance())->PHOSGeometry();
245
246   phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
247   fPHOSMod = relid[0];
248   }
249 }
250
251 //______________________________________________________________________________
252 void  AliPHOSRecPoint::EvalPrimaries(TClonesArray * digits)
253 {
254   // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
255   
256   AliPHOSDigit * digit ;
257   Int_t * tempo    = new Int_t[fMaxTrack] ;
258
259   Int_t index ;  
260   for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
261     digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ; 
262     Int_t nprimaries = digit->GetNprimary() ;
263     if(nprimaries){
264       Int_t * newprimaryarray = new Int_t[nprimaries] ;
265       Int_t ii ; 
266       for ( ii = 0 ; ii < nprimaries ; ii++)
267         newprimaryarray[ii] = digit->GetPrimary(ii+1) ; 
268
269       Int_t jndex ;
270       for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
271         if ( fMulTrack > fMaxTrack ) {
272           fMulTrack = - 1 ;
273           Error("EvalPrimaries", "GetNprimaries ERROR > increase fMaxTrack" ) ;
274           break ;
275         }
276         Int_t newprimary = newprimaryarray[jndex] ;
277         Int_t kndex ;
278         Bool_t already = kFALSE ;
279         for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
280           if ( newprimary == tempo[kndex] ){
281             already = kTRUE ;
282             break ;
283           }
284         } // end of check
285         if ( !already) { // store it
286           tempo[fMulTrack] = newprimary ; 
287           fMulTrack++ ;
288         } // store it
289       } // all primaries in digit
290       delete [] newprimaryarray ; 
291     }
292   } // all digits
293
294   if(fMulTrack)
295     fTracksList = new Int_t[fMulTrack] ;
296   for(index = 0; index < fMulTrack; index++)
297     fTracksList[index] = tempo[index] ;
298   
299   delete [] tempo ;
300   
301 }
302 //____________________________________________________________________________
303 void AliPHOSRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrixF & gmat) const
304 {
305   // returns the position of the cluster in the global reference system of ALICE
306   // and the uncertainty on this position
307
308   (AliPHOSGetter::Instance())->PHOSGeometry()->GetGlobalPHOS(this, gpos, gmat);
309
310 //   Float_t xyz[3];
311 //   GetGlobalXYZ(xyz);
312 //   gpos.SetXYZ(xyz[0],xyz[1],xyz[2]);
313
314   
315 }
316
317
318 //______________________________________________________________________________
319 void AliPHOSRecPoint::Paint(Option_t *)
320 {
321   // Paint this ALiRecPoint as a TMarker  with its current attributes
322   
323   TVector3 pos(0.,0.,0.)  ;
324   GetLocalPosition(pos)   ;
325   Coord_t x = pos.X()     ;
326   Coord_t y = pos.Z()     ;
327   Color_t markercolor = 1 ;
328   Size_t  markersize = 1. ;
329   Style_t markerstyle = 5 ;
330   
331   if (!gPad->IsBatch()) {
332     gVirtualX->SetMarkerColor(markercolor) ;
333     gVirtualX->SetMarkerSize (markersize)  ;
334     gVirtualX->SetMarkerStyle(markerstyle) ;
335   }
336   gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
337   gPad->PaintPolyMarker(1,&x,&y,"") ;
338 }
339 //______________________________________________________________________________
340 void AliPHOSRecPoint::GetLocalPosition(TVector3 & pos) const
341 {
342   // returns the position of the cluster in the local reference system 
343   // of the sub-detector
344   
345   pos = fLocPos;
346 }