the MIXT geometry (IHEP+GPS2) has been introduced
[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) ;
69183710 58 if(!gMinuit) gMinuit = new TMinuit(100) ;
6727be7e 59 fUnfoldFlag = kTRUE ;
d15a28e7 60}
61
62//____________________________________________________________________________
9f616d61 63 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
64{
65 // dtor
69183710 66
7956ec10 67 delete gMinuit ;
68 gMinuit = 0 ;
9f616d61 69}
b2a60966 70
9f616d61 71//____________________________________________________________________________
d15a28e7 72Bool_t AliPHOSTrackSegmentMakerv1::FindFit(AliPHOSEmcRecPoint * emcRP, int * maxAt, Float_t * maxAtEnergy,
92862013 73 Int_t nPar, Float_t * fitparameters)
9f616d61 74{
b2a60966 75 // Calls TMinuit to fit the energy distribution of a cluster with several maxima
6ad0bfa0 76
9f616d61 77 gMinuit->SetPrintLevel(-1) ; // No Printout
78 gMinuit->SetFCN(UnfoldingChiSquare) ; // To set the address of the minimization function
79 gMinuit->SetObjectFit(emcRP) ; // To tranfer pointer to UnfoldingChiSquare
80
81 // filling initial values for fit parameters
d15a28e7 82 AliPHOSDigit * digit ;
9f616d61 83
84 Int_t ierflg = 0;
85 Int_t index = 0 ;
92862013 86 Int_t nDigits = (Int_t) nPar / 3 ;
9f616d61 87
d15a28e7 88 Int_t iDigit ;
9f616d61 89
90
92862013 91 for(iDigit = 0; iDigit < nDigits; iDigit++){
d15a28e7 92 digit = (AliPHOSDigit *) maxAt[iDigit];
93
92862013 94 Int_t relid[4] ;
d15a28e7 95 Float_t x ;
96 Float_t z ;
98cbd830 97 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
98 fGeom->RelPosInModule(relid, x, z) ;
d15a28e7 99
92862013 100 Float_t energy = maxAtEnergy[iDigit] ;
d15a28e7 101
9f616d61 102 gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ;
103 index++ ;
d15a28e7 104 if(ierflg != 0){
105 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ;
106 return kFALSE;
107 }
9f616d61 108 gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ;
109 index++ ;
d15a28e7 110 if(ierflg != 0){
111 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ;
112 return kFALSE;
113 }
92862013 114 gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ;
9f616d61 115 index++ ;
d15a28e7 116 if(ierflg != 0){
92862013 117 cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ;
d15a28e7 118 return kFALSE;
6ad0bfa0 119 }
d15a28e7 120 }
121
9f616d61 122 Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly
123 // depends on it.
124 Double_t p1 = 1.0 ;
125 Double_t p2 = 0.0 ;
126
69183710 127 gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TMinuit to reduce function calls
9f616d61 128 gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient
d15a28e7 129 gMinuit->SetMaxIterations(5);
9f616d61 130 gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings
98cbd830 131
9f616d61 132 gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize
98cbd830 133
9f616d61 134 if(ierflg == 4){ // Minimum not found
135 cout << "PHOS Unfolding> Fit not converged, cluster abandoned "<< endl ;
d15a28e7 136 return kFALSE ;
137 }
92862013 138 for(index = 0; index < nPar; index++){
d15a28e7 139 Double_t err ;
140 Double_t val ;
9f616d61 141 gMinuit->GetParameter(index, val, err) ; // Returns value and error of parameter index
92862013 142 fitparameters[index] = val ;
d15a28e7 143 }
98cbd830 144
d15a28e7 145 return kTRUE;
9f616d61 146
d15a28e7 147}
9f616d61 148
d15a28e7 149//____________________________________________________________________________
98cbd830 150void AliPHOSTrackSegmentMakerv1::FillOneModule(AliPHOSRecPoint::RecPointsList * emcIn,
28c3a259 151 TArrayI * emcOut,
88714635 152 AliPHOSRecPoint::RecPointsList * ppsdIn,
28c3a259 153 TArrayI * ppsdOutUp,
154 TArrayI * ppsdOutLow,
88714635 155 Int_t & phosmod,
156 Int_t & emcStopedAt,
157 Int_t & ppsdStopedAt)
9f616d61 158{
69183710 159 // Fill xxxOut arrays with clusters from one PHOS module
9f616d61 160
161 AliPHOSEmcRecPoint * emcRecPoint ;
d15a28e7 162 AliPHOSPpsdRecPoint * ppsdRecPoint ;
163 Int_t index ;
6ad0bfa0 164
92862013 165 Int_t nEmcUnfolded = emcIn->GetEntries() ;
28c3a259 166 emcOut->Set(nEmcUnfolded);
167 Int_t inEmcOut = 0 ;
92862013 168 for(index = emcStopedAt; index < nEmcUnfolded; index++){
6ad0bfa0 169
98cbd830 170 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
9f616d61 171
98cbd830 172 if(emcRecPoint->GetPHOSMod() != phosmod )
173 break ;
31aa6d6c 174
28c3a259 175 emcOut->AddAt(emcRecPoint->GetIndexInList(),inEmcOut) ;
176 inEmcOut++ ;
d15a28e7 177 }
28c3a259 178 emcOut->Set(inEmcOut) ;
179
d15a28e7 180 emcStopedAt = index ;
181
28c3a259 182 ppsdOutLow->Set(ppsdIn->GetEntries()) ;
183 ppsdOutUp->Set(ppsdIn->GetEntries()) ;
184 Int_t inPpsdLow = 0;
185 Int_t inPpsdUp = 0;
d15a28e7 186 for(index = ppsdStopedAt; index < ppsdIn->GetEntries(); index++){
83974468 187 ppsdRecPoint = (AliPHOSPpsdRecPoint *) ppsdIn->At(index) ;
92862013 188 if(ppsdRecPoint->GetPHOSMod() != phosmod )
9f616d61 189 break ;
d15a28e7 190 if(ppsdRecPoint->GetUp() )
28c3a259 191 ppsdOutUp->AddAt(index,inPpsdUp++) ;
d15a28e7 192 else
28c3a259 193 ppsdOutLow->AddAt(index,inPpsdLow++) ;
d15a28e7 194 }
28c3a259 195 ppsdOutLow->Set(inPpsdLow);
196 ppsdOutUp->Set(inPpsdUp);
d15a28e7 197 ppsdStopedAt = index ;
6ad0bfa0 198
d15a28e7 199}
200//____________________________________________________________________________
92862013 201Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcclu,AliPHOSPpsdRecPoint * PpsdClu, Bool_t &toofar)
d15a28e7 202{
b2a60966 203 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
204
92862013 205 Float_t r = fR0 ;
d15a28e7 206
207 TVector3 vecEmc ;
208 TVector3 vecPpsd ;
209
92862013 210 emcclu->GetLocalPosition(vecEmc) ;
d15a28e7 211 PpsdClu->GetLocalPosition(vecPpsd) ;
92862013 212 if(emcclu->GetPHOSMod() == PpsdClu->GetPHOSMod()){
7956ec10 213 // if(vecPpsd.X() >= vecEmc.X() - fDelta ){
214 // if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){
6ad0bfa0 215 // Correct to difference in CPV and EMC position due to different distance to center.
216 // we assume, that particle moves from center
98cbd830 217 Float_t dCPV = fGeom->GetIPtoOuterCoverDistance();
218 Float_t dEMC = fGeom->GetIPtoCrystalSurface() ;
92862013 219 dEMC = dEMC / dCPV ;
220 vecPpsd = dEMC * vecPpsd - vecEmc ;
221 r = vecPpsd.Mag() ;
7956ec10 222 // } // if zPpsd >= zEmc - fDelta
92862013 223 toofar = kFALSE ;
7956ec10 224 //} // if xPpsd >= xEmc - fDelta
225 // else
226 //toofar = kTRUE ;
d15a28e7 227 }
228 else
92862013 229 toofar = kTRUE ;
7956ec10 230
231 //toofar = kFALSE ;
232
d15a28e7 233
92862013 234 return r ;
d15a28e7 235}
236
237//____________________________________________________________________________
28c3a259 238void AliPHOSTrackSegmentMakerv1::MakeLinks(TArrayI * emcRecPoints, TArrayI * ppsdRecPointsUp,
239 TArrayI * ppsdRecPointsLow, TClonesArray * linklowArray,
92862013 240 TClonesArray *linkupArray)
d15a28e7 241{
b2a60966 242 // Finds distances (links) between all EMC and PPSD clusters, which are not further apart from each other than fR0
243
d15a28e7 244
92862013 245 AliPHOSPpsdRecPoint * ppsdlow ;
246 AliPHOSPpsdRecPoint * ppsdup ;
247 AliPHOSEmcRecPoint * emcclu ;
28c3a259 248
d15a28e7 249 Int_t iLinkLow = 0 ;
250 Int_t iLinkUp = 0 ;
251
28c3a259 252 Int_t iEmcRP;
253
254 for(iEmcRP = 0; iEmcRP < emcRecPoints->GetSize(); iEmcRP++ ) {
255 emcclu = (AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emcRecPoints->At(iEmcRP),"emc") ;
92862013 256 Bool_t toofar ;
d15a28e7 257
28c3a259 258 Int_t iPpsdLow ;
259
260 for(iPpsdLow = 0; iPpsdLow < ppsdRecPointsLow->GetSize();iPpsdLow++ ) {
261
262 ppsdlow = (AliPHOSPpsdRecPoint *) fPlease->GimeRecPoint(ppsdRecPointsLow->At(iPpsdLow),"ppsd") ;
92862013 263 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdlow, toofar) ;
d15a28e7 264
92862013 265 if(toofar)
d15a28e7 266 break ;
83974468 267 if(r < fR0){
28c3a259 268 new( (*linklowArray)[iLinkLow++]) AliPHOSLink(r, iEmcRP, iPpsdLow) ;
269 }
d15a28e7 270 }
271
28c3a259 272 Int_t iPpsdUp = 0 ;
273 for(iPpsdUp = 0; iPpsdUp < ppsdRecPointsUp->GetSize();iPpsdUp++ ) {
274
275 ppsdup = (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdRecPointsUp->At(iPpsdUp),"ppsd") ;
92862013 276 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdup, toofar) ;
d15a28e7 277
92862013 278 if(toofar)
d15a28e7 279 break ;
83974468 280 if(r < fR0) {
28c3a259 281 new( (*linkupArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iPpsdUp) ;
282 }
d15a28e7 283 }
28c3a259 284 }
d15a28e7 285
92862013 286 linklowArray->Sort() ; //first links with smallest distances
287 linkupArray->Sort() ;
d15a28e7 288}
28c3a259 289
d15a28e7 290//____________________________________________________________________________
28c3a259 291void AliPHOSTrackSegmentMakerv1::MakePairs(TArrayI * emcRecPoints,
292 TArrayI * ppsdRecPointsUp,
293 TArrayI * ppsdRecPointsLow,
88714635 294 TClonesArray * linklowArray,
295 TClonesArray * linkupArray,
296 AliPHOSTrackSegment::TrackSegmentsList * trsl)
6ad0bfa0 297{
298
299 // Finds the smallest links and makes pairs of PPSD and EMC clusters with smallest distance
300
92862013 301 TIter nextLow(linklowArray) ;
302 TIter nextUp(linkupArray) ;
d15a28e7 303
304 AliPHOSLink * linkLow ;
305 AliPHOSLink * linkUp ;
306
28c3a259 307 Int_t emc ;
308 Int_t ppsdLow ;
309 Int_t ppsdUp ;
d15a28e7 310
28c3a259 311 AliPHOSPpsdRecPoint * nullpointer = 0 ;
312 ppsdUp = 0 ;
9f616d61 313
d15a28e7 314 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
28c3a259 315
316 emc = emcRecPoints->At(linkLow->GetEmc()) ;
317 ppsdLow = ppsdRecPointsLow->At(linkLow->GetPpsd()) ;
28c3a259 318
7956ec10 319 if( (emc >= 0) && (ppsdLow >= 0) ){ // RecPoints not removed yet
320
28c3a259 321 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *)fPlease->GimeRecPoint(emc,"emc"),
322 nullpointer,
323 (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdLow,"ppsd") ) ;
324 ((AliPHOSTrackSegment* )trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
325 //replace index of emc to negative and shifted index of TS
326 emcRecPoints->AddAt(-2 - fNTrackSegments,linkLow->GetEmc()) ;
7956ec10 327 //replace index of PPSD Low to negative and shifted index of TS
28c3a259 328 ppsdRecPointsLow->AddAt(-2 - fNTrackSegments,linkLow->GetPpsd()) ;
329 fNTrackSegments++ ;
330
6ad0bfa0 331 }
d15a28e7 332 }
28c3a259 333
334 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
335 emc = emcRecPoints->At(linkUp->GetEmc()) ;
336 if(emc != -1){ //without ppsd Up yet
d15a28e7 337
28c3a259 338 ppsdUp = ppsdRecPointsUp->At(linkUp->GetPpsd()) ;
7956ec10 339 if(ppsdUp >= 0){ //ppsdUp still exist
340
341 if(emc >= 0){ //without ppsd Low => create new TS
342
343 fNTrackSegments = trsl->GetEntries() ;
344 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emc,"emc"),
345 (AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdUp,"ppsd"),
346 nullpointer) ;
347 ((AliPHOSTrackSegment *) trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
348 fNTrackSegments++ ;
349 }
350 else{ // append ppsd Up to existing TS
351 ((AliPHOSTrackSegment *)trsl->At(-2-emc))->SetPpsdUpRecPoint((AliPHOSPpsdRecPoint *)fPlease->GimeRecPoint(ppsdUp,"ppsd"));
352 }
353
354 emcRecPoints->AddAt(-1,linkUp->GetEmc()) ; //Mark that PPSD Up found
355 //replace index of PPSD Up to negative and shifted index of TS
356 ppsdRecPointsUp->AddAt(-2 - fNTrackSegments,linkUp->GetPpsd()) ;
357 } //if ppsdUp still exist
28c3a259 358 }
359 }
360
361 Int_t iEmcRP ;
362 for(iEmcRP = 0; iEmcRP <emcRecPoints->GetSize() ; iEmcRP++ ){
363 emc = emcRecPoints->At(iEmcRP) ;
364 if(emc >=0 ){
365 ppsdUp = 0;
366 ppsdLow = 0;
367 new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fPlease->GimeRecPoint(emc,"emc"),
368 nullpointer, nullpointer ) ;
369 ((AliPHOSTrackSegment *) trsl->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
370 fNTrackSegments++;
d15a28e7 371 }
b2a60966 372
d15a28e7 373 }
28c3a259 374
d15a28e7 375}
376
377//____________________________________________________________________________
88714635 378void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * dl,
379 AliPHOSRecPoint::RecPointsList * emcl,
380 AliPHOSRecPoint::RecPointsList * ppsdl,
b73f246d 381 AliPHOSRecPoint::RecPointsList * cpvl,
88714635 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
b73f246d 400 UnfoldAll(dl, cpvl) ; // Unfolds all CPV clusters
98cbd830 401 }
d15a28e7 402
b73f246d 403 Int_t phosmod = fGeom->GetNCPVModules() + 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
441//____________________________________________________________________________
0336aa72 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
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
485//____________________________________________________________________________
98cbd830 486void AliPHOSTrackSegmentMakerv1::UnfoldAll(DigitsList * dl, AliPHOSRecPoint::RecPointsList * emcIn)
487{
488 // Performs unfolding of all EMC clusters, sorts them and resets indexes in RecPoints
489
490 AliPHOSEmcRecPoint * emcRecPoint ;
491 Int_t index ;
492 Int_t nEmcUnfolded = emcIn->GetEntries() ;
493
494 for(index = 0 ; index < nEmcUnfolded; index++){
495
69183710 496 emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ;
98cbd830 497
69183710 498 Int_t nMultipl = emcRecPoint->GetMultiplicity() ;
499 Int_t * maxAt = new Int_t[nMultipl] ;
98cbd830 500 Float_t * maxAtEnergy = new Float_t[nMultipl] ;
501 Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ;
502
69183710 503 if( nMax > 1 ) { // if cluster is very flat (no pronounced maximum) then nMax = 0
98cbd830 504 UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy) ;
505 emcIn->Remove(emcRecPoint);
506 emcIn->Compress() ;
507 index-- ;
508 nEmcUnfolded-- ;
509 }
510
511 delete[] maxAt ;
512 delete[] maxAtEnergy ;
513 } //Unfolding finished
514
515 emcIn->Sort() ;
516
517 // to set index to new and correct index of old RecPoints
28c3a259 518 for( index = 0 ; index < emcIn->GetEntries() ; index++){
69183710 519
98cbd830 520 ((AliPHOSEmcRecPoint *) emcIn->At(index))->SetIndexInList(index) ;
69183710 521
98cbd830 522 }
523
28c3a259 524 emcIn->Sort() ;
525
98cbd830 526}
527//____________________________________________________________________________
88714635 528void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * dl,
529 AliPHOSRecPoint::RecPointsList * emcIn,
530 AliPHOSEmcRecPoint * iniEmc,
531 Int_t nMax,
532 int * maxAt,
98cbd830 533 Float_t * maxAtEnergy)
d15a28e7 534{
b2a60966 535 // Performs the unfolding of a cluster with nMax overlapping showers
536 // This is time consuming (use the (Un)SetUnfolFlag() )
537
92862013 538 Int_t nPar = 3 * nMax ;
31aa6d6c 539 Float_t * fitparameters = new Float_t[nPar] ;
98cbd830 540
9f616d61 541
92862013 542 Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ;
31aa6d6c 543 if( !rv ) {
544 // Fit failed, return and remove cluster
545 delete[] fitparameters ;
d15a28e7 546 return ;
31aa6d6c 547 }
98cbd830 548
d15a28e7 549 Float_t xDigit ;
550 Float_t zDigit ;
92862013 551 Int_t relid[4] ;
d15a28e7 552
92862013 553 Int_t nDigits = iniEmc->GetMultiplicity() ;
d15a28e7 554 Float_t xpar ;
555 Float_t zpar ;
92862013 556 Float_t epar ;
557 Float_t distance ;
558 Float_t ratio ;
31aa6d6c 559 Float_t * efit = new Float_t[nDigits] ;
d15a28e7 560 Int_t iparam ;
561 Int_t iDigit ;
562
563 AliPHOSDigit * digit ;
564 AliPHOSEmcRecPoint * emcRP ;
6ad0bfa0 565 Int_t * emcDigits = iniEmc->GetDigitsList() ;
d15a28e7 566 Float_t * emcEnergies = iniEmc->GetEnergiesList() ;
567
568 Int_t iRecPoint = emcIn->GetEntries() ;
569
92862013 570 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
98cbd830 571 digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;
572 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
573 fGeom->RelPosInModule(relid, xDigit, zDigit) ;
92862013 574 efit[iDigit] = 0;
d15a28e7 575 iparam = 0 ;
576
92862013 577 while(iparam < nPar ){
578 xpar = fitparameters[iparam] ;
579 zpar = fitparameters[iparam+1] ;
580 epar = fitparameters[iparam+2] ;
d15a28e7 581 iparam += 3 ;
92862013 582 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
583 distance = TMath::Sqrt(distance) ;
b2a60966 584 efit[iDigit] += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
d15a28e7 585 }
d15a28e7 586 }
587
588 iparam = 0 ;
589 Float_t eDigit ;
590
98cbd830 591
92862013 592 while(iparam < nPar ){
593 xpar = fitparameters[iparam] ;
594 zpar = fitparameters[iparam+1] ;
595 epar = fitparameters[iparam+2] ;
d15a28e7 596 iparam += 3 ;
98cbd830 597
28c3a259 598 if(iRecPoint >= emcIn->GetSize())
599 emcIn->Expand(2*iRecPoint) ;
600 (*emcIn)[iRecPoint] = new AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ;
601
98cbd830 602 emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint);
603 iRecPoint++ ;
d15a28e7 604
92862013 605 for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){
98cbd830 606 digit = fPlease->GimeDigit( emcDigits[iDigit] ) ;
607 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
608 fGeom->RelPosInModule(relid, xDigit, zDigit) ;
92862013 609 distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
610 distance = TMath::Sqrt(distance) ;
b2a60966 611 ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ;
92862013 612 eDigit = emcEnergies[iDigit] * ratio ;
9f616d61 613 emcRP->AddDigit( *digit, eDigit ) ;
d15a28e7 614 }
615
d15a28e7 616 }
31aa6d6c 617
618 delete[] fitparameters ;
619 delete[] efit ;
620
d15a28e7 621}
6ad0bfa0 622
d15a28e7 623//______________________________________________________________________________
92862013 624void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag)
d15a28e7 625{
b2a60966 626 // Calculates th Chi square for the cluster unfolding minimization
627 // Number of parameters, Gradient, Chi squared, parameters, what to do
98cbd830 628
9f616d61 629 AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit
98cbd830 630
6ad0bfa0 631 Int_t * emcDigits = emcRP->GetDigitsList() ;
98cbd830 632
633 Int_t nOfDigits = emcRP->GetDigitsMultiplicity() ;
634
d15a28e7 635 Float_t * emcEnergies = emcRP->GetEnergiesList() ;
98cbd830 636
637 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ;
638
639 AliPHOSIndexToObject * please = AliPHOSIndexToObject::GetInstance() ;
640
d15a28e7 641 fret = 0. ;
642 Int_t iparam ;
643
9f616d61 644 if(iflag == 2)
92862013 645 for(iparam = 0 ; iparam < nPar ; iparam++)
9f616d61 646 Grad[iparam] = 0 ; // Will evaluate gradient
647
98cbd830 648 Double_t efit ;
649
d15a28e7 650 AliPHOSDigit * digit ;
98cbd830 651 Int_t iDigit ;
652
653 for( iDigit = 0 ; iDigit < nOfDigits ; iDigit++) {
654
655 digit = please->GimeDigit( emcDigits[iDigit] ) ;
9f616d61 656
92862013 657 Int_t relid[4] ;
d15a28e7 658 Float_t xDigit ;
659 Float_t zDigit ;
98cbd830 660
92862013 661 geom->AbsToRelNumbering(digit->GetId(), relid) ;
98cbd830 662
92862013 663 geom->RelPosInModule(relid, xDigit, zDigit) ;
98cbd830 664
9f616d61 665 if(iflag == 2){ // calculate gradient
666 Int_t iParam = 0 ;
92862013 667 efit = 0 ;
668 while(iParam < nPar ){
669 Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ;
9f616d61 670 iParam++ ;
92862013 671 distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ;
672 distance = TMath::Sqrt( distance ) ;
9f616d61 673 iParam++ ;
92862013 674 efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
9f616d61 675 iParam++ ;
676 }
92862013 677 Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E)
9f616d61 678 iParam = 0 ;
92862013 679 while(iParam < nPar ){
9f616d61 680 Double_t xpar = x[iParam] ;
681 Double_t zpar = x[iParam+1] ;
92862013 682 Double_t epar = x[iParam+2] ;
9f616d61 683 Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) );
684 Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ;
685 Double_t r4 = dr*dr*dr*dr ;
686 Double_t r295 = TMath::Power(dr,2.95) ;
687 Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) +
688 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ;
689
92862013 690 Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x
9f616d61 691 iParam++ ;
92862013 692 Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z
9f616d61 693 iParam++ ;
694 Grad[iParam] += shape ; // Derivative over energy
695 iParam++ ;
696 }
697 }
92862013 698 efit = 0;
9f616d61 699 iparam = 0 ;
98cbd830 700
92862013 701 while(iparam < nPar ){
9f616d61 702 Double_t xpar = x[iparam] ;
703 Double_t zpar = x[iparam+1] ;
92862013 704 Double_t epar = x[iparam+2] ;
9f616d61 705 iparam += 3 ;
92862013 706 Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ;
707 distance = TMath::Sqrt(distance) ;
708 efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ;
9f616d61 709 }
98cbd830 710
92862013 711 fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ;
9f616d61 712 // Here we assume, that sigma = sqrt(E)
d15a28e7 713 }
98cbd830 714
d15a28e7 715}