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