Adding checkpoints (T.Kuhr)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRecPoint.cxx
CommitLineData
ab48128d 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 EMCAL Reconstructed Points
18// Why should I put meaningless comments
19// just to satisfy
20// the code checker
d64c959b 21//*-- Author: Yves Schutz (SUBATECH)
ab48128d 22
23// --- ROOT system ---
24#include "TPad.h"
d64c959b 25#include "TGraph.h"
26#include "TPaveText.h"
ab48128d 27#include "TClonesArray.h"
28
29// --- Standard library ---
ab48128d 30
31// --- AliRoot header files ---
32
33#include "AliEMCALGeometry.h"
34#include "AliEMCALDigit.h"
35#include "AliEMCALRecPoint.h"
36#include "AliEMCALGetter.h"
37
38ClassImp(AliEMCALRecPoint)
39
40
41//____________________________________________________________________________
42AliEMCALRecPoint::AliEMCALRecPoint()
43 : AliRecPoint()
44{
45 // ctor
46
692088ae 47 fMaxTrack = 0 ;
ab48128d 48 fTheta = fPhi = 0. ;
692088ae 49 fEMCALArm = 0;
fdebddeb 50 fECASection = kFALSE ;
ab48128d 51}
52
53//____________________________________________________________________________
54AliEMCALRecPoint::AliEMCALRecPoint(const char * opt) : AliRecPoint(opt)
55{
56 // ctor
57
58 fMaxTrack = 200 ;
59 fTheta = fPhi = 0. ;
60 fEMCALArm = 1;
61
62}
63
64//____________________________________________________________________________
65Int_t AliEMCALRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
66{
67 // Compute distance from point px,py to a AliEMCALRecPoint considered as a Tmarker
68 // Compute the closest distance of approach from point px,py to this marker.
69 // The distance is computed in pixels units.
70
71 TVector3 pos(0.,0.,0.) ;
72 GetLocalPosition( pos) ;
73 Float_t x = pos.X() ;
74 Float_t y = pos.Z() ;
75 const Int_t kMaxDiff = 10;
76 Int_t pxm = gPad->XtoAbsPixel(x);
77 Int_t pym = gPad->YtoAbsPixel(y);
78 Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
79
80 if (dist > kMaxDiff) return 9999;
81 return dist;
82}
83
84//___________________________________________________________________________
85 void AliEMCALRecPoint::Draw(Option_t *option)
86 {
87 // Draw this AliEMCALRecPoint with its current attributes
88
89 AppendPad(option);
90 }
91
92//______________________________________________________________________________
9e5d2067 93void AliEMCALRecPoint::ExecuteEvent(Int_t event, Int_t, Int_t)
ab48128d 94{
95 // Execute action corresponding to one event
96 // This member function is called when a AliEMCALRecPoint is clicked with the locator
97 //
98 // If Left button is clicked on AliEMCALRecPoint, the digits are switched on
99 // and switched off when the mouse button is released.
100
101 // static Int_t pxold, pyold;
102
103 static TGraph * digitgraph = 0 ;
104 static TPaveText* clustertext = 0 ;
105
106 if (!gPad->IsEditable()) return;
107
108 switch (event) {
109
110
111 case kButton1Down:{
112 AliEMCALDigit * digit ;
88cb7938 113 AliEMCALGeometry * emcalgeom = (AliEMCALGetter::Instance())->EMCALGeometry() ;
ab48128d 114
115 Int_t iDigit;
fdebddeb 116 Int_t relid[3] ;
ab48128d 117
118 const Int_t kMulDigit=AliEMCALRecPoint::GetDigitsMultiplicity() ;
119 Float_t * xi = new Float_t [kMulDigit] ;
120 Float_t * zi = new Float_t [kMulDigit] ;
121
122 for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
123 Fatal("AliEMCALRecPoint::ExecuteEvent", " -> Something wrong with the code");
124 digit = 0 ; //dynamic_cast<AliEMCALDigit *>((fDigitsList)[iDigit]);
125 emcalgeom->AbsToRelNumbering(digit->GetId(), relid) ;
126 emcalgeom->PosInAlice(relid, xi[iDigit], zi[iDigit]) ;
127 }
128
129 if (!digitgraph) {
130 digitgraph = new TGraph(fMulDigit,xi,zi);
131 digitgraph-> SetMarkerStyle(5) ;
132 digitgraph-> SetMarkerSize(1.) ;
133 digitgraph-> SetMarkerColor(1) ;
134 digitgraph-> Draw("P") ;
135 }
136 if (!clustertext) {
137
138 TVector3 pos(0.,0.,0.) ;
139 GetLocalPosition(pos) ;
140 clustertext = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+50,pos.Z()+35,"") ;
141 Text_t line1[40] ;
142 Text_t line2[40] ;
143 sprintf(line1,"Energy=%1.2f GeV",GetEnergy()) ;
144 sprintf(line2,"%d Digits",GetDigitsMultiplicity()) ;
145 clustertext ->AddText(line1) ;
146 clustertext ->AddText(line2) ;
147 clustertext ->Draw("");
148 }
149 gPad->Update() ;
9e5d2067 150 Print("") ;
ab48128d 151 delete[] xi ;
152 delete[] zi ;
153 }
154
155break;
156
157 case kButton1Up:
158 if (digitgraph) {
159 delete digitgraph ;
160 digitgraph = 0 ;
161 }
162 if (clustertext) {
163 delete clustertext ;
164 clustertext = 0 ;
165 }
166
167 break;
168
169 }
170}
171//____________________________________________________________________________
9e5d2067 172void AliEMCALRecPoint::EvalAll(Float_t /*logWeight*/,TClonesArray * digits)
88cb7938 173{
ab48128d 174 //evaluates (if necessary) all RecPoint data members
175
176 EvalPrimaries(digits) ;
177}
178
179//____________________________________________________________________________
180void AliEMCALRecPoint::EvalEMCALArm(AliEMCALDigit * digit)
181{
182 // Returns the EMCAL module in which the RecPoint is found
183
184
185 if( fEMCALArm == 0){
fdebddeb 186 Int_t relid[3] ;
ab48128d 187
88cb7938 188 AliEMCALGeometry * emcalgeom = (AliEMCALGetter::Instance())->EMCALGeometry();
ab48128d 189
190 emcalgeom->AbsToRelNumbering(digit->GetId(), relid) ;
191 fEMCALArm = relid[0];
192 }
193}
194
195//______________________________________________________________________________
196void AliEMCALRecPoint::EvalPrimaries(TClonesArray * digits)
197{
198 // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
199
200 AliEMCALDigit * digit ;
201 Int_t * tempo = new Int_t[fMaxTrack] ;
202
203 Int_t index ;
204 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
205 digit = dynamic_cast<AliEMCALDigit *>(digits->At( fDigitsList[index] )) ;
206 Int_t nprimaries = digit->GetNprimary() ;
207 Int_t * newprimaryarray = new Int_t[nprimaries] ;
208 Int_t ii ;
209 for ( ii = 0 ; ii < nprimaries ; ii++)
210 newprimaryarray[ii] = digit->GetPrimary(ii+1) ;
211
212 Int_t jndex ;
213 for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
214 if ( fMulTrack > fMaxTrack ) {
215 fMulTrack = - 1 ;
9859bfc0 216 Error("GetNprimaries", "increase fMaxTrack ") ;
ab48128d 217 break ;
218 }
219 Int_t newprimary = newprimaryarray[jndex] ;
220 Int_t kndex ;
221 Bool_t already = kFALSE ;
222 for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
223 if ( newprimary == tempo[kndex] ){
224 already = kTRUE ;
225 break ;
226 }
227 } // end of check
228 if ( !already) { // store it
229 tempo[fMulTrack] = newprimary ;
230 fMulTrack++ ;
231 } // store it
232 } // all primaries in digit
233 delete newprimaryarray ;
234 } // all digits
235
236
237 fTracksList = new Int_t[fMulTrack] ;
238 for(index = 0; index < fMulTrack; index++)
239 fTracksList[index] = tempo[index] ;
240
241 delete tempo ;
242
243}
7ee5c5be 244
ab48128d 245//____________________________________________________________________________
246void AliEMCALRecPoint::GetGlobalPosition(TVector3 & gpos) const
247{
248 // returns the position of the cluster in the global reference system of ALICE
ab48128d 249
88cb7938 250 AliEMCALGeometry * emcalgeom = AliEMCALGetter::Instance()->EMCALGeometry();
ab48128d 251 gpos.SetX(fPhi) ;
88cb7938 252 if ( IsInECA() )
253 gpos.SetY(emcalgeom->GetIP2ECASection()) ;
7ee5c5be 254 else
aad8e277 255 Fatal("GetGlobalPosition", "Unexpected tower section") ;
ab48128d 256 gpos.SetZ(fTheta) ;
ab48128d 257}
258
aad8e277 259//____________________________________________________________________________
260void AliEMCALRecPoint::GetLocalPosition(TVector3 & lpos) const
261{
262 // returns the position of the cluster in the global reference system of ALICE
263
264 lpos.SetX(fLocPos.X()) ;
265 lpos.SetY(fLocPos.Y()) ;
266 lpos.SetZ(fLocPos.Z()) ;
267}
ab48128d 268
269//______________________________________________________________________________
270void AliEMCALRecPoint::Paint(Option_t *)
271{
272 // Paint this ALiRecPoint as a TMarker with its current attributes
273
274 TVector3 pos(0.,0.,0.) ;
275 GetLocalPosition(pos) ;
276 Coord_t x = pos.X() ;
277 Coord_t y = pos.Z() ;
278 Color_t markercolor = 1 ;
279 Size_t markersize = 1. ;
280 Style_t markerstyle = 5 ;
281
282 if (!gPad->IsBatch()) {
283 gVirtualX->SetMarkerColor(markercolor) ;
284 gVirtualX->SetMarkerSize (markersize) ;
285 gVirtualX->SetMarkerStyle(markerstyle) ;
286 }
287 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
288 gPad->PaintPolyMarker(1,&x,&y,"") ;
289}