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" |
39 | #include "AliPHOSTrackSegment.h" |
40 | #include "AliPHOSLink.h" |
41 | #include "AliPHOSv0.h" |
42 | #include "AliRun.h" |
43 | |
92862013 |
44 | extern void UnfoldingChiSquare(Int_t &nPar, Double_t *Grad, Double_t & fret, Double_t *x, Int_t iflag) ; |
9f616d61 |
45 | |
d15a28e7 |
46 | ClassImp( AliPHOSTrackSegmentMakerv1) |
47 | |
48 | |
49 | //____________________________________________________________________________ |
b2a60966 |
50 | AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker() |
d15a28e7 |
51 | { |
9f616d61 |
52 | // ctor |
b2a60966 |
53 | |
d15a28e7 |
54 | fR0 = 4. ; |
55 | AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ; |
56 | //clusters are sorted in "rows" and "columns" of width geom->GetCrystalSize(0), |
57 | fDelta = fR0 + geom->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 | //____________________________________________________________________________ |
71 | Bool_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 | |
d15a28e7 |
76 | AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ; |
d15a28e7 |
77 | |
9f616d61 |
78 | gMinuit->SetPrintLevel(-1) ; // No Printout |
79 | gMinuit->SetFCN(UnfoldingChiSquare) ; // To set the address of the minimization function |
80 | gMinuit->SetObjectFit(emcRP) ; // To tranfer pointer to UnfoldingChiSquare |
81 | |
82 | // filling initial values for fit parameters |
d15a28e7 |
83 | AliPHOSDigit * digit ; |
9f616d61 |
84 | |
85 | Int_t ierflg = 0; |
86 | Int_t index = 0 ; |
92862013 |
87 | Int_t nDigits = (Int_t) nPar / 3 ; |
9f616d61 |
88 | |
d15a28e7 |
89 | Int_t iDigit ; |
9f616d61 |
90 | |
91 | |
92862013 |
92 | for(iDigit = 0; iDigit < nDigits; iDigit++){ |
d15a28e7 |
93 | digit = (AliPHOSDigit *) maxAt[iDigit]; |
94 | |
92862013 |
95 | Int_t relid[4] ; |
d15a28e7 |
96 | Float_t x ; |
97 | Float_t z ; |
92862013 |
98 | geom->AbsToRelNumbering(digit->GetId(), relid) ; |
99 | geom->RelPosInModule(relid, x, z) ; |
d15a28e7 |
100 | |
92862013 |
101 | Float_t energy = maxAtEnergy[iDigit] ; |
d15a28e7 |
102 | |
9f616d61 |
103 | gMinuit->mnparm(index, "x", x, 0.1, 0, 0, ierflg) ; |
104 | index++ ; |
d15a28e7 |
105 | if(ierflg != 0){ |
106 | cout << "PHOS Unfolding> Unable to set initial value for fit procedure : x = " << x << endl ; |
107 | return kFALSE; |
108 | } |
9f616d61 |
109 | gMinuit->mnparm(index, "z", z, 0.1, 0, 0, ierflg) ; |
110 | index++ ; |
d15a28e7 |
111 | if(ierflg != 0){ |
112 | cout << "PHOS Unfolding> Unable to set initial value for fit procedure : z = " << z << endl ; |
113 | return kFALSE; |
114 | } |
92862013 |
115 | gMinuit->mnparm(index, "Energy", energy , 0.05*energy, 0., 4.*energy, ierflg) ; |
9f616d61 |
116 | index++ ; |
d15a28e7 |
117 | if(ierflg != 0){ |
92862013 |
118 | cout << "PHOS Unfolding> Unable to set initial value for fit procedure : energy = " << energy << endl ; |
d15a28e7 |
119 | return kFALSE; |
6ad0bfa0 |
120 | } |
d15a28e7 |
121 | } |
122 | |
9f616d61 |
123 | Double_t p0 = 0.1 ; // "Tolerance" Evaluation stops when EDM = 0.0001*p0 ; The number of function call slightly |
124 | // depends on it. |
125 | Double_t p1 = 1.0 ; |
126 | Double_t p2 = 0.0 ; |
127 | |
128 | gMinuit->mnexcm("SET STR", &p2, 0, ierflg) ; // force TgMinuit to reduce function calls |
129 | gMinuit->mnexcm("SET GRA", &p1, 1, ierflg) ; // force TMinuit to use my gradient |
d15a28e7 |
130 | gMinuit->SetMaxIterations(5); |
9f616d61 |
131 | gMinuit->mnexcm("SET NOW", &p2 , 0, ierflg) ; // No Warnings |
132 | gMinuit->mnexcm("MIGRAD", &p0, 0, ierflg) ; // minimize |
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 | } |
d15a28e7 |
143 | return kTRUE; |
9f616d61 |
144 | |
d15a28e7 |
145 | } |
9f616d61 |
146 | |
d15a28e7 |
147 | //____________________________________________________________________________ |
b2a60966 |
148 | void AliPHOSTrackSegmentMakerv1::FillOneModule(DigitsList * dl, RecPointsList * emcIn, TObjArray * emcOut, |
d15a28e7 |
149 | RecPointsList * ppsdIn, TObjArray * ppsdOutUp, |
92862013 |
150 | TObjArray * ppsdOutLow, Int_t & phosmod, Int_t & emcStopedAt, |
d15a28e7 |
151 | Int_t & ppsdStopedAt) |
9f616d61 |
152 | { |
153 | // Unfold clusters and fill xxxOut arrays with clusters from one PHOS module |
154 | |
155 | AliPHOSEmcRecPoint * emcRecPoint ; |
d15a28e7 |
156 | AliPHOSPpsdRecPoint * ppsdRecPoint ; |
157 | Int_t index ; |
6ad0bfa0 |
158 | |
92862013 |
159 | Int_t nEmcUnfolded = emcIn->GetEntries() ; |
160 | for(index = emcStopedAt; index < nEmcUnfolded; index++){ |
83974468 |
161 | emcRecPoint = (AliPHOSEmcRecPoint *) emcIn->At(index) ; |
6ad0bfa0 |
162 | |
92862013 |
163 | if(emcRecPoint->GetPHOSMod() != phosmod ) |
9f616d61 |
164 | break ; |
165 | |
92862013 |
166 | Int_t nMultipl = emcRecPoint->GetMultiplicity() ; |
31aa6d6c |
167 | Int_t * maxAt = new Int_t[nMultipl] ; |
168 | Float_t * maxAtEnergy = new Float_t[nMultipl] ; |
92862013 |
169 | Int_t nMax = emcRecPoint->GetNumberOfLocalMax(maxAt, maxAtEnergy) ; |
6a3f1304 |
170 | |
6727be7e |
171 | if(nMax <= 1 ) // if cluster is very flat (no pronounced maximum) then nMax = 0 |
d15a28e7 |
172 | emcOut->Add(emcRecPoint) ; |
6727be7e |
173 | else if (fUnfoldFlag) { |
b2a60966 |
174 | UnfoldClusters(dl, emcIn, emcRecPoint, nMax, maxAt, maxAtEnergy, emcOut) ; |
d15a28e7 |
175 | emcIn->Remove(emcRecPoint); |
176 | emcIn->Compress() ; |
92862013 |
177 | nEmcUnfolded-- ; |
d15a28e7 |
178 | index-- ; |
179 | } |
31aa6d6c |
180 | |
181 | delete[] maxAt ; |
182 | delete[] maxAtEnergy ; |
d15a28e7 |
183 | } |
184 | emcStopedAt = index ; |
185 | |
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() ) |
191 | ppsdOutUp->Add(ppsdRecPoint) ; |
192 | else |
193 | ppsdOutLow->Add(ppsdRecPoint) ; |
194 | } |
195 | ppsdStopedAt = index ; |
6ad0bfa0 |
196 | |
d15a28e7 |
197 | emcOut->Sort() ; |
198 | ppsdOutUp->Sort() ; |
6ad0bfa0 |
199 | ppsdOutLow->Sort() ; |
d15a28e7 |
200 | } |
201 | //____________________________________________________________________________ |
92862013 |
202 | Float_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()){ |
d15a28e7 |
214 | if(vecPpsd.X() >= vecEmc.X() - fDelta ){ |
215 | if(vecPpsd.Z() >= vecEmc.Z() - fDelta ){ |
216 | AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ; |
6ad0bfa0 |
217 | // Correct to difference in CPV and EMC position due to different distance to center. |
218 | // we assume, that particle moves from center |
92862013 |
219 | Float_t dCPV = geom->GetIPtoOuterCoverDistance(); |
220 | Float_t dEMC = geom->GetIPtoCrystalSurface() ; |
221 | dEMC = dEMC / dCPV ; |
222 | vecPpsd = dEMC * vecPpsd - vecEmc ; |
223 | r = vecPpsd.Mag() ; |
d15a28e7 |
224 | } // if zPpsd >= zEmc - fDelta |
92862013 |
225 | toofar = kFALSE ; |
d15a28e7 |
226 | } // if xPpsd >= xEmc - fDelta |
227 | else |
92862013 |
228 | toofar = kTRUE ; |
d15a28e7 |
229 | } |
230 | else |
92862013 |
231 | toofar = kTRUE ; |
d15a28e7 |
232 | |
92862013 |
233 | return r ; |
d15a28e7 |
234 | } |
235 | |
236 | //____________________________________________________________________________ |
92862013 |
237 | void AliPHOSTrackSegmentMakerv1::MakeLinks(TObjArray * emcRecPoints, TObjArray * ppsdRecPointsUp, |
238 | TObjArray * ppsdRecPointsLow, TClonesArray * linklowArray, |
239 | TClonesArray *linkupArray) |
d15a28e7 |
240 | { |
b2a60966 |
241 | // Finds distances (links) between all EMC and PPSD clusters, which are not further apart from each other than fR0 |
242 | |
92862013 |
243 | TIter nextEmc(emcRecPoints) ; |
d15a28e7 |
244 | Int_t iEmcClu = 0 ; |
245 | |
92862013 |
246 | AliPHOSPpsdRecPoint * ppsdlow ; |
247 | AliPHOSPpsdRecPoint * ppsdup ; |
248 | AliPHOSEmcRecPoint * emcclu ; |
d15a28e7 |
249 | |
250 | Int_t iLinkLow = 0 ; |
251 | Int_t iLinkUp = 0 ; |
252 | |
92862013 |
253 | while( (emcclu = (AliPHOSEmcRecPoint*)nextEmc() ) ) { |
254 | Bool_t toofar ; |
255 | TIter nextPpsdLow(ppsdRecPointsLow ) ; |
d15a28e7 |
256 | Int_t iPpsdLow = 0 ; |
257 | |
92862013 |
258 | while( (ppsdlow = (AliPHOSPpsdRecPoint*)nextPpsdLow() ) ) { |
259 | Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdlow, toofar) ; |
d15a28e7 |
260 | |
92862013 |
261 | if(toofar) |
d15a28e7 |
262 | break ; |
83974468 |
263 | if(r < fR0){ |
92862013 |
264 | new( (*linklowArray)[iLinkLow++]) AliPHOSLink(r, iEmcClu, iPpsdLow) ; |
83974468 |
265 | } |
d15a28e7 |
266 | iPpsdLow++ ; |
267 | |
268 | } |
269 | |
92862013 |
270 | TIter nextPpsdUp(ppsdRecPointsUp ) ; |
d15a28e7 |
271 | Int_t iPpsdUp = 0 ; |
272 | |
92862013 |
273 | while( (ppsdup = (AliPHOSPpsdRecPoint*)nextPpsdUp() ) ) { |
274 | Float_t r = GetDistanceInPHOSPlane(emcclu, ppsdup, toofar) ; |
d15a28e7 |
275 | |
92862013 |
276 | if(toofar) |
d15a28e7 |
277 | break ; |
83974468 |
278 | if(r < fR0) { |
92862013 |
279 | new( (*linkupArray)[iLinkUp++]) AliPHOSLink(r, iEmcClu, iPpsdUp) ; |
83974468 |
280 | } |
d15a28e7 |
281 | iPpsdUp++ ; |
282 | |
283 | } |
284 | |
285 | iEmcClu++ ; |
286 | |
287 | } // while nextEmC |
288 | |
92862013 |
289 | linklowArray->Sort() ; //first links with smallest distances |
290 | linkupArray->Sort() ; |
d15a28e7 |
291 | } |
292 | |
293 | //____________________________________________________________________________ |
92862013 |
294 | void AliPHOSTrackSegmentMakerv1::MakePairs(TObjArray * emcRecPoints, TObjArray * ppsdRecPointsUp, |
295 | TObjArray * ppsdRecPointsLow, TClonesArray * linklowArray, |
296 | TClonesArray * linkupArray, 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 | |
307 | AliPHOSEmcRecPoint * emc ; |
308 | AliPHOSPpsdRecPoint * ppsdLow ; |
309 | AliPHOSPpsdRecPoint * ppsdUp ; |
310 | |
92862013 |
311 | AliPHOSRecPoint * nullpointer = 0 ; |
9f616d61 |
312 | |
d15a28e7 |
313 | while ( (linkLow = (AliPHOSLink *)nextLow() ) ){ |
92862013 |
314 | emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(linkLow->GetEmc()) ; |
315 | ppsdLow = (AliPHOSPpsdRecPoint *) ppsdRecPointsLow->At(linkLow->GetPpsd()) ; |
6ad0bfa0 |
316 | if( (emc) && (ppsdLow) ){ // RecPoints not removed yet |
d15a28e7 |
317 | ppsdUp = 0 ; |
318 | |
319 | while ( (linkUp = (AliPHOSLink *)nextUp() ) ){ |
320 | if(linkLow->GetEmc() == linkUp->GetEmc() ){ |
92862013 |
321 | ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ; |
d15a28e7 |
322 | break ; |
323 | } |
324 | |
325 | } // while nextUp |
326 | |
327 | nextUp.Reset(); |
b2a60966 |
328 | // AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ; |
329 | // trsl->Add(subtr) ; |
330 | new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ; |
331 | fNTrackSegments++ ; |
92862013 |
332 | emcRecPoints->AddAt(nullpointer,linkLow->GetEmc()) ; |
333 | ppsdRecPointsLow->AddAt(nullpointer,linkLow->GetPpsd()) ; |
d15a28e7 |
334 | |
335 | if(ppsdUp) |
92862013 |
336 | ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ; |
d15a28e7 |
337 | |
6ad0bfa0 |
338 | } |
d15a28e7 |
339 | } |
340 | |
92862013 |
341 | TIter nextEmc(emcRecPoints) ; |
d15a28e7 |
342 | nextEmc.Reset() ; |
343 | |
92862013 |
344 | while( (emc = (AliPHOSEmcRecPoint*)nextEmc()) ){ //to create pairs if no ppsdlow |
9f616d61 |
345 | ppsdLow = 0 ; |
346 | ppsdUp = 0 ; |
d15a28e7 |
347 | |
348 | while ( (linkUp = (AliPHOSLink *)nextUp() ) ){ |
349 | |
92862013 |
350 | if(emcRecPoints->IndexOf(emc) == linkUp->GetEmc() ){ |
351 | ppsdUp = (AliPHOSPpsdRecPoint *) ppsdRecPointsUp->At(linkUp->GetPpsd()) ; |
d15a28e7 |
352 | break ; |
353 | } |
354 | |
355 | } |
b2a60966 |
356 | // AliPHOSTrackSegment * subtr = new AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ; |
357 | // trsl->Add(subtr) ; |
358 | new( (*trsl)[fNTrackSegments] ) AliPHOSTrackSegment(emc, ppsdUp, ppsdLow ) ; |
359 | fNTrackSegments++ ; |
360 | |
361 | |
d15a28e7 |
362 | if(ppsdUp) |
92862013 |
363 | ppsdRecPointsUp->AddAt(nullpointer,linkUp->GetPpsd()) ; |
d15a28e7 |
364 | } |
365 | |
366 | } |
367 | |
368 | //____________________________________________________________________________ |
b2a60966 |
369 | void AliPHOSTrackSegmentMakerv1::MakeTrackSegments(DigitsList * dl, RecPointsList * emcl, |
d15a28e7 |
370 | RecPointsList * ppsdl, TrackSegmentsList * trsl) |
371 | { |
b2a60966 |
372 | // Makes the track segments out of the list of EMC and PPSD Recpoints and stores them in a list |
d15a28e7 |
373 | |
92862013 |
374 | Int_t phosmod = 1 ; |
9f616d61 |
375 | Int_t emcStopedAt = 0 ; |
d15a28e7 |
376 | Int_t ppsdStopedAt = 0 ; |
377 | |
92862013 |
378 | TObjArray * emcRecPoints = new TObjArray(100) ; // these arrays keep pointers |
379 | TObjArray * ppsdRecPointsUp = new TObjArray(100) ; // to RecPoints, which are |
380 | TObjArray * ppsdRecPointsLow = new TObjArray(100) ; // kept in TClonesArray's emcl and ppsdl |
d15a28e7 |
381 | |
382 | |
92862013 |
383 | TClonesArray * linklowArray = new TClonesArray("AliPHOSLink", 100); |
384 | TClonesArray * linkupArray = new TClonesArray("AliPHOSLink", 100); |
d15a28e7 |
385 | |
386 | AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ; |
387 | |
92862013 |
388 | while(phosmod <= geom->GetNModules() ){ |
d15a28e7 |
389 | |
b2a60966 |
390 | FillOneModule(dl, emcl, emcRecPoints, ppsdl, ppsdRecPointsUp, ppsdRecPointsLow, phosmod, emcStopedAt, ppsdStopedAt) ; |
6ad0bfa0 |
391 | |
92862013 |
392 | MakeLinks(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray) ; |
d15a28e7 |
393 | |
92862013 |
394 | MakePairs(emcRecPoints, ppsdRecPointsUp, ppsdRecPointsLow, linklowArray, linkupArray, trsl) ; |
d15a28e7 |
395 | |
92862013 |
396 | emcRecPoints->Clear() ; |
9f616d61 |
397 | |
92862013 |
398 | ppsdRecPointsUp->Clear() ; |
9f616d61 |
399 | |
92862013 |
400 | ppsdRecPointsLow->Clear() ; |
9f616d61 |
401 | |
92862013 |
402 | linkupArray->Clear() ; |
9f616d61 |
403 | |
92862013 |
404 | linklowArray->Clear() ; |
9f616d61 |
405 | |
92862013 |
406 | phosmod++ ; |
d15a28e7 |
407 | } |
92862013 |
408 | delete emcRecPoints ; |
409 | emcRecPoints = 0 ; |
9f616d61 |
410 | |
92862013 |
411 | delete ppsdRecPointsUp ; |
412 | ppsdRecPointsUp = 0 ; |
9f616d61 |
413 | |
92862013 |
414 | delete ppsdRecPointsLow ; |
415 | ppsdRecPointsLow = 0 ; |
9f616d61 |
416 | |
92862013 |
417 | delete linkupArray ; |
418 | linkupArray = 0 ; |
9f616d61 |
419 | |
92862013 |
420 | delete linklowArray ; |
421 | linklowArray = 0 ; |
d15a28e7 |
422 | } |
423 | |
424 | //____________________________________________________________________________ |
9f616d61 |
425 | Double_t AliPHOSTrackSegmentMakerv1::ShowerShape(Double_t r) |
426 | { |
b2a60966 |
427 | // Shape of the shower (see PHOS TDR) |
428 | // If you change this function, change also the gradien evaluation in ChiSquare() |
429 | |
6ad0bfa0 |
430 | Double_t r4 = r*r*r*r ; |
431 | Double_t r295 = TMath::Power(r, 2.95) ; |
d15a28e7 |
432 | Double_t shape = TMath::Exp( -r4 * (1. / (2.32 + 0.26 * r4) + 0.0316 / (1 + 0.0652 * r295) ) ) ; |
433 | return shape ; |
434 | } |
435 | |
436 | //____________________________________________________________________________ |
b2a60966 |
437 | void AliPHOSTrackSegmentMakerv1::UnfoldClusters(DigitsList * dl, RecPointsList * emcIn, AliPHOSEmcRecPoint * iniEmc, |
92862013 |
438 | Int_t nMax, int * maxAt, Float_t * maxAtEnergy, TObjArray * emcList) |
d15a28e7 |
439 | { |
b2a60966 |
440 | // Performs the unfolding of a cluster with nMax overlapping showers |
441 | // This is time consuming (use the (Un)SetUnfolFlag() ) |
442 | |
92862013 |
443 | Int_t nPar = 3 * nMax ; |
31aa6d6c |
444 | Float_t * fitparameters = new Float_t[nPar] ; |
d15a28e7 |
445 | AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ; |
9f616d61 |
446 | |
92862013 |
447 | Bool_t rv = FindFit(iniEmc, maxAt, maxAtEnergy, nPar, fitparameters) ; |
31aa6d6c |
448 | if( !rv ) { |
449 | // Fit failed, return and remove cluster |
450 | delete[] fitparameters ; |
d15a28e7 |
451 | return ; |
31aa6d6c |
452 | } |
d15a28e7 |
453 | |
454 | Float_t xDigit ; |
455 | Float_t zDigit ; |
92862013 |
456 | Int_t relid[4] ; |
d15a28e7 |
457 | |
92862013 |
458 | Int_t nDigits = iniEmc->GetMultiplicity() ; |
d15a28e7 |
459 | Float_t xpar ; |
460 | Float_t zpar ; |
92862013 |
461 | Float_t epar ; |
462 | Float_t distance ; |
463 | Float_t ratio ; |
31aa6d6c |
464 | Float_t * efit = new Float_t[nDigits] ; |
d15a28e7 |
465 | Int_t iparam ; |
466 | Int_t iDigit ; |
467 | |
468 | AliPHOSDigit * digit ; |
469 | AliPHOSEmcRecPoint * emcRP ; |
6ad0bfa0 |
470 | Int_t * emcDigits = iniEmc->GetDigitsList() ; |
d15a28e7 |
471 | Float_t * emcEnergies = iniEmc->GetEnergiesList() ; |
472 | |
473 | Int_t iRecPoint = emcIn->GetEntries() ; |
474 | |
92862013 |
475 | for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){ |
d15a28e7 |
476 | digit = (AliPHOSDigit *) emcDigits[iDigit]; |
92862013 |
477 | geom->AbsToRelNumbering(digit->GetId(), relid) ; |
478 | geom->RelPosInModule(relid, xDigit, zDigit) ; |
479 | efit[iDigit] = 0; |
d15a28e7 |
480 | iparam = 0 ; |
481 | |
92862013 |
482 | while(iparam < nPar ){ |
483 | xpar = fitparameters[iparam] ; |
484 | zpar = fitparameters[iparam+1] ; |
485 | epar = fitparameters[iparam+2] ; |
d15a28e7 |
486 | iparam += 3 ; |
92862013 |
487 | distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ; |
488 | distance = TMath::Sqrt(distance) ; |
b2a60966 |
489 | efit[iDigit] += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ; |
d15a28e7 |
490 | } |
d15a28e7 |
491 | } |
492 | |
493 | iparam = 0 ; |
494 | Float_t eDigit ; |
495 | |
92862013 |
496 | while(iparam < nPar ){ |
497 | xpar = fitparameters[iparam] ; |
498 | zpar = fitparameters[iparam+1] ; |
499 | epar = fitparameters[iparam+2] ; |
d15a28e7 |
500 | iparam += 3 ; |
501 | new ((*emcIn)[iRecPoint]) AliPHOSEmcRecPoint( iniEmc->GetLogWeightCut(), iniEmc->GetLocMaxCut() ) ; |
502 | emcRP = (AliPHOSEmcRecPoint *) emcIn->At(iRecPoint++); |
503 | |
92862013 |
504 | for(iDigit = 0 ; iDigit < nDigits ; iDigit ++){ |
d15a28e7 |
505 | digit = (AliPHOSDigit *) emcDigits[iDigit]; |
92862013 |
506 | geom->AbsToRelNumbering(digit->GetId(), relid) ; |
507 | geom->RelPosInModule(relid, xDigit, zDigit) ; |
508 | distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ; |
509 | distance = TMath::Sqrt(distance) ; |
b2a60966 |
510 | ratio = epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) / efit[iDigit] ; |
92862013 |
511 | eDigit = emcEnergies[iDigit] * ratio ; |
9f616d61 |
512 | emcRP->AddDigit( *digit, eDigit ) ; |
d15a28e7 |
513 | } |
514 | |
515 | emcList->Add(emcRP) ; |
516 | |
517 | } |
31aa6d6c |
518 | |
519 | delete[] fitparameters ; |
520 | delete[] efit ; |
521 | |
d15a28e7 |
522 | } |
6ad0bfa0 |
523 | |
d15a28e7 |
524 | //______________________________________________________________________________ |
92862013 |
525 | void UnfoldingChiSquare(Int_t & nPar, Double_t * Grad, Double_t & fret, Double_t * x, Int_t iflag) |
d15a28e7 |
526 | { |
b2a60966 |
527 | // Calculates th Chi square for the cluster unfolding minimization |
528 | // Number of parameters, Gradient, Chi squared, parameters, what to do |
9f616d61 |
529 | |
d15a28e7 |
530 | AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance() ; |
d15a28e7 |
531 | |
9f616d61 |
532 | AliPHOSEmcRecPoint * emcRP = (AliPHOSEmcRecPoint *) gMinuit->GetObjectFit() ; // EmcRecPoint to fit |
6ad0bfa0 |
533 | Int_t * emcDigits = emcRP->GetDigitsList() ; |
d15a28e7 |
534 | Float_t * emcEnergies = emcRP->GetEnergiesList() ; |
535 | fret = 0. ; |
536 | Int_t iparam ; |
537 | |
9f616d61 |
538 | if(iflag == 2) |
92862013 |
539 | for(iparam = 0 ; iparam < nPar ; iparam++) |
9f616d61 |
540 | Grad[iparam] = 0 ; // Will evaluate gradient |
541 | |
92862013 |
542 | Double_t efit ; |
9f616d61 |
543 | |
d15a28e7 |
544 | AliPHOSDigit * digit ; |
545 | Int_t iDigit = 0 ; |
9f616d61 |
546 | |
d15a28e7 |
547 | while ( (digit = (AliPHOSDigit *)emcDigits[iDigit] )){ |
92862013 |
548 | Int_t relid[4] ; |
d15a28e7 |
549 | Float_t xDigit ; |
550 | Float_t zDigit ; |
92862013 |
551 | geom->AbsToRelNumbering(digit->GetId(), relid) ; |
552 | geom->RelPosInModule(relid, xDigit, zDigit) ; |
d15a28e7 |
553 | |
9f616d61 |
554 | if(iflag == 2){ // calculate gradient |
555 | Int_t iParam = 0 ; |
92862013 |
556 | efit = 0 ; |
557 | while(iParam < nPar ){ |
558 | Double_t distance = (xDigit - x[iParam]) * (xDigit - x[iParam]) ; |
9f616d61 |
559 | iParam++ ; |
92862013 |
560 | distance += (zDigit - x[iParam]) * (zDigit - x[iParam]) ; |
561 | distance = TMath::Sqrt( distance ) ; |
9f616d61 |
562 | iParam++ ; |
92862013 |
563 | efit += x[iParam] * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ; |
9f616d61 |
564 | iParam++ ; |
565 | } |
92862013 |
566 | Double_t sum = 2. * (efit - emcEnergies[iDigit]) / emcEnergies[iDigit] ; // Here we assume, that sigma = sqrt(E) |
9f616d61 |
567 | iParam = 0 ; |
92862013 |
568 | while(iParam < nPar ){ |
9f616d61 |
569 | Double_t xpar = x[iParam] ; |
570 | Double_t zpar = x[iParam+1] ; |
92862013 |
571 | Double_t epar = x[iParam+2] ; |
9f616d61 |
572 | Double_t dr = TMath::Sqrt( (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ); |
573 | Double_t shape = sum * AliPHOSTrackSegmentMakerv1::ShowerShape(dr) ; |
574 | Double_t r4 = dr*dr*dr*dr ; |
575 | Double_t r295 = TMath::Power(dr,2.95) ; |
576 | Double_t deriv =-4. * dr*dr * ( 2.32 / ( (2.32 + 0.26 * r4) * (2.32 + 0.26 * r4) ) + |
577 | 0.0316 * (1. + 0.0171 * r295) / ( ( 1. + 0.0652 * r295) * (1. + 0.0652 * r295) ) ) ; |
578 | |
92862013 |
579 | Grad[iParam] += epar * shape * deriv * (xpar - xDigit) ; // Derivative over x |
9f616d61 |
580 | iParam++ ; |
92862013 |
581 | Grad[iParam] += epar * shape * deriv * (zpar - zDigit) ; // Derivative over z |
9f616d61 |
582 | iParam++ ; |
583 | Grad[iParam] += shape ; // Derivative over energy |
584 | iParam++ ; |
585 | } |
586 | } |
92862013 |
587 | efit = 0; |
9f616d61 |
588 | iparam = 0 ; |
92862013 |
589 | while(iparam < nPar ){ |
9f616d61 |
590 | Double_t xpar = x[iparam] ; |
591 | Double_t zpar = x[iparam+1] ; |
92862013 |
592 | Double_t epar = x[iparam+2] ; |
9f616d61 |
593 | iparam += 3 ; |
92862013 |
594 | Double_t distance = (xDigit - xpar) * (xDigit - xpar) + (zDigit - zpar) * (zDigit - zpar) ; |
595 | distance = TMath::Sqrt(distance) ; |
596 | efit += epar * AliPHOSTrackSegmentMakerv1::ShowerShape(distance) ; |
9f616d61 |
597 | } |
92862013 |
598 | fret += (efit-emcEnergies[iDigit])*(efit-emcEnergies[iDigit])/emcEnergies[iDigit] ; |
9f616d61 |
599 | // Here we assume, that sigma = sqrt(E) |
600 | iDigit++ ; |
d15a28e7 |
601 | } |
602 | } |