1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //_________________________________________________________________________
17 // Base Class for PHOS Reconstructed Points
18 // Why should I put meaningless comments
21 //*-- Author: Gines Martinez (SUBATECH)
23 // --- ROOT system ---
26 #include "TPaveText.h"
27 #include "TClonesArray.h"
28 #include "TGeoMatrix.h"
30 // --- Standard library ---
32 // --- AliRoot header files ---
34 #include "AliPHOSGeometry.h"
35 #include "AliPHOSDigit.h"
36 #include "AliPHOSRecPoint.h"
37 #include "AliPHOSGetter.h"
38 #include "AliGeomManager.h"
40 ClassImp(AliPHOSRecPoint)
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)
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))
67 //_______________________________________________________________________
68 AliPHOSRecPoint::~AliPHOSRecPoint()
73 delete [] fDigitsList ;
74 delete [] fTracksList ;
77 //____________________________________________________________________________
78 AliPHOSRecPoint::AliPHOSRecPoint(const AliPHOSRecPoint &rp) :
80 fPHOSMod(rp.fPHOSMod),fMulTrack(rp.fMulTrack),fMaxDigit(rp.fMaxDigit),
81 fMulDigit(rp.fMulDigit),fMaxTrack(rp.fMaxTrack),fDigitsList(new Int_t[rp.fMaxDigit]),
82 fTracksList(new Int_t[rp.fMaxTrack]),fAmp(rp.fAmp),fIndexInList(rp.fIndexInList),
83 fLocPos(rp.fLocPos),fLocPosM(rp.fLocPosM)
87 for(Int_t i=0; i<fMulDigit; i++)
88 fDigitsList[i] = rp.fDigitsList[i];
90 for(Int_t i=0; i<fMulTrack; i++)
91 fTracksList[i] = rp.fTracksList[i];
94 //____________________________________________________________________________
95 AliPHOSRecPoint& AliPHOSRecPoint::operator= (const AliPHOSRecPoint &rp)
97 if(&rp == this) return *this;
99 fPHOSMod = rp.fPHOSMod;
100 fMulTrack = rp.fMulTrack;
101 fMaxDigit = rp.fMaxDigit;
102 fMulDigit = rp.fMulDigit;
103 fMaxTrack = rp.fMaxTrack;
105 fIndexInList = rp.fIndexInList;
106 fLocPos = rp.fLocPos;
107 fLocPosM = rp.fLocPosM;
109 for(Int_t i=0; i<fMaxDigit; i++)
110 fDigitsList[i] = rp.fDigitsList[i];
112 for(Int_t i=0; i<fMaxTrack; i++)
113 fTracksList[i] = rp.fTracksList[i];
117 //____________________________________________________________________________
118 Int_t AliPHOSRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
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.
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);
133 if (dist > kMaxDiff) return 9999;
137 //___________________________________________________________________________
138 void AliPHOSRecPoint::Draw(Option_t *option)
140 // Draw this AliPHOSRecPoint with its current attributes
145 //______________________________________________________________________________
146 void AliPHOSRecPoint::ExecuteEvent(Int_t event, Int_t, Int_t)
148 // Execute action corresponding to one event
149 // This member function is called when a AliPHOSRecPoint is clicked with the locator
151 // If Left button is clicked on AliPHOSRecPoint, the digits are switched on
152 // and switched off when the mouse button is released.
154 // static Int_t pxold, pyold;
156 static TGraph * digitgraph = 0 ;
157 static TPaveText* clustertext = 0 ;
159 if (!gPad->IsEditable()) return;
165 AliPHOSDigit * digit ;
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());
172 AliPHOSGeometry * phosgeom = AliPHOSLoader::GetPHOSGeometry();
177 const Int_t kMulDigit=AliPHOSRecPoint::GetDigitsMultiplicity() ;
178 Float_t * xi = new Float_t [kMulDigit] ;
179 Float_t * zi = new Float_t [kMulDigit] ;
181 for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
182 Fatal("AliPHOSRecPoint::ExecuteEvent", "-> Something wrong with the code");
183 digit = 0 ; //dynamic_cast<AliPHOSDigit *>((fDigitsList)[iDigit]);
184 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
185 phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]) ;
189 digitgraph = new TGraph(fMulDigit,xi,zi);
190 digitgraph-> SetMarkerStyle(5) ;
191 digitgraph-> SetMarkerSize(1.) ;
192 digitgraph-> SetMarkerColor(1) ;
193 digitgraph-> Draw("P") ;
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,"") ;
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("");
230 //____________________________________________________________________________
231 void AliPHOSRecPoint::EvalAll(TClonesArray * digits)
233 //evaluates (if necessary) all RecPoint data members
235 EvalPrimaries(digits) ;
238 //____________________________________________________________________________
239 void AliPHOSRecPoint::EvalPHOSMod(AliPHOSDigit * digit)
241 // Returns the PHOS module in which the RecPoint is found
246 AliPHOSGeometry * phosgeom = (AliPHOSGetter::Instance())->PHOSGeometry();
248 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
253 //______________________________________________________________________________
254 void AliPHOSRecPoint::EvalPrimaries(TClonesArray * digits)
256 // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
258 AliPHOSDigit * digit ;
259 Int_t * tempo = new Int_t[fMaxTrack] ;
262 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
263 digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ;
264 Int_t nprimaries = digit->GetNprimary() ;
266 Int_t * newprimaryarray = new Int_t[nprimaries] ;
268 for ( ii = 0 ; ii < nprimaries ; ii++)
269 newprimaryarray[ii] = digit->GetPrimary(ii+1) ;
272 for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
273 if ( fMulTrack > fMaxTrack ) {
275 Error("EvalPrimaries", "GetNprimaries ERROR > increase fMaxTrack" ) ;
278 Int_t newprimary = newprimaryarray[jndex] ;
280 Bool_t already = kFALSE ;
281 for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
282 if ( newprimary == tempo[kndex] ){
287 if ( !already) { // store it
288 tempo[fMulTrack] = newprimary ;
291 } // all primaries in digit
292 delete [] newprimaryarray ;
297 if(fTracksList)delete [] fTracksList;
298 fTracksList = new Int_t[fMulTrack] ;
300 for(index = 0; index < fMulTrack; index++)
301 fTracksList[index] = tempo[index] ;
306 //____________________________________________________________________________
307 void AliPHOSRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrixF & gmat) const
309 // returns the position of the cluster in the global reference system of ALICE
310 // and the uncertainty on this position
312 (AliPHOSGetter::Instance())->PHOSGeometry()->GetGlobalPHOS(this, gpos, gmat);
315 // GetGlobalXYZ(xyz);
316 // gpos.SetXYZ(xyz[0],xyz[1],xyz[2]);
322 //______________________________________________________________________________
323 void AliPHOSRecPoint::Paint(Option_t *)
325 // Paint this ALiRecPoint as a TMarker with its current attributes
327 TVector3 pos(0.,0.,0.) ;
328 GetLocalPosition(pos) ;
329 Coord_t x = pos.X() ;
330 Coord_t y = pos.Z() ;
331 Color_t markercolor = 1 ;
332 Size_t markersize = 1. ;
333 Style_t markerstyle = 5 ;
335 if (!gPad->IsBatch()) {
336 gVirtualX->SetMarkerColor(markercolor) ;
337 gVirtualX->SetMarkerSize (markersize) ;
338 gVirtualX->SetMarkerStyle(markerstyle) ;
340 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
341 gPad->PaintPolyMarker(1,&x,&y,"") ;
343 //______________________________________________________________________________
344 void AliPHOSRecPoint::GetLocalPosition(TVector3 & pos) const
346 // returns the position of the cluster in the local reference system
347 // of the sub-detector
352 //____________________________________________________________________________
353 void AliPHOSRecPoint::EvalLocal2TrackingCSTransform()
355 //Evaluates local to "tracking" c.s. transformation (B.P.).
356 //All evaluations should be completed before calling for this function.
357 //See ALICE PPR Chapter 5 p.18 for "tracking" c.s. definition,
358 //or just ask Jouri Belikov. :)
361 SetVolumeId(AliGeomManager::LayerToVolUID(AliGeomManager::kPHOS1,GetPHOSMod()-1));
364 SetVolumeId(AliGeomManager::LayerToVolUID(AliGeomManager::kPHOS2,GetPHOSMod()-1));
366 Double_t lxyz[3] = {fLocPos.X(),fLocPos.Y(),fLocPos.Z()};
367 Double_t txyz[3] = {0,0,0};
369 Double_t crystalShift;
371 AliPHOSGeometry * phosgeom = (AliPHOSGetter::Instance())->PHOSGeometry();
372 AliPHOSEMCAGeometry* geoEMCA = phosgeom->GetEMCAGeometry();
374 //Calculate offset to crystal surface.
375 //See fCrystalShift code in AliPHOSGeometry::Init()).
377 Float_t * inthermo = geoEMCA->GetInnerThermoHalfSize() ;
378 Float_t * strip = geoEMCA->GetStripHalfSize() ;
379 Float_t* splate = geoEMCA->GetSupportPlateHalfSize();
380 Float_t * crystal = geoEMCA->GetCrystalHalfSize() ;
381 Float_t * pin = geoEMCA->GetAPDHalfSize() ;
382 Float_t * preamp = geoEMCA->GetPreampHalfSize() ;
383 crystalShift = -inthermo[1]+strip[1]+splate[1]+crystal[1]-geoEMCA->GetAirGapLed()/2.+pin[1]+preamp[1] ;
387 lxyz[2] = -lxyz[2]; //Opposite z directions in EMC matrix and local frame!!!
390 dy = phosgeom->GetCPVBoxSize(1)/2.; //center of CPV module
392 lxyz[1] = lxyz[1] - dy;
394 const TGeoHMatrix* tr2loc = GetTracking2LocalMatrix();
395 if(!tr2loc) AliFatal(Form("No Tracking2LocalMatrix found."));
397 tr2loc->MasterToLocal(lxyz,txyz);
398 SetX(txyz[0]); SetY(txyz[1]); SetZ(txyz[2]);
400 if(AliLog::GetGlobalDebugLevel()>0) {
401 TVector3 gpos; TMatrixF gmat;
402 GetGlobalPosition(gpos,gmat);
410 AliInfo(Form("lCS-->(%.3f,%.3f,%.3f), tCS-->(%.3f,%.3f,%.3f), gCS-->(%.3f,%.3f,%.3f), gCScalc-->(%.3f,%.3f,%.3f), module %d %s",
411 fLocPos.X(),fLocPos.Y(),fLocPos.Z(),
412 GetX(),GetY(),GetZ(),
413 gpos.X(),gpos.Y(),gpos.Z(),
414 gxyz[0],gxyz[1],gxyz[2],GetPHOSMod(),emc.Data()));