Xi(b) (pdg code 5232) added to Pdg data base.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrackSegmentMakerv1.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 **************************************************************************/
15
b2a60966 16/* $Id$ */
17
d15a28e7 18//_________________________________________________________________________
b2a60966 19// Implementation version 1 of algorithm class to construct PHOS track segments
20// Associates EMC and PPSD clusters
21// Unfolds the EMC cluster
22//
23//*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH)
24//
d15a28e7 25
26// --- ROOT system ---
27
28#include "TObjArray.h"
29#include "TClonesArray.h"
9f616d61 30#include "TObjectTable.h"
d15a28e7 31
32// --- Standard library ---
33
de9ec31b 34#include <iostream.h>
d15a28e7 35
36// --- AliRoot header files ---
37
38#include "AliPHOSTrackSegmentMakerv1.h"
98cbd830 39#include "AliPHOSIndexToObject.h"
d15a28e7 40#include "AliPHOSTrackSegment.h"
41#include "AliPHOSLink.h"
42#include "AliPHOSv0.h"
43#include "AliRun.h"
44
92862013 45extern void UnfoldingChiSquare(Int_t &nPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag) ;
9f616d61 46
d15a28e7 47ClassImp( AliPHOSTrackSegmentMakerv1)
48
49
50//____________________________________________________________________________
b2a60966 51 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
d15a28e7 52{
9f616d61 53 // ctor
b2a60966 54
28c3a259 55 fR0 = 10. ;
d15a28e7 56 //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0),
98cbd830 57 fDelta = fR0 + fGeom->GetCrystalSize(0) ;
6727be7e 58 fMinuit = new TMinuit(100) ;
59 fUnfoldFlag = kTRUE ;
d15a28e7 60}
61
9f616d61 62//____________________________________________________________________________
63 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
64{
65 // dtor
b2a60966 66
67 delete fMinuit ;
9f616d61 68}
b2a60966 69
d15a28e7 70//____________________________________________________________________________
71Bool_t AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
92862013 72 Int_t nPar, Float_t * fitparameters)
9f616d61 73{
b2a60966 74 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
6ad0bfa0 75
9f616d61 76 gMinuit->SetPrintLevel(-1) ; // No Printout
77 gMinuit->SetFCN(UnfoldingChiSquare) ; // To set the address of the minimization function
78 gMinuit->SetObjectFit(emcRP) ; // To tranfer pointer to UnfoldingChiSquare
79
80 // filling initial values for fit parameters
d15a28e7 81 AliPHOSDigit * digit ;
9f616d61 82
83 Int_t ierflg = 0;
84 Int_t index = 0 ;
92862013 85 Int_t nDigits = (Int_t) nPar / 3 ;
9f616d61 86
d15a28e7 87 Int_t iDigit ;
9f616d61 88
89
92862013 90 for(iDigit = 0; iDigit < nDigits; iDigit++){
d15a28e7 91 digit = (AliPHOSDigit *) maxAt[iDigit];
92
92862013 93 Int_t relid[4] ;
d15a28e7 94 Float_t x ;
95 Float_t z ;
98cbd830 96 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
97 fGeom->RelPosInModule(relid, x, z) ;
d15a28e7 98
92862013 99 Float_t energy = maxAtEnergy[iDigit] ;
d15a28e7 100
9f616d61 101 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
102 index++ ;
d15a28e7 103 if(ierflg != 0){
104 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
105 return kFALSE;
106 }
9f616d61 107 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
108 index++ ;
d15a28e7 109 if(ierflg != 0){
110 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
111 return kFALSE;
112 }
92862013 113 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
9f616d61 114 index++ ;
d15a28e7 115 if(ierflg != 0){
92862013 116 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
d15a28e7 117 return kFALSE;
6ad0bfa0 118 }
d15a28e7 119 }
120
9f616d61 121 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
122 // depends on it.
123 Double_t p1 = 1.0 ;
124 Double_t p2 = 0.0 ;
125
126 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TgMinuit to reduce function calls
127 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
d15a28e7 128 gMinuit->SetMaxIterations(5);
9f616d61 129 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
98cbd830 130
9f616d61 131 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
98cbd830 132
9f616d61 133 if(ierflg == 4){ // Minimum not found
134 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
d15a28e7 135 return kFALSE ;
136 }
92862013 137 for(index = 0; index < nPar; index++){
d15a28e7 138 Double_t err ;
139 Double_t val ;
9f616d61 140 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
92862013 141 fitparameters[index] = val ;
d15a28e7 142 }
98cbd830 143
d15a28e7 144 return kTRUE;
9f616d61 145
d15a28e7 146}
9f616d61 147
d15a28e7 148//____________________________________________________________________________
98cbd830 149void AliPHOSTrackSegmentMakerv1::FillOneModule(AliPHOSRecPoint::RecPointsList * emcIn,
28c3a259 150 TArrayI * emcOut,
88714635 151 AliPHOSRecPoint::RecPointsList * ppsdIn,
28c3a259 152 TArrayI * ppsdOutUp,
153 TArrayI * ppsdOutLow,
88714635 154 Int_t & phosmod,
155 Int_t & emcStopedAt,
156 Int_t & ppsdStopedAt)
9f616d61 157{
0336aa72 158 // Fill xxxOut arrays with clusters from one PHOS module EMC+PPSD
9f616d61 159
160 AliPHOSEmcRecPoint * emcRecPoint ;
d15a28e7 161 AliPHOSPpsdRecPoint * ppsdRecPoint ;
162 Int_t index ;
6ad0bfa0 163
92862013 164 Int_t nEmcUnfolded = emcIn->GetEntries() ;
28c3a259 165 emcOut->Set(nEmcUnfolded);
166 Int_t inEmcOut = 0 ;
92862013 167 for(index = emcStopedAt; index < nEmcUnfolded; index++){
6ad0bfa0 168
98cbd830 169 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
9f616d61 170
98cbd830 171 if(emcRecPoint->GetPHOSMod() != phosmod )
172 break ;
31aa6d6c 173
28c3a259 174 emcOut->AddAt(emcRecPoint->GetIndexInList(),inEmcOut) ;
175 inEmcOut++ ;
d15a28e7 176 }
28c3a259 177 emcOut->Set(inEmcOut) ;
178
d15a28e7 179 emcStopedAt = index ;
180
28c3a259 181 ppsdOutLow->Set(ppsdIn->GetEntries()) ;
182 ppsdOutUp->Set(ppsdIn->GetEntries()) ;
183 Int_t inPpsdLow = 0;
184 Int_t inPpsdUp = 0;
d15a28e7 185 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
83974468 186 ppsdRecPoint = (AliPHOSPpsdRecPoint *) ppsdIn->At(index) ;
92862013 187 if(ppsdRecPoint->GetPHOSMod() != phosmod )
9f616d61 188 break ;
d15a28e7 189 if(ppsdRecPoint->GetUp() )
28c3a259 190 ppsdOutUp->AddAt(index,inPpsdUp++) ;
d15a28e7 191 else
28c3a259 192 ppsdOutLow->AddAt(index,inPpsdLow++) ;
d15a28e7 193 }
28c3a259 194 ppsdOutLow->Set(inPpsdLow);
195 ppsdOutUp->Set(inPpsdUp);
d15a28e7 196 ppsdStopedAt = index ;
6ad0bfa0 197
0336aa72 198}
199//____________________________________________________________________________
200void AliPHOSTrackSegmentMakerv1::FillOneModule(AliPHOSRecPoint::RecPointsList * emcIn,
201 TArrayI * emcOut,
202 AliPHOSRecPoint::RecPointsList * cpvIn,
203 TArrayI * cpvOut,
204 Int_t & phosmod,
205 Int_t & emcStopedAt,
206 Int_t & cpvStopedAt)
207{
208 // Fill xxxOut arrays with clusters from one PHOS module EMC+CPV
209
210 AliPHOSEmcRecPoint * emcRecPoint ;
211 AliPHOSEmcRecPoint * cpvRecPoint ;
212 Int_t index ;
213
214 Int_t nEmcUnfolded = emcIn->GetEntries() ;
215 emcOut->Set(nEmcUnfolded);
216 Int_t inEmcOut = 0 ;
217 for(index = emcStopedAt; index < nEmcUnfolded; index++){
218 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
219 if(emcRecPoint->GetPHOSMod() != phosmod )
220 break ;
221
222 emcOut->AddAt(emcRecPoint->GetIndexInList(),inEmcOut) ;
223 inEmcOut++ ;
224 }
225 emcOut->Set(inEmcOut) ;
226 emcStopedAt = index ;
227
228 cpvOut->Set(cpvIn->GetEntries()) ;
229 Int_t inCpvOut = 0;
230 for(index = cpvStopedAt; index < cpvIn->GetEntries(); index++){
231 cpvRecPoint = (AliPHOSEmcRecPoint *) cpvIn->At(index) ;
232 if(cpvRecPoint->GetPHOSMod() != phosmod )
233 break ;
234 else
235 cpvOut->AddAt(index,inCpvOut++) ;
236 }
237 cpvOut->Set(inCpvOut);
238 cpvStopedAt = index ;
239
d15a28e7 240}
241//____________________________________________________________________________
92862013 242Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcclu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &toofar)
d15a28e7 243{
b2a60966 244 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
245
92862013 246 Float_t r = fR0 ;
d15a28e7 247
248 TVector3 vecEmc ;
249 TVector3 vecPpsd ;
250
92862013 251 emcclu->GetLocalPosition(vecEmc) ;
d15a28e7 252 PpsdClu->GetLocalPosition(vecPpsd) ;
92862013 253 if(emcclu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
d15a28e7 254 if(vecPpsd.X() >= vecEmc.X() - fDelta ){
255 if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
6ad0bfa0 256 // Correct to difference in CPV and EMC position due to different distance to center.
257 // we assume, that particle moves from center
98cbd830 258 Float_t dCPV = fGeom->GetIPtoOuterCoverDistance();
259 Float_t dEMC = fGeom->GetIPtoCrystalSurface() ;
92862013 260 dEMC = dEMC / dCPV ;
261 vecPpsd = dEMC * vecPpsd - vecEmc ;
262 r = vecPpsd.Mag() ;
d15a28e7 263 } // if zPpsd >= zEmc - fDelta
92862013 264 toofar = kFALSE ;
d15a28e7 265 } // if xPpsd >= xEmc - fDelta
266 else
92862013 267 toofar = kTRUE ;
d15a28e7 268 }
269 else
92862013 270 toofar = kTRUE ;
d15a28e7 271
92862013 272 return r ;
d15a28e7 273}
274
275//____________________________________________________________________________
28c3a259 276void AliPHOSTrackSegmentMakerv1::MakeLinks(TArrayI * emcRecPoints, TArrayI * ppsdRecPointsUp,
277 TArrayI * ppsdRecPointsLow, TClonesArray * linklowArray,
92862013 278 TClonesArray *linkupArray)
d15a28e7 279{
b2a60966 280 // Finds distances (links) between all EMC and PPSD clusters, which are not further apart from each other than fR0
281
d15a28e7 282
92862013 283 AliPHOSPpsdRecPoint * ppsdlow ;
284 AliPHOSPpsdRecPoint * ppsdup ;
285 AliPHOSEmcRecPoint * emcclu ;
28c3a259 286
d15a28e7 287 Int_t iLinkLow = 0 ;
288 Int_t iLinkUp = 0 ;
289
28c3a259 290 Int_t iEmcRP;
291
292 for(iEmcRP = 0; iEmcRP < emcRecPoints->GetSize(); iEmcRP++ ) {
293 emcclu = (AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emcRecPoints->At(iEmcRP),"emc") ;
92862013 294 Bool_t toofar ;
d15a28e7 295
28c3a259 296 Int_t iPpsdLow ;
297
298 for(iPpsdLow = 0; iPpsdLow < ppsdRecPointsLow->GetSize();iPpsdLow++ ) {
299
300 ppsdlow = (AliPHOSPpsdRecPoint *) fPlease->GimeRecPoint(ppsdRecPointsLow->At(iPpsdLow),"ppsd") ;
92862013 301 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdlow, toofar) ;
d15a28e7 302
92862013 303 if(toofar)
d15a28e7 304 break ;
83974468 305 if(r < fR0){
28c3a259 306 new( (*linklowArray)[iLinkLow++]) AliPHOSLink(r, iEmcRP, iPpsdLow) ;
307 }
d15a28e7 308 }
309
28c3a259 310 Int_t iPpsdUp = 0 ;
311 for(iPpsdUp = 0; iPpsdUp < ppsdRecPointsUp->GetSize();iPpsdUp++ ) {
312
313 ppsdup = (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdRecPointsUp->At(iPpsdUp),"ppsd") ;
92862013 314 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdup, toofar) ;
d15a28e7 315
92862013 316 if(toofar)
d15a28e7 317 break ;
83974468 318 if(r < fR0) {
28c3a259 319 new( (*linkupArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iPpsdUp) ;
320 }
d15a28e7 321 }
28c3a259 322 }
d15a28e7 323
92862013 324 linklowArray->Sort() ; //first links with smallest distances
325 linkupArray->Sort() ;
d15a28e7 326}
28c3a259 327
d15a28e7 328//____________________________________________________________________________
28c3a259 329void AliPHOSTrackSegmentMakerv1::MakePairs(TArrayI * emcRecPoints,
330 TArrayI * ppsdRecPointsUp,
331 TArrayI * ppsdRecPointsLow,
88714635 332 TClonesArray * linklowArray,
333 TClonesArray * linkupArray,
334 AliPHOSTrackSegment::TrackSegmentsList * trsl)
6ad0bfa0 335{
336
337 // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
338
92862013 339 TIter nextLow(linklowArray) ;
340 TIter nextUp(linkupArray) ;
d15a28e7 341
342 AliPHOSLink * linkLow ;
343 AliPHOSLink * linkUp ;
344
28c3a259 345 Int_t emc ;
346 Int_t ppsdLow ;
347 Int_t ppsdUp ;
d15a28e7 348
28c3a259 349 AliPHOSPpsdRecPoint * nullpointer = 0 ;
350 ppsdUp = 0 ;
9f616d61 351
d15a28e7 352 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
28c3a259 353
354 emc = emcRecPoints->At(linkLow->GetEmc()) ;
355 ppsdLow = ppsdRecPointsLow->At(linkLow->GetPpsd()) ;
356 if( (emc >= 0) && (ppsdLow >= 0) ){ // RecPoints not removed yet
357
358 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *)fPlease->GimeRecPoint(emc,"emc"),
359 nullpointer,
360 (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdLow,"ppsd") ) ;
361 ((AliPHOSTrackSegment* )trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
362 //replace index of emc to negative and shifted index of TS
363 emcRecPoints->AddAt(-2 - fNTrackSegments,linkLow->GetEmc()) ;
364 //replace index of emc to negative and shifted index of TS
365 ppsdRecPointsLow->AddAt(-2 - fNTrackSegments,linkLow->GetPpsd()) ;
366 fNTrackSegments++ ;
367
6ad0bfa0 368 }
d15a28e7 369 }
28c3a259 370
371 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
372 emc = emcRecPoints->At(linkUp->GetEmc()) ;
373 if(emc != -1){ //without ppsd Up yet
d15a28e7 374
28c3a259 375 ppsdUp = ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
376
377 if(emc >= 0){ //without ppsd Low => create new TS
378
379 fNTrackSegments = trsl->GetEntries() ;
380 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emc,"emc"),
381 (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdUp,"ppsd"),
382 nullpointer) ;
383 ((AliPHOSTrackSegment *) trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
384 fNTrackSegments++ ;
385 }
386 else{ // append ppsd Up to existing TS
387 ((AliPHOSTrackSegment *)trsl->At(-2-emc))->SetPpsdUpRecPoint((AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdUp,"ppsd"));
d15a28e7 388 }
28c3a259 389 emcRecPoints->AddAt(-1,linkUp->GetEmc()) ; //Mark that PPSD Up found
d15a28e7 390
28c3a259 391 }
392 }
393
394 Int_t iEmcRP ;
395 for(iEmcRP = 0; iEmcRP <emcRecPoints->GetSize() ; iEmcRP++ ){
396 emc = emcRecPoints->At(iEmcRP) ;
397 if(emc >=0 ){
398 ppsdUp = 0;
399 ppsdLow = 0;
400 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emc,"emc"),
401 nullpointer, nullpointer ) ;
402 ((AliPHOSTrackSegment *) trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
403 fNTrackSegments++;
d15a28e7 404 }
b2a60966 405
d15a28e7 406 }
28c3a259 407
d15a28e7 408}
409
410//____________________________________________________________________________
88714635 411void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * dl,
412 AliPHOSRecPoint::RecPointsList * emcl,
413 AliPHOSRecPoint::RecPointsList * ppsdl,
414 AliPHOSTrackSegment::TrackSegmentsList * trsl)
d15a28e7 415{
b2a60966 416 // Makes the track segments out of the list of EMC and PPSD Recpoints and stores them in a list
98cbd830 417
92862013 418 Int_t phosmod = 1 ;
9f616d61 419 Int_t emcStopedAt = 0 ;
d15a28e7 420 Int_t ppsdStopedAt = 0 ;
28c3a259 421
422 fNTrackSegments = 0 ;
423
d15a28e7 424
28c3a259 425 TArrayI * emcRecPoints = new TArrayI(1000) ; // these arrays keep indexes
426 TArrayI * ppsdRecPointsUp = new TArrayI(1000) ; // of RecPoints, which are
427 TArrayI * ppsdRecPointsLow = new TArrayI(1000) ; // kept in TClonesArray's emcl and ppsdl
d15a28e7 428
429
92862013 430 TClonesArray * linklowArray = new TClonesArray("AliPHOSLink", 100);
431 TClonesArray * linkupArray = new TClonesArray("AliPHOSLink", 100);
6ad0bfa0 432
28c3a259 433
98cbd830 434 if(fUnfoldFlag){
0336aa72 435 UnfoldAll(dl, emcl) ; // Unfolds all EMC clusters
98cbd830 436 }
d15a28e7 437
28c3a259 438
98cbd830 439 while(phosmod <= fGeom->GetNModules() ){
440
441 FillOneModule(emcl, emcRecPoints, ppsdl, ppsdRecPointsUp, ppsdRecPointsLow, phosmod, emcStopedAt, ppsdStopedAt) ;
442
443 MakeLinks(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray) ;
444
92862013 445 MakePairs(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray, trsl) ;
98cbd830 446
28c3a259 447 emcRecPoints->Reset() ;
98cbd830 448
28c3a259 449 ppsdRecPointsUp->Reset() ;
98cbd830 450
28c3a259 451 ppsdRecPointsLow->Reset() ;
98cbd830 452
92862013 453 linkupArray->Clear() ;
98cbd830 454
92862013 455 linklowArray->Clear() ;
98cbd830 456
92862013 457 phosmod++ ;
d15a28e7 458 }
28c3a259 459
92862013 460 delete emcRecPoints ;
461 emcRecPoints = 0 ;
98cbd830 462
92862013 463 delete ppsdRecPointsUp ;
464 ppsdRecPointsUp = 0 ;
9f616d61 465
92862013 466 delete ppsdRecPointsLow ;
467 ppsdRecPointsLow = 0 ;
9f616d61 468
92862013 469 delete linkupArray ;
470 linkupArray = 0 ;
9f616d61 471
92862013 472 delete linklowArray ;
473 linklowArray = 0 ;
d15a28e7 474}
475
0336aa72 476//____________________________________________________________________________
477void AliPHOSTrackSegmentMakerv1::MakeTrackSegmentsCPV(DigitsList * dl,
478 AliPHOSRecPoint::RecPointsList * emcl,
479 AliPHOSRecPoint::RecPointsList * cpvl)
480{
481 // Unfold clusters in EMC and CPV and refill reconstructed point lists emcl and ppsdl
482 // Yuri Kharlov. 19 October 2000
483
484 fNTrackSegments = 0 ;
485
486 TArrayI * emcRecPoints = new TArrayI(1000) ; // these arrays keep indexes
487 TArrayI * cpvRecPoints = new TArrayI(1000) ; // of RecPoints, which are kept in emcl and ppsdl
488
489 if(fUnfoldFlag){
490 UnfoldAll(dl, emcl) ; // Unfolds all EMC clusters
491 UnfoldAll(dl, cpvl) ; // Unfolds all CPV clusters
492 }
493
494// Int_t phosmod = 1 ;
495// Int_t emcStopedAt = 0 ;
496// Int_t cpvStopedAt = 0 ;
497// while(phosmod <= fGeom->GetNModules() ){
498// FillOneModule(emcl, emcRecPoints, ppsdl, cpvRecPoints, phosmod, emcStopedAt, cpvStopedAt) ;
499// emcRecPoints->Reset() ;
500// cpvRecPoints->Reset() ;
501// phosmod++ ;
502// }
503
504 delete emcRecPoints ; emcRecPoints = 0 ;
505 delete cpvRecPoints ; cpvRecPoints = 0 ;
506}
507
d15a28e7 508//____________________________________________________________________________
9f616d61 509Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r)
510{
b2a60966 511 // Shape of the shower (see PHOS TDR)
512 // If you change this function, change also the gradien evaluation in ChiSquare()
513
6ad0bfa0 514 Double_t r4 = r*r*r*r ;
515 Double_t r295 = TMath::Power(r, 2.95) ;
d15a28e7 516 Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ;
517 return shape ;
518}
519
98cbd830 520//____________________________________________________________________________
521void AliPHOSTrackSegmentMakerv1::UnfoldAll(DigitsList * dl, AliPHOSRecPoint::RecPointsList * emcIn)
522{
523 // Performs unfolding of all EMC clusters, sorts them and resets indexes in RecPoints
524
525 AliPHOSEmcRecPoint * emcRecPoint ;
526 Int_t index ;
527 Int_t nEmcUnfolded = emcIn->GetEntries() ;
528
529 for(index = 0 ; index < nEmcUnfolded; index++){
530
0336aa72 531 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
98cbd830 532
0336aa72 533 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
534 Int_t * maxAt = new Int_t[nMultipl] ;
98cbd830 535 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
536 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
537
538 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
98cbd830 539 UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy) ;
540 emcIn->Remove(emcRecPoint);
541 emcIn->Compress() ;
542 index-- ;
543 nEmcUnfolded-- ;
544 }
545
546 delete[] maxAt ;
547 delete[] maxAtEnergy ;
548 } //Unfolding finished
549
550 emcIn->Sort() ;
551
552 // to set index to new and correct index of old RecPoints
28c3a259 553 for( index = 0 ; index < emcIn->GetEntries() ; index++){
98cbd830 554 ((AliPHOSEmcRecPoint *) emcIn->At(index))->SetIndexInList(index) ;
98cbd830 555 }
556
28c3a259 557 emcIn->Sort() ;
558
98cbd830 559}
d15a28e7 560//____________________________________________________________________________
88714635 561void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * dl,
562 AliPHOSRecPoint::RecPointsList * emcIn,
563 AliPHOSEmcRecPoint * iniEmc,
564 Int_t nMax,
565 int * maxAt,
98cbd830 566 Float_t * maxAtEnergy)
d15a28e7 567{
b2a60966 568 // Performs the unfolding of a cluster with nMax overlapping showers
569 // This is time consuming (use the (Un)SetUnfolFlag() )
570
92862013 571 Int_t nPar = 3 * nMax ;
31aa6d6c 572 Float_t * fitparameters = new Float_t[nPar] ;
98cbd830 573
9f616d61 574
92862013 575 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
31aa6d6c 576 if( !rv ) {
577 // Fit failed, return and remove cluster
578 delete[] fitparameters ;
d15a28e7 579 return ;
31aa6d6c 580 }
98cbd830 581
582
d15a28e7 583 Float_t xDigit ;
584 Float_t zDigit ;
92862013 585 Int_t relid[4] ;
d15a28e7 586
92862013 587 Int_t nDigits = iniEmc->GetMultiplicity() ;
d15a28e7 588 Float_t xpar ;
589 Float_t zpar ;
92862013 590 Float_t epar ;
591 Float_t distance ;
592 Float_t ratio ;
31aa6d6c 593 Float_t * efit = new Float_t[nDigits] ;
d15a28e7 594 Int_t iparam ;
595 Int_t iDigit ;
596
597 AliPHOSDigit * digit ;
598 AliPHOSEmcRecPoint * emcRP ;
6ad0bfa0 599 Int_t * emcDigits = iniEmc->GetDigitsList() ;
d15a28e7 600 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
601
602 Int_t iRecPoint = emcIn->GetEntries() ;
603
92862013 604 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
98cbd830 605 digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;
606 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
607 fGeom->RelPosInModule(relid, xDigit, zDigit) ;
92862013 608 efit[iDigit] = 0;
d15a28e7 609 iparam = 0 ;
610
92862013 611 while(iparam < nPar ){
612 xpar = fitparameters[iparam] ;
613 zpar = fitparameters[iparam+1] ;
614 epar = fitparameters[iparam+2] ;
d15a28e7 615 iparam += 3 ;
92862013 616 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
617 distance = TMath::Sqrt(distance) ;
b2a60966 618 efit[iDigit] += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
d15a28e7 619 }
d15a28e7 620 }
621
622 iparam = 0 ;
623 Float_t eDigit ;
624
98cbd830 625
92862013 626 while(iparam < nPar ){
627 xpar = fitparameters[iparam] ;
628 zpar = fitparameters[iparam+1] ;
629 epar = fitparameters[iparam+2] ;
d15a28e7 630 iparam += 3 ;
98cbd830 631
28c3a259 632 if(iRecPoint >= emcIn->GetSize())
633 emcIn->Expand(2*iRecPoint) ;
634 (*emcIn)[iRecPoint] = new AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
635
98cbd830 636 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint);
637 iRecPoint++ ;
d15a28e7 638
92862013 639 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
98cbd830 640 digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;
641 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
642 fGeom->RelPosInModule(relid, xDigit, zDigit) ;
92862013 643 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
644 distance = TMath::Sqrt(distance) ;
b2a60966 645 ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ;
92862013 646 eDigit = emcEnergies[iDigit] * ratio ;
9f616d61 647 emcRP->AddDigit( *digit, eDigit ) ;
d15a28e7 648 }
649
d15a28e7 650 }
31aa6d6c 651
652 delete[] fitparameters ;
653 delete[] efit ;
654
d15a28e7 655}
6ad0bfa0 656
d15a28e7 657//______________________________________________________________________________
92862013 658void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
d15a28e7 659{
b2a60966 660 // Calculates th Chi square for the cluster unfolding minimization
661 // Number of parameters, Gradient, Chi squared, parameters, what to do
98cbd830 662
9f616d61 663 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
98cbd830 664
6ad0bfa0 665 Int_t * emcDigits = emcRP->GetDigitsList() ;
98cbd830 666
667 Int_t nOfDigits = emcRP->GetDigitsMultiplicity() ;
668
d15a28e7 669 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
98cbd830 670
671 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
672
673 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
674
d15a28e7 675 fret = 0. ;
676 Int_t iparam ;
677
9f616d61 678 if(iflag == 2)
92862013 679 for(iparam = 0 ; iparam < nPar ; iparam++)
9f616d61 680 Grad[iparam] = 0 ; // Will evaluate gradient
681
98cbd830 682 Double_t efit ;
683
d15a28e7 684 AliPHOSDigit * digit ;
98cbd830 685 Int_t iDigit ;
686
687 for( iDigit = 0 ; iDigit < nOfDigits ; iDigit++) {
688
689 digit = please->GimeDigit( emcDigits[iDigit] ) ;
9f616d61 690
92862013 691 Int_t relid[4] ;
d15a28e7 692 Float_t xDigit ;
693 Float_t zDigit ;
98cbd830 694
92862013 695 geom->AbsToRelNumbering(digit->GetId(), relid) ;
98cbd830 696
92862013 697 geom->RelPosInModule(relid, xDigit, zDigit) ;
98cbd830 698
9f616d61 699 if(iflag == 2){ // calculate gradient
700 Int_t iParam = 0 ;
92862013 701 efit = 0 ;
702 while(iParam < nPar ){
703 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
9f616d61 704 iParam++ ;
92862013 705 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
706 distance = TMath::Sqrt( distance ) ;
9f616d61 707 iParam++ ;
92862013 708 efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
9f616d61 709 iParam++ ;
710 }
92862013 711 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
9f616d61 712 iParam = 0 ;
92862013 713 while(iParam < nPar ){
9f616d61 714 Double_t xpar = x[iParam] ;
715 Double_t zpar = x[iParam+1] ;
92862013 716 Double_t epar = x[iParam+2] ;
9f616d61 717 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
718 Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ;
719 Double_t r4 = dr*dr*dr*dr ;
720 Double_t r295 = TMath::Power(dr,2.95) ;
721 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
722 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
723
92862013 724 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
9f616d61 725 iParam++ ;
92862013 726 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
9f616d61 727 iParam++ ;
728 Grad[iParam] += shape ; // Derivative over energy
729 iParam++ ;
730 }
731 }
92862013 732 efit = 0;
9f616d61 733 iparam = 0 ;
98cbd830 734
92862013 735 while(iparam < nPar ){
9f616d61 736 Double_t xpar = x[iparam] ;
737 Double_t zpar = x[iparam+1] ;
92862013 738 Double_t epar = x[iparam+2] ;
9f616d61 739 iparam += 3 ;
92862013 740 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
741 distance = TMath::Sqrt(distance) ;
742 efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
9f616d61 743 }
98cbd830 744
92862013 745 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
9f616d61 746 // Here we assume, that sigma = sqrt(E)
d15a28e7 747 }
98cbd830 748
d15a28e7 749}