Tracking2LocalCS matrices corrected.
[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
b2a60966 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 ---
33
34#include "AliPHOSGeometry.h"
35#include "AliPHOSDigit.h"
36#include "AliPHOSRecPoint.h"
7b7c1533 37#include "AliPHOSGetter.h"
b48eb81e 38#include "AliGeomManager.h"
9f616d61 39
d15a28e7 40ClassImp(AliPHOSRecPoint)
41
42
43//____________________________________________________________________________
44AliPHOSRecPoint::AliPHOSRecPoint()
9ee9f78d 45 : AliCluster(),fPHOSMod(0),
46 fMulTrack(0),fMaxDigit(100),fMulDigit(0),fMaxTrack(0),
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)
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),
59 fDigitsList(new int[fMaxDigit]),fTracksList(new int[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
73a68ccb 63{
64 // ctor
65
55fe9d13 66}
9ee9f78d 67//_______________________________________________________________________
68AliPHOSRecPoint::~AliPHOSRecPoint()
69{
70 // dtor
71
72 delete fLocPosM ;
73 delete [] fDigitsList ;
74 delete [] fTracksList ;
75
76}
77//____________________________________________________________________________
78AliPHOSRecPoint::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(new int[rp.fMaxDigit]),
82 fTracksList(new int[rp.fMaxTrack]),fAmp(rp.fAmp),fIndexInList(rp.fIndexInList),
83 fLocPos(rp.fLocPos),fLocPosM(rp.fLocPosM)
84{
85 //copy ctor
55fe9d13 86
9ee9f78d 87 for(Int_t i=0; i<fMaxDigit; i++)
88 fDigitsList[i] = rp.fDigitsList[i];
89
90 for(Int_t i=0; i<fMaxTrack; i++)
91 fTracksList[i] = rp.fTracksList[i];
92
93}
94//____________________________________________________________________________
95AliPHOSRecPoint& AliPHOSRecPoint::operator= (const AliPHOSRecPoint &rp)
96{
97 if(&rp == this) return *this;
98
99 fPHOSMod = rp.fPHOSMod;
100 fMulTrack = rp.fMulTrack;
101 fMaxDigit = rp.fMaxDigit;
102 fMulDigit = rp.fMulDigit;
103 fMaxTrack = rp.fMaxTrack;
104 fAmp = rp.fAmp;
105 fIndexInList = rp.fIndexInList;
106 fLocPos = rp.fLocPos;
107 fLocPosM = rp.fLocPosM;
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}
55fe9d13 117//____________________________________________________________________________
9f616d61 118Int_t AliPHOSRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
119{
b2a60966 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;
9f616d61 135}
6ad0bfa0 136
9f616d61 137//___________________________________________________________________________
138 void AliPHOSRecPoint::Draw(Option_t *option)
139 {
6ad0bfa0 140 // Draw this AliPHOSRecPoint with its current attributes
141
142 AppendPad(option);
9f616d61 143 }
144
145//______________________________________________________________________________
8f2a3661 146void AliPHOSRecPoint::ExecuteEvent(Int_t event, Int_t, Int_t)
9f616d61 147{
6ad0bfa0 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.
9f616d61 153
154 // static Int_t pxold, pyold;
155
b2a60966 156 static TGraph * digitgraph = 0 ;
157 static TPaveText* clustertext = 0 ;
158
159 if (!gPad->IsEditable()) return;
9f616d61 160
b2a60966 161 switch (event) {
162
163
164 case kButton1Down:{
165 AliPHOSDigit * digit ;
88cb7938 166
167// Accessing geometry this way is equivalent to getting from gAlice
168// to have Detector in Folder one have to load gAlice anyway
169// AliPHOSLoader * gime = AliPHOSLoader::GetInstance();
170// AliPHOSGeometry * phosgeom = const_cast<AliPHOSGeometry*>(gime->PHOSGeometry());
171
172 AliPHOSGeometry * phosgeom = AliPHOSLoader::GetPHOSGeometry();
7b7c1533 173
b2a60966 174 Int_t iDigit;
175 Int_t relid[4] ;
31aa6d6c 176
88714635 177 const Int_t kMulDigit=AliPHOSRecPoint::GetDigitsMultiplicity() ;
178 Float_t * xi = new Float_t [kMulDigit] ;
179 Float_t * zi = new Float_t [kMulDigit] ;
b2a60966 180
88714635 181 for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
4696e514 182 Fatal("AliPHOSRecPoint::ExecuteEvent", "-> Something wrong with the code");
7a9d98f9 183 digit = 0 ; //dynamic_cast<AliPHOSDigit *>((fDigitsList)[iDigit]);
b2a60966 184 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
185 phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]) ;
186 }
187
188 if (!digitgraph) {
189 digitgraph = new TGraph(fMulDigit,xi,zi);
190 digitgraph-> SetMarkerStyle(5) ;
191 digitgraph-> SetMarkerSize(1.) ;
192 digitgraph-> SetMarkerColor(1) ;
193 digitgraph-> Draw("P") ;
194 }
195 if (!clustertext) {
196
197 TVector3 pos(0.,0.,0.) ;
198 GetLocalPosition(pos) ;
199 clustertext = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+50,pos.Z()+35,"") ;
200 Text_t line1[40] ;
201 Text_t line2[40] ;
202 sprintf(line1,"Energy=%1.2f GeV",GetEnergy()) ;
203 sprintf(line2,"%d Digits",GetDigitsMultiplicity()) ;
204 clustertext ->AddText(line1) ;
205 clustertext ->AddText(line2) ;
206 clustertext ->Draw("");
207 }
208 gPad->Update() ;
a8c47ab6 209 Print("dummy") ;
31aa6d6c 210 delete[] xi ;
211 delete[] zi ;
212 }
b2a60966 213
31aa6d6c 214break;
b2a60966 215
216 case kButton1Up:
217 if (digitgraph) {
218 delete digitgraph ;
219 digitgraph = 0 ;
220 }
221 if (clustertext) {
222 delete clustertext ;
223 clustertext = 0 ;
224 }
225
226 break;
227
9f616d61 228 }
9f616d61 229}
ad8cfaf4 230//____________________________________________________________________________
e957fea8 231void AliPHOSRecPoint::EvalAll(TClonesArray * digits)
88cb7938 232{
ad8cfaf4 233 //evaluates (if necessary) all RecPoint data members
9f616d61 234
2731cd1e 235 EvalPrimaries(digits) ;
ad8cfaf4 236}
88cb7938 237
d15a28e7 238//____________________________________________________________________________
2731cd1e 239void AliPHOSRecPoint::EvalPHOSMod(AliPHOSDigit * digit)
b2a60966 240{
241 // Returns the PHOS module in which the RecPoint is found
83974468 242
2731cd1e 243 if( fPHOSMod == 0){
ad8cfaf4 244 Int_t relid[4] ;
88cb7938 245
246 AliPHOSGeometry * phosgeom = (AliPHOSGetter::Instance())->PHOSGeometry();
d15a28e7 247
92862013 248 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
d15a28e7 249 fPHOSMod = relid[0];
2731cd1e 250 }
d15a28e7 251}
6ad0bfa0 252
9f616d61 253//______________________________________________________________________________
2731cd1e 254void AliPHOSRecPoint::EvalPrimaries(TClonesArray * digits)
cf239357 255{
2731cd1e 256 // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
b2a60966 257
cf239357 258 AliPHOSDigit * digit ;
2731cd1e 259 Int_t * tempo = new Int_t[fMaxTrack] ;
260
261 Int_t index ;
cf239357 262 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
7a9d98f9 263 digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ;
88cb7938 264 Int_t nprimaries = digit->GetNprimary() ;
265 if(nprimaries){
266 Int_t * newprimaryarray = new Int_t[nprimaries] ;
267 Int_t ii ;
268 for ( ii = 0 ; ii < nprimaries ; ii++)
269 newprimaryarray[ii] = digit->GetPrimary(ii+1) ;
270
271 Int_t jndex ;
272 for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
273 if ( fMulTrack > fMaxTrack ) {
274 fMulTrack = - 1 ;
275 Error("EvalPrimaries", "GetNprimaries ERROR > increase fMaxTrack" ) ;
276 break ;
277 }
278 Int_t newprimary = newprimaryarray[jndex] ;
279 Int_t kndex ;
280 Bool_t already = kFALSE ;
281 for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
282 if ( newprimary == tempo[kndex] ){
283 already = kTRUE ;
884e9693 284 break ;
285 }
88cb7938 286 } // end of check
287 if ( !already) { // store it
288 tempo[fMulTrack] = newprimary ;
289 fMulTrack++ ;
290 } // store it
291 } // all primaries in digit
292 delete [] newprimaryarray ;
884e9693 293 }
cf239357 294 } // all digits
295
884e9693 296 if(fMulTrack)
297 fTracksList = new Int_t[fMulTrack] ;
2731cd1e 298 for(index = 0; index < fMulTrack; index++)
884e9693 299 fTracksList[index] = tempo[index] ;
300
780a31c1 301 delete [] tempo ;
884e9693 302
cf239357 303}
4b45b217 304//____________________________________________________________________________
e8d02863 305void AliPHOSRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrixF & gmat) const
4b45b217 306{
307 // returns the position of the cluster in the global reference system of ALICE
308 // and the uncertainty on this position
9ee9f78d 309
310 (AliPHOSGetter::Instance())->PHOSGeometry()->GetGlobalPHOS(this, gpos, gmat);
311
312// Float_t xyz[3];
313// GetGlobalXYZ(xyz);
314// gpos.SetXYZ(xyz[0],xyz[1],xyz[2]);
315
316
4b45b217 317}
318
cf239357 319
320//______________________________________________________________________________
9f616d61 321void AliPHOSRecPoint::Paint(Option_t *)
322{
b2a60966 323 // Paint this ALiRecPoint as a TMarker with its current attributes
324
325 TVector3 pos(0.,0.,0.) ;
326 GetLocalPosition(pos) ;
327 Coord_t x = pos.X() ;
328 Coord_t y = pos.Z() ;
329 Color_t markercolor = 1 ;
330 Size_t markersize = 1. ;
331 Style_t markerstyle = 5 ;
332
333 if (!gPad->IsBatch()) {
334 gVirtualX->SetMarkerColor(markercolor) ;
335 gVirtualX->SetMarkerSize (markersize) ;
336 gVirtualX->SetMarkerStyle(markerstyle) ;
337 }
338 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
339 gPad->PaintPolyMarker(1,&x,&y,"") ;
9f616d61 340}
88cb7938 341//______________________________________________________________________________
9ee9f78d 342void AliPHOSRecPoint::GetLocalPosition(TVector3 & pos) const
343{
344 // returns the position of the cluster in the local reference system
345 // of the sub-detector
346
347 pos = fLocPos;
348}
b48eb81e 349
350//____________________________________________________________________________
351void AliPHOSRecPoint::EvalLocal2TrackingCSTransform()
352{
353 //Evaluates local to "tracking" c.s. transformation (B.P.).
354 //All evaluations should be completed before calling for this function.
355 //See ALICE PPR Chapter 5 p.18 for "tracking" c.s. definition,
356 //or just ask Jouri Belikov. :)
357
358 if(IsEmc()) {
359 SetVolumeId(AliGeomManager::LayerToVolUID(AliGeomManager::kPHOS1,GetPHOSMod()-1));
360 }
361 else
76e42795 362 SetVolumeId(AliGeomManager::LayerToVolUID(AliGeomManager::kPHOS2,GetPHOSMod()-1));
b48eb81e 363
364 Double_t lxyz[3] = {fLocPos.X(),0,fLocPos.Z()};
365 Double_t txyz[3] = {0,0,0};
366
367 const TGeoHMatrix* tr2loc = GetTracking2LocalMatrix();
368 if(!tr2loc) AliFatal(Form("No Tracking2LocalMatrix found."));
369
370 tr2loc->MasterToLocal(lxyz,txyz);
7e9d90f9 371 SetX(txyz[0]); SetY(txyz[1]); SetZ(txyz[2]);
b48eb81e 372
373}