Adaption to new fluka common blocks (E. Futo)
[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"
2731cd1e 25#include "TClonesArray.h"
55fe9d13 26#include "TGraph.h"
27#include "TPaveText.h"
d15a28e7 28
29// --- Standard library ---
30
31// --- AliRoot header files ---
32
33#include "AliPHOSGeometry.h"
34#include "AliPHOSDigit.h"
35#include "AliPHOSRecPoint.h"
7b7c1533 36#include "AliPHOSGetter.h"
9f616d61 37
d15a28e7 38ClassImp(AliPHOSRecPoint)
39
40
41//____________________________________________________________________________
42AliPHOSRecPoint::AliPHOSRecPoint()
43 : AliRecPoint()
44{
b2a60966 45 // ctor
46
baef0810 47 fMaxTrack = 200 ;
d15a28e7 48 fPHOSMod = 0;
4b45b217 49
d15a28e7 50}
51
52//____________________________________________________________________________
73a68ccb 53AliPHOSRecPoint::AliPHOSRecPoint(const char * opt) : AliRecPoint(opt)
54{
55 // ctor
56
57 fMaxTrack = 200 ;
58 fPHOSMod = 0;
59
60}
61
62//____________________________________________________________________________
55fe9d13 63AliPHOSRecPoint::AliPHOSRecPoint(const AliPHOSRecPoint & rp ) : AliRecPoint(rp)
64{
65 // cpy ctor
66
67 fMaxTrack = rp.fMaxTrack;
68 fPHOSMod = rp.fPHOSMod;
69
70}
71
72//____________________________________________________________________________
9f616d61 73Int_t AliPHOSRecPoint::DistancetoPrimitive(Int_t px, Int_t py)
74{
b2a60966 75 // Compute distance from point px,py to a AliPHOSRecPoint considered as a Tmarker
76 // Compute the closest distance of approach from point px,py to this marker.
77 // The distance is computed in pixels units.
78
79 TVector3 pos(0.,0.,0.) ;
80 GetLocalPosition( pos) ;
81 Float_t x = pos.X() ;
82 Float_t y = pos.Z() ;
83 const Int_t kMaxDiff = 10;
84 Int_t pxm = gPad->XtoAbsPixel(x);
85 Int_t pym = gPad->YtoAbsPixel(y);
86 Int_t dist = (px-pxm)*(px-pxm) + (py-pym)*(py-pym);
87
88 if (dist > kMaxDiff) return 9999;
89 return dist;
9f616d61 90}
6ad0bfa0 91
9f616d61 92//___________________________________________________________________________
93 void AliPHOSRecPoint::Draw(Option_t *option)
94 {
6ad0bfa0 95 // Draw this AliPHOSRecPoint with its current attributes
96
97 AppendPad(option);
9f616d61 98 }
99
100//______________________________________________________________________________
cde7e5dc 101void AliPHOSRecPoint::ExecuteEvent(Int_t event, Int_t px, Int_t py) const
9f616d61 102{
6ad0bfa0 103 // Execute action corresponding to one event
104 // This member function is called when a AliPHOSRecPoint is clicked with the locator
105 //
106 // If Left button is clicked on AliPHOSRecPoint, the digits are switched on
107 // and switched off when the mouse button is released.
9f616d61 108
109 // static Int_t pxold, pyold;
110
b2a60966 111 static TGraph * digitgraph = 0 ;
112 static TPaveText* clustertext = 0 ;
113
114 if (!gPad->IsEditable()) return;
9f616d61 115
b2a60966 116 switch (event) {
117
118
119 case kButton1Down:{
120 AliPHOSDigit * digit ;
7b7c1533 121 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
7a9d98f9 122 AliPHOSGeometry * phosgeom = const_cast<AliPHOSGeometry*>(gime->PHOSGeometry());
7b7c1533 123
b2a60966 124 Int_t iDigit;
125 Int_t relid[4] ;
31aa6d6c 126
88714635 127 const Int_t kMulDigit=AliPHOSRecPoint::GetDigitsMultiplicity() ;
128 Float_t * xi = new Float_t [kMulDigit] ;
129 Float_t * zi = new Float_t [kMulDigit] ;
b2a60966 130
88714635 131 for(iDigit = 0; iDigit < kMulDigit; iDigit++) {
4696e514 132 Fatal("AliPHOSRecPoint::ExecuteEvent", "-> Something wrong with the code");
7a9d98f9 133 digit = 0 ; //dynamic_cast<AliPHOSDigit *>((fDigitsList)[iDigit]);
b2a60966 134 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
135 phosgeom->RelPosInModule(relid, xi[iDigit], zi[iDigit]) ;
136 }
137
138 if (!digitgraph) {
139 digitgraph = new TGraph(fMulDigit,xi,zi);
140 digitgraph-> SetMarkerStyle(5) ;
141 digitgraph-> SetMarkerSize(1.) ;
142 digitgraph-> SetMarkerColor(1) ;
143 digitgraph-> Draw("P") ;
144 }
145 if (!clustertext) {
146
147 TVector3 pos(0.,0.,0.) ;
148 GetLocalPosition(pos) ;
149 clustertext = new TPaveText(pos.X()-10,pos.Z()+10,pos.X()+50,pos.Z()+35,"") ;
150 Text_t line1[40] ;
151 Text_t line2[40] ;
152 sprintf(line1,"Energy=%1.2f GeV",GetEnergy()) ;
153 sprintf(line2,"%d Digits",GetDigitsMultiplicity()) ;
154 clustertext ->AddText(line1) ;
155 clustertext ->AddText(line2) ;
156 clustertext ->Draw("");
157 }
158 gPad->Update() ;
159 Print() ;
31aa6d6c 160 delete[] xi ;
161 delete[] zi ;
162 }
b2a60966 163
31aa6d6c 164break;
b2a60966 165
166 case kButton1Up:
167 if (digitgraph) {
168 delete digitgraph ;
169 digitgraph = 0 ;
170 }
171 if (clustertext) {
172 delete clustertext ;
173 clustertext = 0 ;
174 }
175
176 break;
177
9f616d61 178 }
9f616d61 179}
ad8cfaf4 180//____________________________________________________________________________
2731cd1e 181void AliPHOSRecPoint::EvalAll(Float_t logWeight,TClonesArray * digits) {
ad8cfaf4 182 //evaluates (if necessary) all RecPoint data members
9f616d61 183
2731cd1e 184 EvalPrimaries(digits) ;
ad8cfaf4 185}
d15a28e7 186//____________________________________________________________________________
2731cd1e 187void AliPHOSRecPoint::EvalPHOSMod(AliPHOSDigit * digit)
b2a60966 188{
189 // Returns the PHOS module in which the RecPoint is found
83974468 190
2731cd1e 191 if( fPHOSMod == 0){
ad8cfaf4 192 Int_t relid[4] ;
83974468 193
7b7c1533 194 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
7a9d98f9 195 AliPHOSGeometry * phosgeom = const_cast<AliPHOSGeometry*>(gime->PHOSGeometry());
d15a28e7 196
92862013 197 phosgeom->AbsToRelNumbering(digit->GetId(), relid) ;
d15a28e7 198 fPHOSMod = relid[0];
2731cd1e 199 }
d15a28e7 200}
6ad0bfa0 201
9f616d61 202//______________________________________________________________________________
2731cd1e 203void AliPHOSRecPoint::EvalPrimaries(TClonesArray * digits)
cf239357 204{
2731cd1e 205 // Constructs the list of primary particles (tracks) which have contributed to this RecPoint
bb53c80c 206 // First in the list - primary, made strongest contribution to the center
207
b2a60966 208
cf239357 209 AliPHOSDigit * digit ;
2731cd1e 210 Int_t * tempo = new Int_t[fMaxTrack] ;
211
bb53c80c 212 //Find digit in center
213 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("IHEP","") ;
214 if(!geom){
215 Error("EvalPrimaries","Can not instantiate PHOS geometry") ;
216 return ;
217 }
218 TVector3 pos ;
219 TMatrix mat ;
220 GetGlobalPosition(pos,mat) ;
fa8c9a22 221 pos.SetZ(-pos.Z()) ;
bb53c80c 222 Int_t module ;
223 Double_t x,z ;
224 geom->ImpactOnEmc(pos.Theta(),pos.Phi(),module,z,x);
225 Int_t absId ;
226 geom->RelPosToAbsId(module,x,z,absId) ;
227 //copy primaries
2731cd1e 228 Int_t index ;
cf239357 229 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
7a9d98f9 230 digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ;
bb53c80c 231 if(digit->GetId() == absId){
232 fMulTrack = digit->GetNprimary() ;
233 for(Int_t ii = 0 ; ii < fMulTrack ; ii++)
234 tempo[ii] = digit->GetPrimary(ii+1) ;
235 }
236 }
237
238 for ( index = 0 ; index < GetDigitsMultiplicity() ; index++ ) { // all digits
239 digit = dynamic_cast<AliPHOSDigit *>(digits->At( fDigitsList[index] )) ;
240 if(digit->GetId()!=absId){ //already done
241 Int_t nprimaries = digit->GetNprimary() ;
242 if(nprimaries){
243 Int_t * newprimaryarray = new Int_t[nprimaries] ;
244 Int_t ii ;
245 for ( ii = 0 ; ii < nprimaries ; ii++)
246 newprimaryarray[ii] = digit->GetPrimary(ii+1) ;
247
248 Int_t jndex ;
249 for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
250 if ( fMulTrack > fMaxTrack ) {
251 fMulTrack = - 1 ;
252 Error("EvalPrimaries", "GetNprimaries ERROR > increase fMaxTrack" ) ;
884e9693 253 break ;
254 }
bb53c80c 255 Int_t newprimary = newprimaryarray[jndex] ;
256 Int_t kndex ;
257 Bool_t already = kFALSE ;
258 for ( kndex = 0 ; kndex < fMulTrack ; kndex++ ) { //check if not already stored
259 if ( newprimary == tempo[kndex] ){
260 already = kTRUE ;
261 break ;
262 }
263 } // end of check
264 if ( !already) { // store it
265 tempo[fMulTrack] = newprimary ;
266 fMulTrack++ ;
267 } // store it
268 } // all primaries in digit
269 delete [] newprimaryarray ;
270 }
884e9693 271 }
cf239357 272 } // all digits
273
884e9693 274 if(fMulTrack)
275 fTracksList = new Int_t[fMulTrack] ;
2731cd1e 276 for(index = 0; index < fMulTrack; index++)
884e9693 277 fTracksList[index] = tempo[index] ;
278
780a31c1 279 delete [] tempo ;
884e9693 280
cf239357 281}
4b45b217 282//____________________________________________________________________________
283void AliPHOSRecPoint::GetGlobalPosition(TVector3 & gpos, TMatrix & gmat) const
284{
285 // returns the position of the cluster in the global reference system of ALICE
286 // and the uncertainty on this position
287
288
289 AliPHOSGetter::GetInstance()->PHOSGeometry()->GetGlobal(this, gpos, gmat) ;
290
291}
292
cf239357 293
294//______________________________________________________________________________
9f616d61 295void AliPHOSRecPoint::Paint(Option_t *)
296{
b2a60966 297 // Paint this ALiRecPoint as a TMarker with its current attributes
298
299 TVector3 pos(0.,0.,0.) ;
300 GetLocalPosition(pos) ;
301 Coord_t x = pos.X() ;
302 Coord_t y = pos.Z() ;
303 Color_t markercolor = 1 ;
304 Size_t markersize = 1. ;
305 Style_t markerstyle = 5 ;
306
307 if (!gPad->IsBatch()) {
308 gVirtualX->SetMarkerColor(markercolor) ;
309 gVirtualX->SetMarkerSize (markersize) ;
310 gVirtualX->SetMarkerStyle(markerstyle) ;
311 }
312 gPad->SetAttMarkerPS(markercolor,markerstyle,markersize) ;
313 gPad->PaintPolyMarker(1,&x,&y,"") ;
9f616d61 314}